require "apache2" --[[ If a snapshot link is given, then push it onto the builder redis queue Example snapshot link: https://git.purplebirdman.com/wolf-seeking-sheep.git/snapshot/127ef0ef17ec1067f77bb7097e84a537a4a01ec7.tar.gz ]]-- function lpush_onto_job_queue(s) local cmd = ("redis-cli -h redis LPUSH snapshots %s"):format(s) local handle = io.popen(cmd) local output = handle:read('*a') handle:close() return output end function dump_file(s) local handle = io.open(s) local output = handle:read('*a') handle:close() return output; end function handle(r) r.content_type = "text/html" local args = r:parseargs() local snapshot_uri = args.snapshot_uri if snapshot_uri then -- filename might have spaces that apache replaces with '+' snapshot_uri = string.gsub(snapshot_uri, '+', ' ') snapshot_uri = string.gsub(snapshot_uri, '%%2F', '/') local out = lpush_onto_job_queue(snapshot_uri) r:puts( out ) return apache2.OK else r:puts( dump_file(r.document_root .. '/build-request.html') ) return apache2.OK end end