feat: serve paste entries
	
		
			
	
		
	
	
		
			
				
	
				ci/woodpecker/push/woodpecker Pipeline was successful
				
					Details
				
			
		
	
				
					
				
			
				
	
				ci/woodpecker/push/woodpecker Pipeline was successful
				
					Details
				
			
		
	
							parent
							
								
									7f42d540b5
								
							
						
					
					
						commit
						97ed770166
					
				| 
						 | 
					@ -26,6 +26,8 @@ RUN make prod && \
 | 
				
			||||||
 | 
					
 | 
				
			||||||
FROM alpine:3.16.3
 | 
					FROM alpine:3.16.3
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ENV LANDER_DATA_DIR=/data
 | 
				
			||||||
 | 
					
 | 
				
			||||||
RUN apk add --update --no-cache boost && \
 | 
					RUN apk add --update --no-cache boost && \
 | 
				
			||||||
    mkdir /data && \
 | 
					    mkdir /data && \
 | 
				
			||||||
    chown -R 1000:1000 /data
 | 
					    chown -R 1000:1000 /data
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -14,5 +14,5 @@ elif [ "$1" = get ]; then
 | 
				
			||||||
    curl -is "$URL/$2" | sed -En 's/^[lL]ocation: (.*)/\1/p'
 | 
					    curl -is "$URL/$2" | sed -En 's/^[lL]ocation: (.*)/\1/p'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
elif [ "$1" = paste ]; then
 | 
					elif [ "$1" = paste ]; then
 | 
				
			||||||
    curl -v --data-binary @"$2" -XPOST -H "X-Api-Key: $API_KEY" "$URL/p/"
 | 
					    curl --data-binary @"$2" -XPOST -H "X-Api-Key: $API_KEY" "$URL/p/"
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										13
									
								
								src/main.cpp
								
								
								
								
							
							
						
						
									
										13
									
								
								src/main.cpp
								
								
								
								
							| 
						 | 
					@ -52,17 +52,20 @@ int main() {
 | 
				
			||||||
  mkdir((data_dir + "/pastes").c_str(), 0700);
 | 
					  mkdir((data_dir + "/pastes").c_str(), 0700);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  crow::SimpleApp app;
 | 
					  crow::SimpleApp app;
 | 
				
			||||||
 | 
					 | 
				
			||||||
  app.loglevel(crow::LogLevel::Info);
 | 
					  app.loglevel(crow::LogLevel::Info);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Serve an entry
 | 
				
			||||||
  CROW_ROUTE(app, "/<string>")
 | 
					  CROW_ROUTE(app, "/<string>")
 | 
				
			||||||
      .methods(crow::HTTPMethod::Get)(
 | 
					      .methods(crow::HTTPMethod::Get)(
 | 
				
			||||||
          [trie](crow::response &res, std::string s) {
 | 
					          [data_dir, trie](crow::response &res, std::string key) {
 | 
				
			||||||
            Entry *entry = ternarytrie_search(trie, s.c_str());
 | 
					            Entry *entry = ternarytrie_search(trie, key.c_str());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // TODO check entry type
 | 
					 | 
				
			||||||
            if (entry != NULL) {
 | 
					            if (entry != NULL) {
 | 
				
			||||||
              res.redirect(entry->string);
 | 
					              if (entry->type == Redirect) {
 | 
				
			||||||
 | 
					                res.redirect(entry->string);
 | 
				
			||||||
 | 
					              } else if (entry->type == Paste) {
 | 
				
			||||||
 | 
					                res.set_static_file_info(data_dir + "/pastes/" + key);
 | 
				
			||||||
 | 
					              }
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
              res.code = 404;
 | 
					              res.code = 404;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue