Invalidate caches when the server restarts

This commit is contained in:
2021-11-29 16:13:19 +01:00
parent ef4e550536
commit ef083ff087
18 changed files with 80 additions and 342 deletions

2
go.mod
View File

@@ -5,7 +5,7 @@ go 1.17
require (
fornaxian.tech/config v0.0.0-20211108212237-6133aed90586
fornaxian.tech/log v0.0.0-20211102185326-552e9b1f8640
fornaxian.tech/pixeldrain_api_client v0.0.0-20211128192613-093515ebeaa7
fornaxian.tech/pixeldrain_api_client v0.0.0-20211128195924-7b5d3f7293df
fornaxian.tech/util v0.0.0-20211102152345-9a486dee9787
github.com/julienschmidt/httprouter v1.3.0
github.com/microcosm-cc/bluemonday v1.0.16

2
go.sum
View File

@@ -5,6 +5,8 @@ fornaxian.tech/log v0.0.0-20211102185326-552e9b1f8640 h1:UPDxJwLRCfh/cv80UMSanzm
fornaxian.tech/log v0.0.0-20211102185326-552e9b1f8640/go.mod h1:sN82qMToeHhP2u3ehvrcE8y1IudRZJAZO9yG5OBYblo=
fornaxian.tech/pixeldrain_api_client v0.0.0-20211128192613-093515ebeaa7 h1:Gx7SRu906VslyPcIL9D3uw3B2uO6u7mIwsMD7SPr+9k=
fornaxian.tech/pixeldrain_api_client v0.0.0-20211128192613-093515ebeaa7/go.mod h1:uajB2ofEsefUtxjvs4m7SDyPVRlfrI3qzCSWcud47hY=
fornaxian.tech/pixeldrain_api_client v0.0.0-20211128195924-7b5d3f7293df h1:eFpcIMRUYqqYr+VeBDvVENsFBjV/UotMqJfWdWbprYE=
fornaxian.tech/pixeldrain_api_client v0.0.0-20211128195924-7b5d3f7293df/go.mod h1:uajB2ofEsefUtxjvs4m7SDyPVRlfrI3qzCSWcud47hY=
fornaxian.tech/util v0.0.0-20211102152345-9a486dee9787 h1:9ujI8Qi6+FTL/YW6xQAS9DmWDMerHBe8foQvVD/G/i0=
fornaxian.tech/util v0.0.0-20211102152345-9a486dee9787/go.mod h1:FqVgfghmxTGR3l9Zx4MOMeZ9KHjiEFl3s3C0BSTvBwk=
github.com/BurntSushi/toml v0.4.1 h1:GaI7EiDXDRfa8VshkTj7Fym7ha+y8/XxIgD2okUIjLw=

View File

@@ -1,68 +0,0 @@
{{define "user_files"}}<!DOCTYPE html>
<html lang="en">
<head>
{{template "meta_tags" "Files"}}
{{template "user_style" .}}
<script>var apiEndpoint = '{{.APIEndpoint}}';</script>
</head>
<body>
{{template "page_top" .}}
<h1>My Files</h1>
<div class="page_content">
<p>
These files were uploaded while logged in to your pixeldrain account,
<a href="/history">click here</a> to view files uploaded anonymously
in this browser.
</p>
<br/>
{{$limit := 200}}
{{$page := .URLQuery.Get "page" | pageNr}}
{{$files := .PixelAPI.UserFiles $page $limit}}
<div class="highlight_dark">
{{if ne $page 0}}
<a href="?page={{sub $page 4}}" class="button">🡄 4 Pages</a>
<a href="?page={{sub $page 2}}" class="button">⬅ 2 Pages</a>
<a href="?page={{sub $page 1}}" class="button button_highlight" style="margin-right: 2em;">← Last Page</a>
{{end}}
Page {{$page}}
{{if len $files.Files | eq $limit}}
<a href="?page={{add $page 1}}" class="button button_highlight" style="margin-left: 2em;">Next Page →</a>
<a href="?page={{add $page 2}}" class="button">2 Pages ⮕</a>
<a href="?page={{add $page 4}}" class="button">4 Pages 🡆</a>
{{end}}
</div>
<br/>
{{range $files.Files}}<!--
--><a class="file_button" href="/u/{{.ID}}" target="_blank">
<img src="{{$.APIEndpoint}}/file/{{.ID}}/thumbnail?width=80&height=80" alt="{{.Name}}" />
<span class="file_button_title">{{.Name}}</span>
<br/>
{{.DateUpload.Format "2006-01-02 15:04:05"}}
</a><!--
-->{{end}}
<br/><br/>
<div class="highlight_dark">
{{if ne $page 0}}
<a href="?page={{sub $page 4}}" class="button">🡄 4 Pages</a>
<a href="?page={{sub $page 2}}" class="button">⬅ 2 Pages</a>
<a href="?page={{sub $page 1}}" class="button button_highlight" style="margin-right: 2em;">← Last Page</a>
{{end}}
Page {{$page}}
{{if len $files.Files | eq $limit}}
<a href="?page={{add $page 1}}" class="button button_highlight" style="margin-left: 2em;">Next Page →</a>
<a href="?page={{add $page 2}}" class="button">2 Pages ⮕</a>
<a href="?page={{add $page 4}}" class="button">4 Pages 🡆</a>
{{end}}
</div>
</div>
{{template "page_bottom" .}}
{{template "analytics"}}
</body>
</html>
{{end}}

View File

@@ -1,60 +0,0 @@
{{define "user_lists"}}<!DOCTYPE html>
<html lang="en">
<head>
{{template "meta_tags" "Lists"}}
{{template "user_style" .}}
<script>var apiEndpoint = '{{.APIEndpoint}}';</script>
</head>
<body>
{{template "page_top" .}}
<h1>My Lists</h1>
<div class="page_content">
{{$limit := 200}}
{{$page := .URLQuery.Get "page" | pageNr}}
{{$lists := .PixelAPI.UserLists $page $limit}}
<div class="highlight_dark">
{{if ne $page 0}}
<a href="?page={{sub $page 4}}" class="button">🡄 4 Pages</a>
<a href="?page={{sub $page 2}}" class="button">⬅ 2 Pages</a>
<a href="?page={{sub $page 1}}" class="button button_highlight" style="margin-right: 2em;">← Last Page</a>
{{end}}
Page {{$page}}
{{if len $lists.Lists | eq $limit}}
<a href="?page={{add $page 1}}" class="button button_highlight" style="margin-left: 2em;">Next Page →</a>
<a href="?page={{add $page 2}}" class="button">2 Pages ⮕</a>
<a href="?page={{add $page 4}}" class="button">4 Pages 🡆</a>
{{end}}
</div>
<br/>
{{range $lists.Lists}}<!--
--><a class="file_button" href="/l/{{.ID}}" target="_blank">
<img src="{{$.APIEndpoint}}/list/{{.ID}}/thumbnail?width=80&height=80" alt="{{.Title}}" />
<span class="file_button_title">{{.Title}}</span>
({{.FileCount}} Files)
<br/>
{{.DateCreated.Format "2006-01-02 15:04:05"}}
</a><!--
-->{{end}}
<br/><br/>
<div class="highlight_dark">
{{if ne $page 0}}
<a href="?page={{sub $page 4}}" class="button">🡄 4 Pages</a>
<a href="?page={{sub $page 2}}" class="button">⬅ 2 Pages</a>
<a href="?page={{sub $page 1}}" class="button button_highlight" style="margin-right: 2em;">← Last Page</a>
{{end}}
Page {{$page}}
{{if len $lists.Lists | eq $limit}}
<a href="?page={{add $page 1}}" class="button button_highlight" style="margin-left: 2em;">Next Page →</a>
<a href="?page={{add $page 2}}" class="button">2 Pages ⮕</a>
<a href="?page={{add $page 4}}" class="button">4 Pages 🡆</a>
{{end}}
</div>
</div>
{{template "page_bottom" .}}
{{template "analytics"}}
</body>
</html>
{{end}}

View File

@@ -1,21 +0,0 @@
{{define "user_settings"}}<!DOCTYPE html>
<html lang="en">
<head>
{{template "meta_tags" .User.Username}}
{{template "user_style" .}}
<script>var apiEndpoint = '{{.APIEndpoint}}';</script>
</head>
<body>
{{template "page_top" .}}
<h1>{{.Title}}</h1>
<div class="page_content"><div class="limit_width">
{{template "form" .Other.PasswordForm}}
{{template "form" .Other.EmailForm}}
{{template "form" .Other.UsernameForm}}
</div></div>
{{template "page_bottom" .}}
{{template "analytics"}}
</body>
</html>
{{end}}

View File

@@ -10,8 +10,8 @@
<script>
window.api_endpoint = '{{.APIEndpoint}}';
</script>
<link rel='stylesheet' href='/res/svelte/admin_panel.css'>
<script defer src='/res/svelte/admin_panel.js'></script>
<link rel='stylesheet' href='/res/svelte/admin_panel.css?v{{.CacheID}}'>
<script defer src='/res/svelte/admin_panel.js?v{{.CacheID}}'></script>
</head>
<body>
{{template "page_top" .}}

View File

@@ -1,161 +0,0 @@
{{ define "ad_headers" }}
{{ if eq .Other.AdBannerType 3 }}
<!-- Adshares -->
<script type="text/javascript">
!function(n){var t,e=function(n,t){var e=[["a","e","i","o","u","y"],["b","c","d","f","g","h","j","k","l","m","n","p","q","r","s","t","v","w","x","y","z"]];if(t)for(var r=0;r<=t.length-1;r++)n=n*t.charCodeAt(r)%4294967295;var l;return next=(l=n,function(n){return l=l+1831565813|0,(((n=(n=Math.imul(l^l>>>15,1|l))+Math.imul(n^n>>>7,61|n)^n)^n>>>14)>>>0)/Math.pow(2,32)}),function(n,t){for(var r=[],l=null,o=0;o<=n-1;o++){var a=void 0;null===l?a=e[0].concat(e[1]):1==l?(a=e[0],l=0):(a=e[1],l=1);var u=a[Math.floor(next()*a.length)];r.push(u),null===l&&(l=-1!=e[0].indexOf(u)?0:1)}return r.push("."+t),r.join("")}}((t=new Date,(t/=1e3)-t%1209600),"_fa7cdd4c68507744")(8,"xyz");if(null===n)console.log("https://"+e);else{var r=n.createElement("script");r.src="https://"+e+"/main.js",(n.body||n.head).appendChild(r)}}("undefined"!=typeof document?document:null);
</script>
{{ end }}
{{ end }}
{{ define "banner_ads"}}
{{ if eq .Other.AdBannerType 1 }}
<!-- A-ads -->
<!-- scrolling="no" is not allowed by the W3C, but overflow: hidden doesn't work in chrome, so I have no choice -->
<iframe class="sponsors_banner"
data-aa="73974"
src="//ad.a-ads.com/73974?size=728x90&background_color={{.Style.Layer2Color.RGB}}&text_color={{.Style.TextColor.RGB}}&title_color={{.Style.HighlightColor.RGB}}&title_hover_color={{.Style.HighlightColor.RGB}}&link_color={{.Style.HighlightColor.RGB}}&link_hover_color={{.Style.HighlightColor.RGB}}"
style="width:728px; height:90px; border:none; padding:0; overflow:hidden;"
scrolling="no">
</iframe>
{{ else if eq .Other.AdBannerType 13 }}
<!-- Amarula electronics -->
<a class="sponsors_banner" style="display: inline-block; width: 576px; height: 96px;" href="/click/DtZ3hHT9?target=https%3A%2F%2Fwww.amarula-electronics.com">
<img src="/res/img/misc/banner_as.png" style="width: 100%; height: 100%" />
</a>
{{else if eq .Other.AdBannerType 2}}
<!-- Patreon -->
<div style="text-align: center; line-height: 22px; font-size: 18px;">
<div style="margin: 4px 8px; display: inline-block; vertical-align: middle;">
Pixeldrain needs money to survive<br/>
<a href="/click/7wy9gg2J?target=%2Fsubscribe" class="button button_highlight">
Support me on Patreon and get some neat perks
</a>
</div>
<div style="margin: 4px 8px; display: inline-block; vertical-align: middle; text-align: left;">
No ads when viewing files<br/>
No ads on your uploaded files<br/>
Longer file retention<br/>
</div>
<div>
{{else if eq .Other.AdBannerType 3}}
<!-- Adshares -->
<div class="_fa7cdd4c68507744 sponsors_banner" data-zone="d8764be36c134d3d807abb2a073dc010" style="width:728px;height:90px;display: inline-block;margin: 0 auto"></div>
{{else if eq .Other.AdBannerType 4}}
<!-- Amarula Jobs -->
<a class="sponsors_banner" style="display: inline-block; width: 576px; height: 96px;" href="/click/DtZ3hHT9?target=https%3A%2F%2Fwww.amarulasolutions.com/jobs">
<img src="/res/img/misc/banner_amarula_jobs.png" style="width: 100%; height: 100%" />
</a>
{{ else if eq .Other.AdBannerType 6 }}
<!-- Adsterra -->
<div class="sponsors_banner" style="display: inline-block; width: 728px; height: 90px;">
<script type="text/javascript">
atOptions = {
'key' : 'a62692cf48c3969d426a09c868ae13f7',
'format' : 'iframe',
'height' : 90,
'width' : 728,
'params' : {}
};
document.write('<scr' + 'ipt type="text/javascript" defer src="http' + (location.protocol === 'https:' ? 's' : '') + '://www.highperformancedisplaycontent.com/a62692cf48c3969d426a09c868ae13f7/invoke.js"></scr' + 'ipt>');
</script>
</div>
{{ else if eq .Other.AdBannerType 7 }}
<!-- Brave -->
<a class="sponsors_banner" style="display: inline-block; width: 728px; height: 90px;" href="/click/MdUXxSov?target=https%3A%2F%2Fbrave.com%2Fpix009">
<img src="/res/img/misc/brave-728x90.png" style="width: 100%; height: 100%" />
</a>
{{ else if eq .Other.AdBannerType 8 }}
<!-- Pro ad 1 -->
<div style="text-align: center; line-height: 1.4em; font-size: 22px;">
<img src="/res/img/pixeldrain_128.png" style="height: 2.4em; vertical-align: middle; margin: 4px;"/>
<div style="margin: 4px; display: inline-block; vertical-align: middle;">
Are your files expiring too quickly?<br/>
<a href="/click/7wy9gg2J?target=%2F%23pro" class="button button_highlight">Pixeldrain Pro: Only €2 per month</a>
</div>
</div>
{{ else if eq .Other.AdBannerType 9 }}
<!-- Pro ad 2 -->
<div style="text-align: center; line-height: 1.4em; font-size: 22px;">
<img src="/res/img/pixeldrain_128.png" style="height: 2.4em; vertical-align: middle; margin: 4px;"/>
<div style="margin: 4px; display: inline-block; vertical-align: middle;">
Are your files too large to share?<br/>
<a href="/click/7wy9gg2J?target=%2F%23pro" class="button button_highlight">Pixeldrain Pro: Only €2 per month</a>
</div>
</div>
{{ else if eq .Other.AdBannerType 10 }}
<!-- Pro ad 3 -->
<div style="text-align: center; line-height: 1.4em; font-size: 22px;">
<img src="/res/img/pixeldrain_128.png" style="height: 2.4em; vertical-align: middle; margin: 4px;"/>
<div style="margin: 4px; display: inline-block; vertical-align: middle;">
Are you tired of advertisements?<br/>
<a href="/click/7wy9gg2J?target=%2F%23pro" class="button button_highlight">Pixeldrain Pro: Only €2 per month</a>
</div>
</div>
{{ else if eq .Other.AdBannerType 11 }}
<!-- Pro ad 4 -->
<div style="text-align: center; line-height: 1.4em; font-size: 22px;">
<img src="/res/img/pixeldrain_128.png" style="height: 2.4em; vertical-align: middle; margin: 4px;"/>
<div style="margin: 4px; display: inline-block; vertical-align: middle;">
Concerned about your online privacy?<br/>
<a href="/click/7wy9gg2J?target=%2F%23pro" class="button button_highlight">Pixeldrain Pro: Only €2 per month</a>
</div>
</div>
{{ else if eq .Other.AdBannerType 12 }}
<!-- Clickadu -->
<div class="sponsors_banner" style="display: inline-block; width: 300px; height: 100px;">
<script data-cfasync="false" type="text/javascript" src="//myolnyr5bsk18.com/lv/esnk/1846778/code.js" async id="__clb-1846778"></script>
</div>
{{ else if eq .Other.AdBannerType 14 }}
<!-- Ads.plus -->
<!-- This tag library should be placed in the head section of the page -->
<script async src="https://securepubads.g.doubleclick.net/tag/js/gpt.js"></script>
<script>
window.googletag = window.googletag || {cmd: []};
googletag.cmd.push(function() {
googletag.defineSlot('/21673142571/299__pixeldrain.com__default__728x90_1', [728, 90], 'div-gpt-ad-pixeldraincom728x90_1').addService(googletag.pubads());
googletag.pubads().collapseEmptyDivs();
googletag.enableServices();
});
</script>
<!-- This is the tag for the unit and should be placed in the respective ad spot in the body part of the page -->
<!-- /21673142571/299__pixeldrain.com__default__728x90_1 -->
<div id='div-gpt-ad-pixeldraincom728x90_1' class="sponsors_banner" style='width: 728px; height: 90px;'>
<script>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-pixeldraincom728x90_1'); });
</script>
</div>
{{ else if eq .Other.AdBannerType 15 }}
<!-- Pixfuture -->
<!-- AuctionX Display platform tag START -->
<div id="27517x728x90x4605x_ADSLOT1" clickTrack="%%CLICK_URL_ESC%%" style="display: block; margin: auto;"></div>
<script type="text/javascript" async src="https://served-by.pixfuture.com/www/delivery/headerbid.js" slotId="27517x728x90x4605x_ADSLOT1" refreshTime="5" refreshInterval="60"></script>
<!-- AuctionX Display platform tag END -->
{{ else if eq .Other.AdBannerType 16 }}
<!-- Publisherrest ad 1 -->
<div style="text-align: center; line-height: 1.4em; font-size: 22px;">
<a href="https://pixeldrain.com/vouchercodes/" class="button button_highlight" style="margin: 8px;">
<i class="icon">shopping_cart</i>
Click here for online shopping discounts!
<i class="icon">shopping_cart</i>
</a>
</div>
{{ else if eq .Other.AdBannerType 17 }}
<!-- Publisherrest ad 2 -->
<div style="text-align: center; line-height: 1.4em; font-size: 22px;">
<a href="https://pixeldrain.com/vouchercodes/" class="button button_highlight" style="margin: 8px;">
<i class="icon">shopping_cart</i>
Check our online shopping discounts!
<i class="icon">shopping_cart</i>
</a>
</div>
{{ else if eq .Other.AdBannerType 18 }}
<!-- Publisherrest ad 3 -->
<div style="text-align: center; line-height: 1.4em; font-size: 22px;">
<a href="https://pixeldrain.com/vouchercodes/" class="button button_highlight" style="margin: 8px;">
<i class="icon">shopping_cart</i>
Free coupon codes for online shopping!
<i class="icon">shopping_cart</i>
</a>
</div>
{{ end }}
{{ end }}

View File

@@ -28,8 +28,8 @@
window.user_authenticated = {{.Authenticated}};
</script>
<link rel='stylesheet' href='/res/svelte/file_viewer.css?v3'>
<script defer src='/res/svelte/file_viewer.js?v3'></script>
<link rel='stylesheet' href='/res/svelte/file_viewer.css?v{{.CacheID}}'>
<script defer src='/res/svelte/file_viewer.js?v{{.CacheID}}'></script>
{{template "analytics"}}
</head>

View File

@@ -25,8 +25,8 @@
window.api_endpoint = '{{.APIEndpoint}}';
</script>
<link rel='stylesheet' href='/res/svelte/filesystem.css'>
<script defer src='/res/svelte/filesystem.js'></script>
<link rel='stylesheet' href='/res/svelte/filesystem.css?v{{.CacheID}}'>
<script defer src='/res/svelte/filesystem.js?v{{.CacheID}}'></script>
</head>
<body></body>
</html>

View File

@@ -88,8 +88,8 @@
window.api_endpoint = '{{.APIEndpoint}}';
window.user = {{.User}};
</script>
<link rel='stylesheet' href='/res/svelte/home_page.css?v3'>
<script defer src='/res/svelte/home_page.js?v3'></script>
<link rel='stylesheet' href='/res/svelte/home_page.css?v{{.CacheID}}'>
<script defer src='/res/svelte/home_page.js?v{{.CacheID}}'></script>
</head>
<body>
{{template "page_top" .}}

View File

@@ -4,8 +4,8 @@
{{template "meta_tags" "Buckets"}}
{{template "user_style" .}}
<script>window.api_endpoint = '{{.APIEndpoint}}';</script>
<link rel='stylesheet' href='/res/svelte/user_buckets.css'>
<script defer src='/res/svelte/user_buckets.js'></script>
<link rel='stylesheet' href='/res/svelte/user_buckets.css?v{{.CacheID}}'>
<script defer src='/res/svelte/user_buckets.js?v{{.CacheID}}'></script>
</head>
<body>
{{template "page_top" .}}

View File

@@ -7,8 +7,8 @@
<script>
window.api_endpoint = '{{.APIEndpoint}}';
</script>
<link rel='stylesheet' href='/res/svelte/user_file_manager.css?v1'>
<script defer src='/res/svelte/user_file_manager.js?v1'></script>
<link rel='stylesheet' href='/res/svelte/user_file_manager.css?v{{.CacheID}}'>
<script defer src='/res/svelte/user_file_manager.js?v{{.CacheID}}'></script>
</head>
<body>

View File

@@ -9,8 +9,8 @@
window.api_endpoint = '{{.APIEndpoint}}';
window.user = {{.User}};
</script>
<link rel='stylesheet' href='/res/svelte/user_home.css?v1'>
<script defer src='/res/svelte/user_home.js?v1'></script>
<link rel='stylesheet' href='/res/svelte/user_home.css?v{{.CacheID}}'>
<script defer src='/res/svelte/user_home.js?v{{.CacheID}}'></script>
</head>
<body>

View File

@@ -34,16 +34,9 @@ let credit_form = {
submit_label: `<i class="icon">send</i> Submit`,
on_submit: async fields => {
const form = new FormData()
if (fields.user_id !== "") {
form.append("user_by", "id")
form.append("id", fields.user_id)
} else if (fields.user_name !== "") {
form.append("user_by", "name")
form.append("name", fields.user_name)
} else if (fields.user_email !== "") {
form.append("user_by", "email")
form.append("email", fields.user_email)
}
form.append("credit", fields.credit*1e6)
const resp = await fetch(
@@ -58,6 +51,47 @@ let credit_form = {
},
}
let impersonate_form = {
name: "impersonate",
fields: [
{
name: "user_id",
label: "User ID",
type: "text",
default_value: "",
}, {
name: "user_name",
label: "User name",
type: "text",
default_value: "",
}, {
name: "user_email",
label: "User e-mail",
type: "text",
default_value: "",
},
],
submit_label: `<i class="icon">send</i> Submit`,
on_submit: async fields => {
const form = new FormData()
form.append("id", fields.user_id)
form.append("name", fields.user_name)
form.append("email", fields.user_email)
const resp = await fetch(
window.api_endpoint+"/admin/impersonate",
{ method: "POST", body: form }
);
if(resp.status >= 400) {
return {error_json: await resp.json()}
}
window.location = "/user"
return {success: true, message: "Success"}
},
}
let coupon_form = {
name: "make_coupon",
fields: [
@@ -154,6 +188,11 @@ onMount(get_coupons)
<Form config={credit_form}></Form>
</div>
<h2>Impersonate user</h2>
<div class="highlight_dark">
<Form config={impersonate_form}></Form>
</div>
<h2>Create coupon codes</h2>
<div class="highlight_dark">
<Form config={coupon_form}></Form>

View File

@@ -36,6 +36,9 @@ type TemplateData struct {
Title string
OGData ogData
// The cache ID is used to invalidate caches when the webserver is restarted
CacheID int64
Other interface{}
URLQuery url.Values
@@ -54,6 +57,7 @@ func (wc *WebController) newTemplateData(w http.ResponseWriter, r *http.Request)
// Use the user's IP address for making requests
PixelAPI: wc.api.RealIP(util.RemoteAddress(r)).RealAgent(r.UserAgent()),
CacheID: wc.cacheID,
Hostname: template.HTML(wc.hostname),
URLQuery: r.URL.Query(),
}

View File

@@ -36,6 +36,9 @@ type WebController struct {
// page-specific variables
captchaSiteKey string
// The cache ID is used to invalidate caches when the webserver is restarted
cacheID int64
httpClient *http.Client
// API client to use for all requests. If the user is authenticated you
@@ -66,6 +69,7 @@ func New(
websiteAddress: websiteAddress,
sessionCookieDomain: sessionCookieDomain,
proxyAPIRequests: proxyAPIRequests,
cacheID: time.Now().Unix() / 3600,
httpClient: &http.Client{Timeout: time.Minute * 10},
api: pixelapi.New(apiURLInternal),
}
@@ -78,14 +82,15 @@ func New(
// Serve static files
var fs = http.FileServer(http.Dir(resourceDir + "/static"))
r.GET(prefix+"/res/*filepath", func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
var resourceHandler = func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
// Cache resources for a year
if !debugMode {
w.Header().Set("Cache-Control", "public, max-age=31536000")
}
r.URL.Path = p.ByName("filepath")
fs.ServeHTTP(w, r)
})
}
r.HEAD(prefix+"/res/*filepath", resourceHandler)
r.OPTIONS(prefix+"/res/*filepath", resourceHandler)
r.GET(prefix+"/res/*filepath", resourceHandler)
// Static assets
r.GET(prefix+"/favicon.ico" /* */, wc.serveFile("/favicon.ico"))
@@ -166,8 +171,6 @@ func New(
{PST, "password_reset" /* */, wc.serveForm(wc.passwordResetForm, handlerOpts{NoEmbed: true})},
{GET, "logout" /* */, wc.serveTemplate("logout", handlerOpts{Auth: true, NoEmbed: true})},
{PST, "logout" /* */, wc.serveLogout},
{GET, "user/files" /* */, wc.serveTemplate("user_files", handlerOpts{Auth: true})},
{GET, "user/lists" /* */, wc.serveTemplate("user_lists", handlerOpts{Auth: true})},
{GET, "user/buckets" /* */, wc.serveTemplate("user_buckets", handlerOpts{Auth: true})},
{GET, "user/filemanager" /* */, wc.serveTemplate("file_manager", handlerOpts{Auth: true})},
{GET, "user/export/files" /**/, wc.serveUserExportFiles},