add tracking

This commit is contained in:
Karol Wypchlo 2020-12-18 12:23:10 +01:00
parent 550bdb2ba7
commit f52b648c5b
2 changed files with 21 additions and 1 deletions

View File

@ -57,7 +57,7 @@
preserve_host: true
url: "http://accounts:3000"
match:
url: "http://oathkeeper:4455/<{user}>"
url: "http://oathkeeper:4455/<{user,user/**}>"
methods:
- GET
authenticators:

View File

@ -291,6 +291,16 @@ server {
# proxy this call to siad endpoint (make sure the ip is correct)
proxy_pass http://siad/skynet/skyfile/$dir1/$dir2/$dir3/$dir4$is_args$args;
# register the upload in accounts service (cookies should contain jwt)
log_by_lua_block {
local skylink = ngx.header["Skynet-Skylink"]
if skylink and ngx.status >= ngx.HTTP_OK and ngx.status < ngx.HTTP_SPECIAL_RESPONSE then
local http = require("socket.http")
local headers = { Cookie = ngx.req.get_headers()["Cookie"] }
http.request { url = "http://accounts:3000/track/upload/" .. skylink, method = "POST", headers = headers }
end
}
}
location ~ "^/(([a-zA-Z0-9-_]{46}|[a-z0-9]{55})(/.*)?)$" {
@ -311,6 +321,16 @@ server {
# decoded whitespaces and set will re-encode it for us before passing it to proxy_pass
set $skylink $1;
# register the download in accounts service (cookies should contain jwt)
log_by_lua_block {
local skylink = ngx.var[2]
if skylink and ngx.status >= ngx.HTTP_OK and ngx.status < ngx.HTTP_SPECIAL_RESPONSE then
local http = require("socket.http")
local headers = { Cookie = ngx.req.get_headers()["Cookie"] }
http.request { url = "http://accounts:3000/track/download/" .. skylink, method = "POST", headers = headers }
end
}
proxy_read_timeout 600;
proxy_set_header User-Agent: Sia-Agent;
# proxy this call to siad /skynet/skylink/ endpoint (make sure the ip is correct)