From b659ac383aefa30ebf235de5c62e951ea3af079a Mon Sep 17 00:00:00 2001 From: Wim Brand Date: Tue, 26 Mar 2019 20:53:19 +0100 Subject: [PATCH 1/8] Add bandwidth counter to file viewer --- pixelapi/file.go | 1 + pixelapi/list.go | 15 ++++++++------- res/static/script/ListNavigator.js | 6 ------ res/static/script/Toolbar.js | 11 ++++++++--- res/static/script/Viewer.js | 1 - res/static/style/viewer.css | 7 +++++++ res/template/file_viewer.html | 5 ++++- res/template/fragments/api/file.html | 1 + res/template/fragments/api/list.html | 9 ++++++--- webcontroller/file_viewer.go | 21 +++++++++++---------- 10 files changed, 46 insertions(+), 31 deletions(-) diff --git a/pixelapi/file.go b/pixelapi/file.go index 4e27130..2fd7343 100644 --- a/pixelapi/file.go +++ b/pixelapi/file.go @@ -18,6 +18,7 @@ type FileInfo struct { Name string `json:"name"` Size uint64 `json:"size"` Views int64 `json:"views"` + BandwidthUsed uint64 `json:"bandwidth_used"` DateUpload time.Time `json:"date_upload"` DateLastView time.Time `json:"date_last_view"` MimeType string `json:"mime_type"` diff --git a/pixelapi/list.go b/pixelapi/list.go index 4f2af11..3bb40bb 100644 --- a/pixelapi/list.go +++ b/pixelapi/list.go @@ -19,13 +19,14 @@ type List struct { // ListFile information object from the pixeldrain API type ListFile struct { - ID string `json:"id"` - DetailHREF string `json:"detail_href"` - Name string `json:"name"` - Description string `json:"description"` - DateCreated time.Time `json:"date_created"` - DateLastView time.Time `json:"date_last_view"` - Views int64 `json:"views"` + ID string `json:"id"` + DetailHREF string `json:"detail_href"` + Name string `json:"name"` + Description string `json:"description"` + DateCreated time.Time `json:"date_created"` + DateLastView time.Time `json:"date_last_view"` + Views int64 `json:"views"` + BandwidthUsed uint64 `json:"bandwidth_used"` } // GetList get a List from the pixeldrain API. Errors will be available through diff --git a/res/static/script/ListNavigator.js b/res/static/script/ListNavigator.js index ee02360..583ee9d 100644 --- a/res/static/script/ListNavigator.js +++ b/res/static/script/ListNavigator.js @@ -209,12 +209,6 @@ var ListNavigator = { document.getElementById("button-expand-toolbar").style.top = navHeight+"px"; document.getElementById("sharebar").style.top = navHeight+"px"; document.getElementById("info_popup").style.top = (navHeight+20)+"px"; - // $("#listNavigator").animate( {top: 0}, {"duration": 1500, "queue": false}); - // $("#filepreview").animate( {top: navHeight},{"duration": 1500, "queue": false}); - // $("#toolbar").animate( {top: navHeight},{"duration": 1500, "queue": false}); - // $("#button-expand-toolbar").animate({top: navHeight},{"duration": 1500, "queue": false}); - // $("#sharebar").animate( {top: navHeight},{"duration": 1500, "queue": false}); - // $("#info_popup").css("top", "120px"); }, 200); } }; diff --git a/res/static/script/Toolbar.js b/res/static/script/Toolbar.js index ed2f71d..e6c9dda 100644 --- a/res/static/script/Toolbar.js +++ b/res/static/script/Toolbar.js @@ -55,8 +55,9 @@ var Toolbar = { document.getElementById("btnCopy").classList.remove("button_highlight") }, 60000); }, - setViews: function(amount){ - document.getElementById("views").innerText = "Views: "+amount; + setStats: function(views, downloads){ + document.getElementById("stat_views").innerText = views + document.getElementById("stat_downloads").innerText = Math.round(downloads*10)/10; } }; @@ -127,12 +128,14 @@ var DetailsWindow = { + "Name" + escapeHTML(data.name) + "" + "Url/u/" + data.id + "" + "Mime Type" + escapeHTML(data.mime_type) + "" - + "IS" + data.id + "" + + "ID" + data.id + "" + "Size" + data.size + "" + + "Bandwidth" + data.bandwidth_used + "" + "Upload Date" + data.date_upload + "" + "Description" + escapeHTML(file.description) + "" + "" ); + Toolbar.setStats(data.views, data.bandwidth_used/data.size); } }); } else { @@ -142,9 +145,11 @@ var DetailsWindow = { + "Mime Type" + escapeHTML(file.mime_type) + "" + "ID" + file.id + "" + "Size" + file.size + "" + + "Bandwidth" + file.bandwidth_used + "" + "Upload Date" + file.date_upload + "" + "" ); + Toolbar.setStats(file.views, file.bandwidth_used/file.size); } } }; diff --git a/res/static/script/Viewer.js b/res/static/script/Viewer.js index b77c201..10f7444 100644 --- a/res/static/script/Viewer.js +++ b/res/static/script/Viewer.js @@ -40,7 +40,6 @@ var Viewer = { }); DetailsWindow.setDetails(file); - Toolbar.setViews(file.views); } }; diff --git a/res/static/style/viewer.css b/res/static/style/viewer.css index af30858..ba2fba1 100644 --- a/res/static/style/viewer.css +++ b/res/static/style/viewer.css @@ -148,6 +148,13 @@ body{ vertical-align: 6px; } +.toolbar_label { + text-align: left; + padding-left: 10px; + font-size: 0.8em; + line-height: 0.7em; +} + #sponsors{ position: relative; height: 600px; diff --git a/res/template/file_viewer.html b/res/template/file_viewer.html index 3a6b162..99e1ea1 100644 --- a/res/template/file_viewer.html +++ b/res/template/file_viewer.html @@ -45,7 +45,10 @@
-
Views: No
+
Views
+
N/A
+
Downloads
+
N/A
Back to the Home page diff --git a/res/template/fragments/api/file.html b/res/template/fragments/api/file.html index fb01f68..44435fd 100644 --- a/res/template/fragments/api/file.html +++ b/res/template/fragments/api/file.html @@ -158,6 +158,7 @@ "date_last_view": 1485894987, // Timestamp "size": 5694837, // Bytes "views" 1234, // Amount of unique file views + "bandwidth_used": 1234567890, // Bytes "mime_type" "image/png", "description": "File description", "mime_image": "http://pixeldra.in/res/img/mime/image-png.png", // Image associated with the mime type diff --git a/res/template/fragments/api/list.html b/res/template/fragments/api/list.html index 4156599..ef79f3a 100644 --- a/res/template/fragments/api/list.html +++ b/res/template/fragments/api/list.html @@ -130,7 +130,8 @@ "description": "", "date_created": 1513033304, "date_last_view": 1513033304, - "views": 1 + "views": 1, + "bandwidth_used": 1234567890 }, { "detail_href": "/file/RKwgZb/info", @@ -139,7 +140,8 @@ "description": "", "date_created": 1513033304, "date_last_view": 1513033304, - "views": 2 + "views": 2, + "bandwidth_used": 1234567890 }, { "detail_href": "/file/DRaL_e/info", @@ -148,7 +150,8 @@ "description": "", "date_created": 1513033304, "date_last_view": 1513033304, - "views": 3 + "views": 3, + "bandwidth_used": 1234567890 } ] } diff --git a/webcontroller/file_viewer.go b/webcontroller/file_viewer.go index e4fdd8b..887816e 100644 --- a/webcontroller/file_viewer.go +++ b/webcontroller/file_viewer.go @@ -82,16 +82,17 @@ func (wc *WebController) serveFileViewerDemo(w http.ResponseWriter, r *http.Requ templateData.Other = viewerData{ Type: "file", APIResponse: map[string]interface{}{ - "id": "demo", - "name": "Demo file", - "date_upload": "2017-01-01 12:34:56", - "date_lastview": "2017-01-01 12:34:56", - "size": 123456789, - "views": 1, - "mime_type": "text/demo", - "description": "A file to demonstrate the viewer page", - "mime_image": "/res/img/mime/text.png", - "thumbnail": "/res/img/mime/text.png", + "id": "demo", + "name": "Demo file", + "date_upload": "2017-01-01 12:34:56", + "date_lastview": "2017-01-01 12:34:56", + "size": 123456789, + "views": 1, + "bandwidth_used": 123456789, + "mime_type": "text/demo", + "description": "A file to demonstrate the viewer page", + "mime_image": "/res/img/mime/text.png", + "thumbnail": "/res/img/mime/text.png", }, } err := wc.templates.Get().ExecuteTemplate(w, "file_viewer", templateData) From bd8ebcddf12d7552f0815802aba285b61ecea41e Mon Sep 17 00:00:00 2001 From: Wim Brand Date: Wed, 27 Mar 2019 17:06:05 +0100 Subject: [PATCH 2/8] Add BAT donation link --- res/template/home.html | 77 ++++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 33 deletions(-) diff --git a/res/template/home.html b/res/template/home.html index 8b3ac04..287f27e 100644 --- a/res/template/home.html +++ b/res/template/home.html @@ -61,24 +61,36 @@ nobody will see it.

-

What cookies does pixeldrain use?

+

Does pixeldrain cost any money?

- When uploading a file pixeldrain will install a cookie named - 'pduploads'. This cookie keeps a dot-separated list of all files - you have uploaded anonymously in this browser. This cookie is - only used for viewing your upload history. -

-

- When logging in to a pixeldrain account a cookie named - 'pd_auth_key' will be installed. This cookie keeps your login - session active. When you delete it you will be logged out of - your account. -

-

- When you use the style selector at the bottom of this page a - cookie called 'style' will be set. This cookie controls the - appearance of the website for you. + No, pixeldrain is completely free at the moment. While there is + an advertisement on the file downloading page, it doesn't + generate nearly enough revenue to pay for maintaining this + service. That's why I'd really appreciate it if you could spare + some coins. Possible methods for donating are:

+

Do I need to register an account?

@@ -97,25 +109,24 @@ page.

-

Does pixeldrain cost any money?

+

What cookies does pixeldrain use?

- No, pixeldrain is completely free at the moment. While there is - an advertisement on the file downloading page, it doesn't - generate nearly enough revenue to pay for maintaining this - service. That's why I'd really appreciate it if you could spare - some coins. Possible methods for donating are: + When uploading a file pixeldrain will install a cookie named + 'pduploads'. This cookie keeps a dot-separated list of all files + you have uploaded anonymously in this browser. This cookie is + only used for viewing your upload history. +

+

+ When logging in to a pixeldrain account a cookie named + 'pd_auth_key' will be installed. This cookie keeps your login + session active. When you delete it you will be logged out of + your account. +

+

+ When you use the style selector at the bottom of this page a + cookie called 'style' will be set. This cookie controls the + appearance of the website for you.

-

Legality

From 16d3bb118f49f29230191f9640965f7fda7e6bf6 Mon Sep 17 00:00:00 2001 From: Wim Brand Date: Wed, 27 Mar 2019 23:57:53 +0100 Subject: [PATCH 3/8] Beginning of malware warning --- pixelapi/file.go | 1 + res/static/script/Toolbar.js | 40 ++++++++++++++++++++++++++++++++++- res/static/style/viewer.css | 18 ++++++++++++++++ res/template/file_viewer.html | 6 +++++- webcontroller/file_viewer.go | 8 +++++-- webcontroller/list_viewer.go | 3 ++- 6 files changed, 71 insertions(+), 5 deletions(-) diff --git a/pixelapi/file.go b/pixelapi/file.go index 2fd7343..f584520 100644 --- a/pixelapi/file.go +++ b/pixelapi/file.go @@ -24,6 +24,7 @@ type FileInfo struct { MimeType string `json:"mime_type"` MimeImage string `json:"mime_image"` ThumbnailHREF string `json:"thumbnail_href"` + Availability string `json:"availability"` } // GetFileInfo gets the FileInfo from the pixeldrain API diff --git a/res/static/script/Toolbar.js b/res/static/script/Toolbar.js index e6c9dda..92a236f 100644 --- a/res/static/script/Toolbar.js +++ b/res/static/script/Toolbar.js @@ -30,7 +30,45 @@ var Toolbar = { } }, download: function () { - document.getElementById("download_frame").src = "/api/file/" + Viewer.currentFile + "?download"; + var triggerDL = function(){ + document.getElementById("download_frame").src = "/api/file/" + Viewer.currentFile + "?download"; + } + + if (captchaKey === "a"){ + // If the server doesn't support captcha there's no use in checking + // availability + triggerDL(); + return; + } + + $.getJSON( + apiEndpoint + "/file/" + Viewer.currentFile + "/availability" + ).done(function(data){ + if(data.success === true){ + // Downloading is allowed, start the download + triggerDL(); + } + }).fail(function(data){ + console.log(data); + if(data.responseJSON.success === false) { + var popupDiv = document.getElementById("captcha_popup"); + + if(data.responseJSON.value === "file_rate_limited_captcha_required") { + popupDiv.innerHTML = '

Rate limiting enabled!
'+ + data.responseJSON.message; + }else if(data.responseJSON.value === "virus_detected_captcha_required"){ + popupDiv.innerHTML = '
Malware warning!
'+ + data.responseJSON.message+ + "
Malware type: " + data.responseJSON.extra; + } + + popupDiv.style.opacity = "1"; + popupDiv.style.visibility = "visible"; + }else{ + // No JSON, try download anyway + triggerDL(); + } + }); }, downloadList: function(){ if(!Viewer.isList){ diff --git a/res/static/style/viewer.css b/res/static/style/viewer.css index ba2fba1..36e7401 100644 --- a/res/static/style/viewer.css +++ b/res/static/style/viewer.css @@ -208,6 +208,24 @@ body{ box-shadow: var(--shadow_color) 0px 0px 50px; z-index: 100; } +.captcha_popup{ + position: fixed; + visibility: hidden; + opacity: 0; + transition: visibility 1s, opacity 1s, left 1s; + background-color: var(--background_color); + height: auto; + width: 500px; + max-width: 100%; + top: 50px; + left: 50%; + margin-left: -200px; + padding: 0 10px; + box-sizing: border-box; + text-align: left; + box-shadow: var(--shadow_color) 0px 0px 50px; + z-index: 100; +} table {width: auto !important;} table > tbody > tr {border: none !important;} diff --git a/res/template/file_viewer.html b/res/template/file_viewer.html index 99e1ea1..6c6f39f 100644 --- a/res/template/file_viewer.html +++ b/res/template/file_viewer.html @@ -29,7 +29,10 @@ - + @@ -163,6 +166,7 @@
+
diff --git a/webcontroller/file_viewer.go b/webcontroller/file_viewer.go index 887816e..712e97e 100644 --- a/webcontroller/file_viewer.go +++ b/webcontroller/file_viewer.go @@ -12,6 +12,7 @@ import ( type viewerData struct { Type string // file or list + CaptchaKey string APIResponse interface{} } @@ -52,7 +53,8 @@ func (wc *WebController) serveFileViewer(w http.ResponseWriter, r *http.Request, if list { templateData.Title = fmt.Sprintf("%d files in Pixeldrain", len(finfo)) templateData.Other = viewerData{ - Type: "list", + Type: "list", + CaptchaKey: wc.captchaSiteKey, APIResponse: map[string]interface{}{ "data": finfo, "date_created": "now", @@ -65,6 +67,7 @@ func (wc *WebController) serveFileViewer(w http.ResponseWriter, r *http.Request, templateData.Title = fmt.Sprintf("%s ~ Pixeldrain file", finfo[0].Name) templateData.Other = viewerData{ Type: "file", + CaptchaKey: wc.captchaSiteKey, APIResponse: finfo[0], } } @@ -80,7 +83,8 @@ func (wc *WebController) serveFileViewer(w http.ResponseWriter, r *http.Request, func (wc *WebController) serveFileViewerDemo(w http.ResponseWriter, r *http.Request) { templateData := wc.newTemplateData(w, r) templateData.Other = viewerData{ - Type: "file", + Type: "file", + CaptchaKey: wc.captchaSiteKey, APIResponse: map[string]interface{}{ "id": "demo", "name": "Demo file", diff --git a/webcontroller/list_viewer.go b/webcontroller/list_viewer.go index c63991c..330bb5f 100644 --- a/webcontroller/list_viewer.go +++ b/webcontroller/list_viewer.go @@ -26,7 +26,8 @@ func (wc *WebController) serveListViewer(w http.ResponseWriter, r *http.Request, templateData.Title = fmt.Sprintf("%s ~ Pixeldrain list", list.Title) templateData.OGData = OpenGraphFromList(*list) templateData.Other = viewerData{ - Type: "list", + Type: "list", + CaptchaKey: wc.captchaSiteKey, APIResponse: map[string]interface{}{ "id": list.ID, "data": list.Files, From 52345de7335ce5946f552b732868986b92831cb6 Mon Sep 17 00:00:00 2001 From: Wim Brand Date: Thu, 28 Mar 2019 10:47:27 +0100 Subject: [PATCH 4/8] Add download captcha UI --- res/static/script/Toolbar.js | 40 ++++++++++++++++++++++++++++----- res/static/style/viewer.css | 4 ++++ res/template/file_viewer.html | 7 +++++- webcontroller/file_viewer.go | 4 ++-- webcontroller/user_account.go | 19 +--------------- webcontroller/web_controller.go | 20 +++++++++++++++++ 6 files changed, 67 insertions(+), 27 deletions(-) diff --git a/res/static/script/Toolbar.js b/res/static/script/Toolbar.js index 92a236f..857438a 100644 --- a/res/static/script/Toolbar.js +++ b/res/static/script/Toolbar.js @@ -49,19 +49,30 @@ var Toolbar = { triggerDL(); } }).fail(function(data){ - console.log(data); if(data.responseJSON.success === false) { var popupDiv = document.getElementById("captcha_popup"); + var popupTitle = document.getElementById("captcha_popup_title"); + var popupContent = document.getElementById("captcha_popup_content"); + var popupCaptcha = document.getElementById("captcha_popup_captcha"); if(data.responseJSON.value === "file_rate_limited_captcha_required") { - popupDiv.innerHTML = '
Rate limiting enabled!
'+ - data.responseJSON.message; + popupTitle.innerText = "Rate limiting enabled!"; + popupContent.innerText = "This file is using a suspicious "+ + "amount of bandwidth relative to its popularity. To "+ + "continue downloading this file you will have to "+ + "prove that you're a human first."; }else if(data.responseJSON.value === "virus_detected_captcha_required"){ - popupDiv.innerHTML = '
Malware warning!
'+ - data.responseJSON.message+ - "
Malware type: " + data.responseJSON.extra; + popupTitle.innerText = "Malware warning!"; + popupContent.innerText = "According to our scanning "+ + "systems this file may contain a virus (type '"+ + data.responseJSON.extra+"'). You can continue "+ + "downloading this file at your own risk, but you will "+ + "have to prove that you're a human first."; } + // Load the recaptcha script with a load function + $.getScript("https://www.google.com/recaptcha/api.js?onload=loadCaptcha&render=explicit"); + popupDiv.style.opacity = "1"; popupDiv.style.visibility = "visible"; }else{ @@ -135,6 +146,23 @@ function copyText(text) { return success; } +function loadCaptcha(){ + grecaptcha.render("captcha_popup_captcha", { + sitekey: captchaKey, + theme: "dark", + callback: function(token){ + document.getElementById("download_frame").src = "/api/file/" + Viewer.currentFile + + "?download&recaptcha_response="+token; + + setTimeout(function(){ + var popupDiv = document.getElementById("captcha_popup"); + popupDiv.style.opacity = "0"; + popupDiv.style.visibility = "hidden"; + }, 1000) + } + }); +} + var DetailsWindow = { visible: false, popupDiv: document.getElementById("info_popup"), diff --git a/res/static/style/viewer.css b/res/static/style/viewer.css index 36e7401..4cf75d7 100644 --- a/res/static/style/viewer.css +++ b/res/static/style/viewer.css @@ -214,6 +214,7 @@ body{ opacity: 0; transition: visibility 1s, opacity 1s, left 1s; background-color: var(--background_color); + border-color: var(--accent_color_dark_border); height: auto; width: 500px; max-width: 100%; @@ -226,6 +227,9 @@ body{ box-shadow: var(--shadow_color) 0px 0px 50px; z-index: 100; } +#captcha_popup_captcha > div { + display: inline-block; +} table {width: auto !important;} table > tbody > tr {border: none !important;} diff --git a/res/template/file_viewer.html b/res/template/file_viewer.html index 6c6f39f..336c779 100644 --- a/res/template/file_viewer.html +++ b/res/template/file_viewer.html @@ -166,7 +166,12 @@
-
+
+
+
+
+
+
diff --git a/webcontroller/file_viewer.go b/webcontroller/file_viewer.go index 712e97e..7c9b848 100644 --- a/webcontroller/file_viewer.go +++ b/webcontroller/file_viewer.go @@ -54,7 +54,7 @@ func (wc *WebController) serveFileViewer(w http.ResponseWriter, r *http.Request, templateData.Title = fmt.Sprintf("%d files in Pixeldrain", len(finfo)) templateData.Other = viewerData{ Type: "list", - CaptchaKey: wc.captchaSiteKey, + CaptchaKey: wc.captchaKey(), APIResponse: map[string]interface{}{ "data": finfo, "date_created": "now", @@ -67,7 +67,7 @@ func (wc *WebController) serveFileViewer(w http.ResponseWriter, r *http.Request, templateData.Title = fmt.Sprintf("%s ~ Pixeldrain file", finfo[0].Name) templateData.Other = viewerData{ Type: "file", - CaptchaKey: wc.captchaSiteKey, + CaptchaKey: wc.captchaKey(), APIResponse: finfo[0], } } diff --git a/webcontroller/user_account.go b/webcontroller/user_account.go index f83b4eb..f1bdaf1 100644 --- a/webcontroller/user_account.go +++ b/webcontroller/user_account.go @@ -14,24 +14,7 @@ func (wc *WebController) serveRegister( p httprouter.Params, ) { var tpld = wc.newTemplateData(w, r) - - // This only runs on the first request - if wc.captchaSiteKey == "" { - var api = pixelapi.New(wc.conf.APIURLInternal, "") - capt, err := api.GetRecaptcha() - if err != nil { - log.Error("Error getting recaptcha key: %s", err) - w.WriteHeader(http.StatusInternalServerError) - return - } - if capt.SiteKey == "" { - wc.captchaSiteKey = "none" - } else { - wc.captchaSiteKey = capt.SiteKey - } - } - - tpld.Other = wc.captchaSiteKey + tpld.Other = wc.captchaKey() err := wc.templates.Get().ExecuteTemplate(w, "register", tpld) if err != nil { diff --git a/webcontroller/web_controller.go b/webcontroller/web_controller.go index e55469f..b5cbfe4 100644 --- a/webcontroller/web_controller.go +++ b/webcontroller/web_controller.go @@ -7,6 +7,7 @@ import ( "github.com/google/uuid" "fornaxian.com/pixeldrain-web/init/conf" + "fornaxian.com/pixeldrain-web/pixelapi" "github.com/Fornaxian/log" "github.com/julienschmidt/httprouter" ) @@ -118,3 +119,22 @@ func (wc *WebController) getAPIKey(r *http.Request) (key string, err error) { } return "", errors.New("not a valid pixeldrain authentication cookie") } + +func (wc *WebController) captchaKey() string { + // This only runs on the first request + if wc.captchaSiteKey == "" { + var api = pixelapi.New(wc.conf.APIURLInternal, "") + capt, err := api.GetRecaptcha() + if err != nil { + log.Error("Error getting recaptcha key: %s", err) + return "" + } + if capt.SiteKey == "" { + wc.captchaSiteKey = "none" + } else { + wc.captchaSiteKey = capt.SiteKey + } + } + + return wc.captchaSiteKey +} From 1138fd0eea807914876d6c75dd9728fdbcbf31ed Mon Sep 17 00:00:00 2001 From: Wim Brand Date: Thu, 28 Mar 2019 11:25:35 +0100 Subject: [PATCH 5/8] Fix user authentication when backend is down --- webcontroller/template_data.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/webcontroller/template_data.go b/webcontroller/template_data.go index 8749db7..2f2313c 100644 --- a/webcontroller/template_data.go +++ b/webcontroller/template_data.go @@ -40,14 +40,20 @@ func (wc *WebController) newTemplateData(w http.ResponseWriter, r *http.Request) t.PixelAPI = pixelapi.New(wc.conf.APIURLInternal, key) uinf, err := t.PixelAPI.UserInfo() if err != nil { - // This session key doesn't work, delete it + // This session key doesn't work, or the backend is down, user + // cannot be authenticated log.Debug("Session check for key '%s' failed: %s", key, err) - http.SetCookie(w, &http.Cookie{ - Name: "pd_auth_key", - Value: "", - Path: "/", - Expires: time.Unix(0, 0), - }) + + if aerr, ok := err.(pixelapi.Error); ok && aerr.Value == "authentication_required" { + // This key is invalid, delete it + log.Debug("Deleting invalid API key") + http.SetCookie(w, &http.Cookie{ + Name: "pd_auth_key", + Value: "", + Path: "/", + Expires: time.Unix(0, 0), + }) + } return t } From 1609b8cb9a1abe048380f568d606d402b96ef960 Mon Sep 17 00:00:00 2001 From: Wim Brand Date: Thu, 28 Mar 2019 11:39:13 +0100 Subject: [PATCH 6/8] Fix error check --- webcontroller/template_data.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webcontroller/template_data.go b/webcontroller/template_data.go index 2f2313c..d229e01 100644 --- a/webcontroller/template_data.go +++ b/webcontroller/template_data.go @@ -44,7 +44,7 @@ func (wc *WebController) newTemplateData(w http.ResponseWriter, r *http.Request) // cannot be authenticated log.Debug("Session check for key '%s' failed: %s", key, err) - if aerr, ok := err.(pixelapi.Error); ok && aerr.Value == "authentication_required" { + if err.Error() == "authentication_required" || err.Error() == "authentication_failed" { // This key is invalid, delete it log.Debug("Deleting invalid API key") http.SetCookie(w, &http.Cookie{ From 991b699416d84dd6c17eb7809024e9054d4bc128 Mon Sep 17 00:00:00 2001 From: Wim Brand Date: Fri, 29 Mar 2019 15:33:33 +0100 Subject: [PATCH 7/8] Remove links from previews --- webcontroller/file_preview.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/webcontroller/file_preview.go b/webcontroller/file_preview.go index ca442da..f473b7e 100644 --- a/webcontroller/file_preview.go +++ b/webcontroller/file_preview.go @@ -187,11 +187,10 @@ seamless="seamless" frameborder="0" allowtransparency="true" func (f filePreview) def() string { return fmt.Sprintf( - `%s
%s
`, + `



%s
Type: '%s'`, + f.APIURL+f.FileInfo.ThumbnailHREF, f.FileInfo.Name, f.FileInfo.MimeType, - f.DownloadURL, - f.APIURL+f.FileInfo.ThumbnailHREF, ) } From 6448b4d3db9d199be0787a087783beabd8aa473a Mon Sep 17 00:00:00 2001 From: Wim Brand Date: Sun, 31 Mar 2019 21:06:52 +0200 Subject: [PATCH 8/8] Add hacker style --- res/static/script/Toolbar.js | 6 +++--- res/static/style/layout.css | 3 ++- res/static/style/viewer.css | 11 +++++------ res/template/home.html | 3 ++- webcontroller/user_style.go | 26 +++++++++++++++++++++++--- 5 files changed, 35 insertions(+), 14 deletions(-) diff --git a/res/static/script/Toolbar.js b/res/static/script/Toolbar.js index 857438a..0e73270 100644 --- a/res/static/script/Toolbar.js +++ b/res/static/script/Toolbar.js @@ -64,8 +64,8 @@ var Toolbar = { }else if(data.responseJSON.value === "virus_detected_captcha_required"){ popupTitle.innerText = "Malware warning!"; popupContent.innerText = "According to our scanning "+ - "systems this file may contain a virus (type '"+ - data.responseJSON.extra+"'). You can continue "+ + "systems this file may contain a virus of type '"+ + data.responseJSON.extra+"'. You can continue "+ "downloading this file at your own risk, but you will "+ "have to prove that you're a human first."; } @@ -153,7 +153,7 @@ function loadCaptcha(){ callback: function(token){ document.getElementById("download_frame").src = "/api/file/" + Viewer.currentFile + "?download&recaptcha_response="+token; - + setTimeout(function(){ var popupDiv = document.getElementById("captcha_popup"); popupDiv.style.opacity = "0"; diff --git a/res/static/style/layout.css b/res/static/style/layout.css index 90ee469..236b09f 100644 --- a/res/static/style/layout.css +++ b/res/static/style/layout.css @@ -103,12 +103,13 @@ body{ font-family: "Lato Thin", sans-serif; font-weight: bold; font-size: 1.8em; - transition: box-shadow 0.5s; + transition: box-shadow 2s; } .navigation a:hover { background: linear-gradient(var(--highlight_color), var(--highlight_color_dark)); box-shadow: var(--highlight_border), 2px 2px 8px var(--shadow_color); color: var(--highlight_text_color); + transition: box-shadow 0.5s; text-decoration: none; } .navigation .icon { diff --git a/res/static/style/viewer.css b/res/static/style/viewer.css index 4cf75d7..e0909fd 100644 --- a/res/static/style/viewer.css +++ b/res/static/style/viewer.css @@ -190,7 +190,6 @@ body{ /* ===================== || MISC COMPONENTS || ===================== */ - .full_popup{ position: fixed; visibility: hidden; @@ -214,18 +213,18 @@ body{ opacity: 0; transition: visibility 1s, opacity 1s, left 1s; background-color: var(--background_color); - border-color: var(--accent_color_dark_border); + border-color: var(--accent_color_dark_border); height: auto; - width: 500px; + width: 450px; max-width: 100%; - top: 50px; + top: 10%; left: 50%; - margin-left: -200px; + transform: translate(-50%, -10%); padding: 0 10px; box-sizing: border-box; text-align: left; box-shadow: var(--shadow_color) 0px 0px 50px; - z-index: 100; + z-index: 101; } #captcha_popup_captcha > div { display: inline-block; diff --git a/res/template/home.html b/res/template/home.html index 287f27e..a1993fa 100644 --- a/res/template/home.html +++ b/res/template/home.html @@ -75,7 +75,7 @@ BasicAttentionToken: Donate BAT by clicking the BAT icon in your address bar. If you don't have Brave browser yet you can download it here: - Install Brave. + Install Brave. Installing and using Brave with this referral link also counts as a 5$ donation. @@ -150,6 +150,7 @@


+
{{template "footer"}}
diff --git a/webcontroller/user_style.go b/webcontroller/user_style.go index b29e722..afec7ef 100644 --- a/webcontroller/user_style.go +++ b/webcontroller/user_style.go @@ -15,15 +15,14 @@ func userStyle(r *http.Request) (style template.CSS) { switch cookie.Value { case "solarized_dark": selectedStyle = solarizedDarkStyle - break case "maroon": selectedStyle = maroonStyle - break + case "hacker": + selectedStyle = hackerStyle case "default": fallthrough // use default case default: selectedStyle = defaultPixeldrainStyle - break } } @@ -205,3 +204,24 @@ var maroonStyle = pixeldrainStyleSheet{ ShadowSpread: 50, ShadowIntensity: 5, } + +var hackerStyle = pixeldrainStyleSheet{ + TextColor: hsl{0, 0, 1}, + InputColor: hsl{0, 0, .25}, + InputTextColor: hsl{0, 0, 1}, + HighlightColor: hsl{120, 1, .6}, + HighlightTextColor: hsl{0, 0, 0}, + DangerColor: hsl{0, .65, .31}, + DangerColorDark: hsl{0, .64, .23}, + FileBackgroundColor: hsl{120, .8, .06}, + + BackgroundColor: hsl{0, 0, 0}, + BodyColor: hsl{0, 0, 0}, + AccentColorDark: hsl{0, 0, .05}, + AccentColorMedium: hsl{0, 0, .10}, + AccentColorLight: hsl{0, 0, .15}, + + ShadowColor: hsl{120, 1, .1}, + ShadowSpread: 50, + ShadowIntensity: 5, +}