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,