feat: serve paste entries
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
7f42d540b5
commit
97ed770166
3 changed files with 11 additions and 6 deletions
13
src/main.cpp
13
src/main.cpp
|
|
@ -52,17 +52,20 @@ int main() {
|
|||
mkdir((data_dir + "/pastes").c_str(), 0700);
|
||||
|
||||
crow::SimpleApp app;
|
||||
|
||||
app.loglevel(crow::LogLevel::Info);
|
||||
|
||||
// Serve an entry
|
||||
CROW_ROUTE(app, "/<string>")
|
||||
.methods(crow::HTTPMethod::Get)(
|
||||
[trie](crow::response &res, std::string s) {
|
||||
Entry *entry = ternarytrie_search(trie, s.c_str());
|
||||
[data_dir, trie](crow::response &res, std::string key) {
|
||||
Entry *entry = ternarytrie_search(trie, key.c_str());
|
||||
|
||||
// TODO check entry type
|
||||
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 {
|
||||
res.code = 404;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue