From 12d2560133413757d299e242424111b993589a32 Mon Sep 17 00:00:00 2001 From: Wim Brand Date: Mon, 25 Jun 2018 23:05:18 +0200 Subject: [PATCH] move meta tags to template, begin of user portal --- pixelapi/file.go | 23 ++--- res/static/res/script/compiled/home.js | 4 +- res/static/res/script/history.js | 19 ++-- res/static/res/typescript/home/home.ts | 9 +- res/static/res/typescript/lib/uploader.ts | 14 +-- res/template/account/filemanager.html | 20 +++++ res/template/account/files.html | 75 ---------------- res/template/account/login.html | 27 +----- res/template/account/logout.html | 35 ++------ res/template/account/register.html | 31 +------ res/template/account/user.html | 101 +++------------------- res/template/apidoc.html | 32 +------ res/template/error.html | 32 ++----- res/template/file_not_found.html | 34 +++----- res/template/fragments/menu.html | 5 +- res/template/fragments/metatags.html | 26 ++++++ res/template/history.html | 32 +------ res/template/home.html | 28 +----- webcontroller/templateData.go | 6 +- webcontroller/webcontroller.go | 6 +- 20 files changed, 136 insertions(+), 423 deletions(-) create mode 100644 res/template/account/filemanager.html delete mode 100644 res/template/account/files.html create mode 100644 res/template/fragments/metatags.html diff --git a/pixelapi/file.go b/pixelapi/file.go index b90ac85..e14f71f 100644 --- a/pixelapi/file.go +++ b/pixelapi/file.go @@ -2,6 +2,7 @@ package pixelapi import ( "io" + "time" ) // GetFile makes a file download request and returns a readcloser. Don't forget @@ -12,17 +13,17 @@ func (p *PixelAPI) GetFile(id string) (io.ReadCloser, error) { // FileInfo File information object from the pixeldrain API type FileInfo struct { - ID string `json:"id"` - FileName string `json:"file_name"` - DateUpload int64 `json:"date_upload"` - DateLastview int64 `json:"date_last_view"` - DaysValid uint16 `json:"days_valid"` - FileSize uint64 `json:"file_size"` - Views uint `json:"views"` - MimeType string `json:"mime_type"` - Description string `json:"description"` - MimeImage string `json:"mime_image"` - ThumbnailHREF string `json:"thumbnail_href"` + ID string `json:"id"` + FileName string `json:"file_name"` + DateUpload time.Time `json:"date_upload"` + DateLastview time.Time `json:"date_last_view"` + DaysValid uint16 `json:"days_valid"` + FileSize uint64 `json:"file_size"` + Views uint `json:"views"` + MimeType string `json:"mime_type"` + Description string `json:"description"` + MimeImage string `json:"mime_image"` + ThumbnailHREF string `json:"thumbnail_href"` } // GetFileInfo gets the FileInfo from the pixeldrain API diff --git a/res/static/res/script/compiled/home.js b/res/static/res/script/compiled/home.js index 38f959d..a7b7fdf 100644 --- a/res/static/res/script/compiled/home.js +++ b/res/static/res/script/compiled/home.js @@ -26,7 +26,7 @@ var UploadProgressBar = /** @class */ (function () { this.uploadDiv.setAttribute('style', 'background: #111'); this.uploadDiv.setAttribute('href', '/u/' + id); this.uploadDiv.setAttribute("target", "_blank"); - this.uploadDivJQ.html('' + this.file.name + '' + this.uploadDivJQ.html('' + this.file.name + '' + this.file.name + '
' + '' + window.location.hostname + '/u/' + id + ''); }; @@ -161,7 +161,7 @@ var UploadWorker = /** @class */ (function () { var that = this; // jquery changes the definiton of "this" $.ajax({ type: 'POST', - url: "/api/file", + url: apiEndpoint + "/file", data: formData, timeout: 7200000, cache: false, diff --git a/res/static/res/script/history.js b/res/static/res/script/history.js index e73752d..3549438 100644 --- a/res/static/res/script/history.js +++ b/res/static/res/script/history.js @@ -1,6 +1,3 @@ - -/* global API_URL */ - var uploads; $(document).ready(function () { @@ -17,7 +14,7 @@ $(document).ready(function () { $.ajax({ type: "GET", dataType: "json", - url: APIURL + "/file/" + id + "/info", + url: apiEndpoint + "/file/" + id + "/info", async: true, success: function(data) { historyAddItem(data); @@ -45,19 +42,21 @@ function historyAddItem(json) { + ""; $("#uploadedFiles").append($(uploadItem).hide().fadeIn(400)); - + return; } - - var date = new Date(json.date_upload * 1000); + + var date = new Date(json.date_upload); var uploadItem = '' - + '" + ''+json.file_name+'' + "
" - + date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + + date.getFullYear() + "-" + + ("00" + (date.getMonth() + 1)).slice(-2) + "-" + + ("00" + date.getDate()).slice(-2) + "
"; $("#uploadedFiles").append($(uploadItem).hide().fadeIn(400)); -} \ No newline at end of file +} diff --git a/res/static/res/typescript/home/home.ts b/res/static/res/typescript/home/home.ts index ccd4395..53b53aa 100644 --- a/res/static/res/typescript/home/home.ts +++ b/res/static/res/typescript/home/home.ts @@ -1,3 +1,4 @@ +declare var apiEndpoint: string; var uploader: UploadManager|null = null; var finishedUploads: Array = new Array() var totalUploads: number = 0 @@ -29,7 +30,7 @@ class UploadProgressBar implements FileUpload { public onProgress(progress: number){ this.uploadDiv.innerText = "Uploading... " + Math.round(progress*1000)/10 + "%\n" + this.file.name this.uploadDiv.setAttribute( - 'style', + 'style', 'background: linear-gradient(' +'to right, ' +'#111 0%, ' @@ -44,7 +45,7 @@ class UploadProgressBar implements FileUpload { this.uploadDiv.setAttribute('href', '/u/'+id) this.uploadDiv.setAttribute("target", "_blank"); this.uploadDivJQ.html( - ''+this.file.name+'' + ''+this.file.name+'' + this.file.name+'
' + ''+window.location.hostname+'/u/'+id+'' ) @@ -82,7 +83,7 @@ $("#select_file_button").click(function(){$("#file_input_field").click()}) $("#file_input_field").change(function(evt){ handleUploads((evt.target).files) - + // This resets the file input field // http://stackoverflow.com/questions/1043957/clearing-input-type-file-using-jquery $('#file_name').html("") @@ -109,4 +110,4 @@ document.addEventListener('drop', function(e: DragEvent){ handleUploads(e.dataTransfer.files) } -}) \ No newline at end of file +}) diff --git a/res/static/res/typescript/lib/uploader.ts b/res/static/res/typescript/lib/uploader.ts index 611bade..7cf2f00 100644 --- a/res/static/res/typescript/lib/uploader.ts +++ b/res/static/res/typescript/lib/uploader.ts @@ -1,3 +1,5 @@ +declare var apiEndpoint: string; + interface FileUpload { file: Blob name: string @@ -56,7 +58,7 @@ class UploadWorker { console.debug("No files left in queue") return // Stop the thread } - + this.uploading = true this.tries = 0 this.upload(file) @@ -73,7 +75,7 @@ class UploadWorker { $.ajax({ type: 'POST', - url: "/api/file", + url: apiEndpoint+"/file", data: formData, timeout: 7200000, // 2 hours cache: false, @@ -117,13 +119,13 @@ class UploadWorker { private setHistoryCookie(id: string){ var uc = Cookie.read("pduploads") - + // First upload in this browser if (uc === null) { Cookie.write("pduploads", id + ".", undefined) return } - + if (uc.length > 2000){ // Cookie is becoming too long, drop the oldest two files uc = uc.substring( @@ -132,7 +134,7 @@ class UploadWorker { uc.indexOf(".") + 1 ) } - + Cookie.write("pduploads", uc + id + ".", undefined) } -} \ No newline at end of file +} diff --git a/res/template/account/filemanager.html b/res/template/account/filemanager.html new file mode 100644 index 0000000..5fbecc8 --- /dev/null +++ b/res/template/account/filemanager.html @@ -0,0 +1,20 @@ +{{define "file_manager"}} + + + {{template "meta_tags" "File Manager"}} + + + + + {{template "menu" .}} +
+ These files were uploaded while logged in to your pixeldrain account, + click here to view files uploaded anonymously + in this browser. +
+ + + {{template "analytics"}} + + +{{end}} diff --git a/res/template/account/files.html b/res/template/account/files.html deleted file mode 100644 index 2c02d2d..0000000 --- a/res/template/account/files.html +++ /dev/null @@ -1,75 +0,0 @@ - - - - File Browser ~ PixelDrain - - - - - - - - - - - - - - - - - - - -
-
-
- -
- Previous -   <--  0  -->   - Nextious -
- - - -
- Previous -   <--  0  -->   - Nextious -
-
- - - - - diff --git a/res/template/account/login.html b/res/template/account/login.html index 57d1579..abbe13c 100644 --- a/res/template/account/login.html +++ b/res/template/account/login.html @@ -2,34 +2,9 @@ - Login ~ PixelDrain - - - - - - - - - - - {{template "bgpattern"}} - - - - - - - - - - + {{template "meta_tags" "Login"}} -
{{template "menu" .}} diff --git a/res/template/account/logout.html b/res/template/account/logout.html index 242aef6..1424cc3 100644 --- a/res/template/account/logout.html +++ b/res/template/account/logout.html @@ -1,30 +1,7 @@ {{define "logout"}} - Logging out... ~ Pixeldrain - - - - - - - - - - - {{template "bgpattern"}} - - - - - - - - - + {{template "meta_tags" "Logging out..."}}
@@ -39,15 +16,15 @@

