diff --git a/Makefile b/Makefile index 304a9de..685f6b8 100644 --- a/Makefile +++ b/Makefile @@ -66,6 +66,7 @@ $(chroot_dir): apk-tools-static-$(version).apk $(Q)$(MKDIR) $(chroot_dir)/pages $(Q)$(MKDIR) $(chroot_dir)/sql $(Q)$(MKDIR) $(chroot_dir)/data + $(Q)$(MKDIR) $(chroot_dir)/data/archive $(Q)$(MKDIR) $(chroot_dir)/endpoints #cd $(chroot_dir) && tar -xvzf ../apk-tools-static-*.apk #cd $(chroot_dir) && sudo ./sbin/apk.static -X $(mirror)latest-stable/main -U --allow-untrusted --root $(chroot_dir) --no-cache --initdb add alpine-base diff --git a/conf/smr.conf.in b/conf/smr.conf.in index 0a5ac08..526a92a 100644 --- a/conf/smr.conf.in +++ b/conf/smr.conf.in @@ -27,6 +27,7 @@ validator v_markup regex (plain|imageboard) validator v_bool regex (0|1) validator v_checkbox regex (|on) validator v_hex_128 regex [0-9a-f]{128} +validator v_time regex [0-9]+ domain * { attach tls @@ -52,6 +53,7 @@ domain * { route /_download download route /_preview preview route /_search search + route /_archive archive # Leading ^ is needed for dynamic routes, kore says the route is dynamic if it does not start with '/' route ^/[^_].* read_story @@ -90,6 +92,9 @@ domain * { params get /_search { validate q v_any } + params get /_archive { + validate t v_time + } params get ^/[^_].* { validate comments v_bool validate pwd v_hex_128 diff --git a/src/lua/endpoints/archive_get.lua b/src/lua/endpoints/archive_get.lua new file mode 100644 index 0000000..1e7004a --- /dev/null +++ b/src/lua/endpoints/archive_get.lua @@ -0,0 +1,7 @@ +local function archive(req) + local archive = assert(io.open("data/archive.zip","r")) + http_response_header(req,"Content-Type","application/zip") + http_response_header(req,"Content-Disposition","attachment; filename=\"slash_monster_archive.zip\"") + http_response(req,200,archive:read("*a")) +end +return archive diff --git a/src/lua/init.lua b/src/lua/init.lua index 4eaeec4..cfc28af 100644 --- a/src/lua/init.lua +++ b/src/lua/init.lua @@ -33,6 +33,7 @@ local endpoint_names = { edit = {"get","post"}, claim = {"get","post"}, search = {"get"}, + archive = {"get"}, } local endpoints = {} for name, methods in pairs(endpoint_names) do @@ -145,4 +146,9 @@ function search(req) endpoints.search_get(req) end +function archive(req) + print("archive method:",http_method_text(req)) + endpoints.archive_get(req) +end + print("Done with init.lua") diff --git a/src/smr.c b/src/smr.c index f5f2a6a..df01ad4 100644 --- a/src/smr.c +++ b/src/smr.c @@ -25,6 +25,7 @@ int claim(struct http_request *); int download(struct http_request *); int preview(struct http_request *); int search(struct http_request *); +int archive(struct http_request *); int style(struct http_request *); int miligram(struct http_request *); int do_lua(struct http_request *req, const char *name); @@ -160,6 +161,24 @@ search(struct http_request *req){ return do_lua(req,"search"); } +int +archive(struct http_request *req){ + /* + struct kore_fileref *ref = kore_fileref_get("data/archive.zip",1); + if(ref != NULL){ + http_response_fileref(ref,HTTP_STATUS_OK,ref); + kore_fileref_release(ref); + return KORE_RESULT_OK; + }else{ + char msg[] = "Failed to create file ref"; + http_response(req,200,msg,strlen(msg)); + return KORE_RESULT_OK; + } + */ + printf("We want to do archive!\n"); + return do_lua(req,"archive"); +} + int home(struct http_request *req){ return do_lua(req,"home");