From 9a4eddcbd1c09fb74773278acd1f7da0d933cdf0 Mon Sep 17 00:00:00 2001 From: Wim Brand Date: Sun, 17 Dec 2017 23:34:49 +0100 Subject: [PATCH] Tweaks --- conf/config.go | 14 +++++++++----- pixelapi/file.go | 24 ++++++++++++------------ pixelapi/list.go | 2 +- res/static/res/script/history.js | 4 ++-- res/template/file_viewer.html | 2 +- res/template/history.html | 1 + webcontroller/filePreview.go | 6 +++--- webcontroller/history.go | 6 ++---- webcontroller/ogData.go | 2 +- webcontroller/templates/funcs.go | 5 +++++ 10 files changed, 37 insertions(+), 29 deletions(-) diff --git a/conf/config.go b/conf/config.go index 6a5a240..1a9f80e 100644 --- a/conf/config.go +++ b/conf/config.go @@ -11,7 +11,8 @@ import ( var vi *viper.Viper var defaultConfig = `# Pixeldrain Web UI server configuration -api_url = "http://127.0.0.1:8080/api" +api_url_external = "/api" # Used in the web browser, can be a relative path +api_url_internal = "http://127.0.0.1:8080/api" # Used for internal API requests to the pixeldrain server, not visible to users static_resource_dir = "res/static" template_dir = "res/template" debug_mode = false` @@ -32,7 +33,8 @@ func Init() { vi.AddConfigPath("/etc") vi.AddConfigPath("/usr/local/etc") - vi.SetDefault("api_url", "http://127.0.0.1:8080/api") + vi.SetDefault("api_url_external", "/api") + vi.SetDefault("api_url_internal", "http://127.0.0.1:8080/api") vi.SetDefault("static_resource_dir", "./res/static") vi.SetDefault("template_dir", "./res/template") vi.SetDefault("debug_mode", false) @@ -76,9 +78,11 @@ func writeCfg() { file.Close() } -// ApiURL returns the API URL -func ApiURL() string { - return vi.GetString("api_url") +func ApiUrlExternal() string { + return vi.GetString("api_url_external") +} +func ApiUrlInternal() string { + return vi.GetString("api_url_internal") } func StaticResourceDir() string { return vi.GetString("static_resource_dir") diff --git a/pixelapi/file.go b/pixelapi/file.go index 977cbb0..a03a185 100644 --- a/pixelapi/file.go +++ b/pixelapi/file.go @@ -9,22 +9,22 @@ import ( // 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"` - Thumbnail string `json:"thumbnail"` + 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"` } // GetFileInfo gets the FileInfo from the pixeldrain API func GetFileInfo(id string) *FileInfo { - body, err := get(conf.ApiURL() + "/file/" + id + "/info") + body, err := get(conf.ApiUrlInternal() + "/file/" + id + "/info") if err != nil { log.Error("req failed: %v", err) diff --git a/pixelapi/list.go b/pixelapi/list.go index 23b8f8e..4bb401c 100644 --- a/pixelapi/list.go +++ b/pixelapi/list.go @@ -28,7 +28,7 @@ type ListFile struct { // GetList get a List from the pixeldrain API func GetList(id string) *List { - body, err := get(conf.ApiURL() + "/list/" + id) + body, err := get(conf.ApiUrlInternal() + "/list/" + id) if err != nil { log.Error("req failed: %v", err) diff --git a/res/static/res/script/history.js b/res/static/res/script/history.js index 7c120ea..1bbcc18 100644 --- a/res/static/res/script/history.js +++ b/res/static/res/script/history.js @@ -17,7 +17,7 @@ $(document).ready(function () { $.ajax({ type: "GET", dataType: "json", - url: "/api/file/" + id + "/info", + url: APIURL + "/file/" + id + "/info", async: true, success: function(data) { historyAddItem(data); @@ -54,7 +54,7 @@ function historyAddItem(json) { var uploadItem = "
" + "" - + "" + json.file_name diff --git a/res/template/file_viewer.html b/res/template/file_viewer.html index a084308..43ef7a3 100644 --- a/res/template/file_viewer.html +++ b/res/template/file_viewer.html @@ -49,7 +49,7 @@ - Views: 0
+