We need you to confirm your action here so we can be sure that you really requested a logout. If we didn't do this, anyone (or - any website) would be able to send you to the page - pixeldrain.com/logout and you would automatically get logged - out of Pixeldrain, which would be very annoying. + any website) would be able to send you to this page and you + would automatically get logged out of Pixeldrain, which would be + very annoying.

To prevent this from happening we're verifying that you actually - want to log out by making you submit this form. Because this + want to log out by making you click this button. Because this logout button triggers a different request type than normal - page vitis we can confirm that you really want to log out. + page visit we can confirm that you really want to log out.

{{template "footer"}} diff --git a/res/template/account/register.html b/res/template/account/register.html index 0220b37..716a748 100644 --- a/res/template/account/register.html +++ b/res/template/account/register.html @@ -1,34 +1,7 @@ -{{define "register"}} - +{{define "register"}} - Register ~ PixelDrain - - - - - - - - - - - - - - - - - - - - - - - {{template "bgpattern"}} + {{template "meta_tags" "Register"}} diff --git a/res/template/account/user.html b/res/template/account/user.html index 20e5e6b..6cc06a8 100644 --- a/res/template/account/user.html +++ b/res/template/account/user.html @@ -1,99 +1,18 @@ - - +{{define "user_home"}} + - File Overview ~ PixelDrain - - - - - - - - - - - - - - - - - + {{template "meta_tags" .Username}} +
-
-
- Logged in as . Log out. -

