Add an archive

This commit is contained in:
Robin Malley 2021-02-03 03:41:22 +00:00
parent c173fae026
commit 7462b1e7ac
5 changed files with 38 additions and 0 deletions

View File

@ -66,6 +66,7 @@ $(chroot_dir): apk-tools-static-$(version).apk
$(Q)$(MKDIR) $(chroot_dir)/pages $(Q)$(MKDIR) $(chroot_dir)/pages
$(Q)$(MKDIR) $(chroot_dir)/sql $(Q)$(MKDIR) $(chroot_dir)/sql
$(Q)$(MKDIR) $(chroot_dir)/data $(Q)$(MKDIR) $(chroot_dir)/data
$(Q)$(MKDIR) $(chroot_dir)/data/archive
$(Q)$(MKDIR) $(chroot_dir)/endpoints $(Q)$(MKDIR) $(chroot_dir)/endpoints
#cd $(chroot_dir) && tar -xvzf ../apk-tools-static-*.apk #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 #cd $(chroot_dir) && sudo ./sbin/apk.static -X $(mirror)latest-stable/main -U --allow-untrusted --root $(chroot_dir) --no-cache --initdb add alpine-base

View File

@ -27,6 +27,7 @@ validator v_markup regex (plain|imageboard)
validator v_bool regex (0|1) validator v_bool regex (0|1)
validator v_checkbox regex (|on) validator v_checkbox regex (|on)
validator v_hex_128 regex [0-9a-f]{128} validator v_hex_128 regex [0-9a-f]{128}
validator v_time regex [0-9]+
domain * { domain * {
attach tls attach tls
@ -52,6 +53,7 @@ domain * {
route /_download download route /_download download
route /_preview preview route /_preview preview
route /_search search route /_search search
route /_archive archive
# Leading ^ is needed for dynamic routes, kore says the route is dynamic if it does not start with '/' # Leading ^ is needed for dynamic routes, kore says the route is dynamic if it does not start with '/'
route ^/[^_].* read_story route ^/[^_].* read_story
@ -90,6 +92,9 @@ domain * {
params get /_search { params get /_search {
validate q v_any validate q v_any
} }
params get /_archive {
validate t v_time
}
params get ^/[^_].* { params get ^/[^_].* {
validate comments v_bool validate comments v_bool
validate pwd v_hex_128 validate pwd v_hex_128

View File

@ -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

View File

@ -33,6 +33,7 @@ local endpoint_names = {
edit = {"get","post"}, edit = {"get","post"},
claim = {"get","post"}, claim = {"get","post"},
search = {"get"}, search = {"get"},
archive = {"get"},
} }
local endpoints = {} local endpoints = {}
for name, methods in pairs(endpoint_names) do for name, methods in pairs(endpoint_names) do
@ -145,4 +146,9 @@ function search(req)
endpoints.search_get(req) endpoints.search_get(req)
end end
function archive(req)
print("archive method:",http_method_text(req))
endpoints.archive_get(req)
end
print("Done with init.lua") print("Done with init.lua")

View File

@ -25,6 +25,7 @@ int claim(struct http_request *);
int download(struct http_request *); int download(struct http_request *);
int preview(struct http_request *); int preview(struct http_request *);
int search(struct http_request *); int search(struct http_request *);
int archive(struct http_request *);
int style(struct http_request *); int style(struct http_request *);
int miligram(struct http_request *); int miligram(struct http_request *);
int do_lua(struct http_request *req, const char *name); int do_lua(struct http_request *req, const char *name);
@ -160,6 +161,24 @@ search(struct http_request *req){
return do_lua(req,"search"); 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 int
home(struct http_request *req){ home(struct http_request *req){
return do_lua(req,"home"); return do_lua(req,"home");