- Bandwidth used past 24 hours:
-
- -
- -
-
-
- Total size of your files: . -

- Your 20 most recently uploaded files: - -
- -
- Your 20 most recently created lists: - - + {{template "menu" .}} +

Welcome home, {{.Username}}!

+ + {{template "footer"}}
- - - + {{template "analytics"}} +{{end}} diff --git a/res/template/apidoc.html b/res/template/apidoc.html index 659f227..e8dcc65 100644 --- a/res/template/apidoc.html +++ b/res/template/apidoc.html @@ -1,33 +1,7 @@ -{{define "apidoc"}} - - +{{define "apidoc"}} + - PixelDrain ~ API Documentation - - - - - - - - - - - - - {{template "bgpattern"}} - - - - - - - - - + {{template "meta_tags" "API Documentation"}} diff --git a/res/template/error.html b/res/template/error.html index bed2008..aa73502 100644 --- a/res/template/error.html +++ b/res/template/error.html @@ -1,39 +1,17 @@ -{{define "error"}} - - +{{define "error"}} + - PixelDrain ~ Error - - - - - - - - - - - - {{template "bgpattern"}} - - - - - - - - - + {{template "meta_tags" "Error"}}
{{template "menu" .}}
-

Some Error occured

+

Some Error occurred

Either you made a mistake, or I made a mistake.

- Anyway, there's nothing to see here, so you'll have to head over to the index page. + Either way, there's nothing to see here, so you'll have to head over to the home page.

Bye! diff --git a/res/template/file_not_found.html b/res/template/file_not_found.html index 9f9c807..487e893 100644 --- a/res/template/file_not_found.html +++ b/res/template/file_not_found.html @@ -1,27 +1,21 @@ -{{define "file_not_found"}} - +{{define "file_not_found"}} - File not found ~ PixelDrain - - - - - - - - + {{template "meta_tags" "File Not Found"}} - -

File not Found

- I'm sorry, but this file does not exist!
- It may have expired, or taken down by the owner.
- You can Visit the homepage to upload your own files. -

- It was fun having you, bye for now! - +
+ {{template "menu"}} +

File not Found

+ I'm sorry, but this file does not exist!
+ It may have expired, or taken down by the owner.
+ You can Visit the homepage to upload your own files. +

+ It was fun having you, bye for now! +
+ {{template "footer"}} +
{{template "analytics"}} -{{end}} \ No newline at end of file +{{end}} diff --git a/res/template/fragments/menu.html b/res/template/fragments/menu.html index e5f0840..7ecb480 100644 --- a/res/template/fragments/menu.html +++ b/res/template/fragments/menu.html @@ -1,9 +1,10 @@ {{define "menu"}}