Tweaks
This commit is contained in:
@@ -11,7 +11,8 @@ import (
|
|||||||
var vi *viper.Viper
|
var vi *viper.Viper
|
||||||
|
|
||||||
var defaultConfig = `# Pixeldrain Web UI server configuration
|
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"
|
static_resource_dir = "res/static"
|
||||||
template_dir = "res/template"
|
template_dir = "res/template"
|
||||||
debug_mode = false`
|
debug_mode = false`
|
||||||
@@ -32,7 +33,8 @@ func Init() {
|
|||||||
vi.AddConfigPath("/etc")
|
vi.AddConfigPath("/etc")
|
||||||
vi.AddConfigPath("/usr/local/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("static_resource_dir", "./res/static")
|
||||||
vi.SetDefault("template_dir", "./res/template")
|
vi.SetDefault("template_dir", "./res/template")
|
||||||
vi.SetDefault("debug_mode", false)
|
vi.SetDefault("debug_mode", false)
|
||||||
@@ -76,9 +78,11 @@ func writeCfg() {
|
|||||||
file.Close()
|
file.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApiURL returns the API URL
|
func ApiUrlExternal() string {
|
||||||
func ApiURL() string {
|
return vi.GetString("api_url_external")
|
||||||
return vi.GetString("api_url")
|
}
|
||||||
|
func ApiUrlInternal() string {
|
||||||
|
return vi.GetString("api_url_internal")
|
||||||
}
|
}
|
||||||
func StaticResourceDir() string {
|
func StaticResourceDir() string {
|
||||||
return vi.GetString("static_resource_dir")
|
return vi.GetString("static_resource_dir")
|
||||||
|
@@ -19,12 +19,12 @@ type FileInfo struct {
|
|||||||
MimeType string `json:"mime_type"`
|
MimeType string `json:"mime_type"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
MimeImage string `json:"mime_image"`
|
MimeImage string `json:"mime_image"`
|
||||||
Thumbnail string `json:"thumbnail"`
|
ThumbnailHREF string `json:"thumbnail_href"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetFileInfo gets the FileInfo from the pixeldrain API
|
// GetFileInfo gets the FileInfo from the pixeldrain API
|
||||||
func GetFileInfo(id string) *FileInfo {
|
func GetFileInfo(id string) *FileInfo {
|
||||||
body, err := get(conf.ApiURL() + "/file/" + id + "/info")
|
body, err := get(conf.ApiUrlInternal() + "/file/" + id + "/info")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("req failed: %v", err)
|
log.Error("req failed: %v", err)
|
||||||
|
@@ -28,7 +28,7 @@ type ListFile struct {
|
|||||||
|
|
||||||
// GetList get a List from the pixeldrain API
|
// GetList get a List from the pixeldrain API
|
||||||
func GetList(id string) *List {
|
func GetList(id string) *List {
|
||||||
body, err := get(conf.ApiURL() + "/list/" + id)
|
body, err := get(conf.ApiUrlInternal() + "/list/" + id)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("req failed: %v", err)
|
log.Error("req failed: %v", err)
|
||||||
|
@@ -17,7 +17,7 @@ $(document).ready(function () {
|
|||||||
$.ajax({
|
$.ajax({
|
||||||
type: "GET",
|
type: "GET",
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
url: "/api/file/" + id + "/info",
|
url: APIURL + "/file/" + id + "/info",
|
||||||
async: true,
|
async: true,
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
historyAddItem(data);
|
historyAddItem(data);
|
||||||
@@ -54,7 +54,7 @@ function historyAddItem(json) {
|
|||||||
|
|
||||||
var uploadItem = "<div class=\"uploadItem\" >"
|
var uploadItem = "<div class=\"uploadItem\" >"
|
||||||
+ "<a href=\"/u/" + json.id + "\" target=\"_blank\">"
|
+ "<a href=\"/u/" + json.id + "\" target=\"_blank\">"
|
||||||
+ "<img src=\"" + json.thumbnail + "\" "
|
+ "<img src=\"" + APIURL + json.thumbnail_href + "\" "
|
||||||
+ "alt=\"" + json.file_name + "\" "
|
+ "alt=\"" + json.file_name + "\" "
|
||||||
+ "class=\"uploadItemImage\" />"
|
+ "class=\"uploadItemImage\" />"
|
||||||
+ json.file_name
|
+ json.file_name
|
||||||
|
@@ -49,7 +49,7 @@
|
|||||||
|
|
||||||
<button class="toolbar-button" onClick="Toolbar.toggle();">Hide Toolbar</button>
|
<button class="toolbar-button" onClick="Toolbar.toggle();">Hide Toolbar</button>
|
||||||
|
|
||||||
Views: <span id="views" th:text="${data.views}">0</span><br/>
|
<!--Views: <span id="views" th:text="${data.views}">0</span>--><br/>
|
||||||
|
|
||||||
<button id="btnDownload" class="toolbar-button" onClick="Toolbar.download();">
|
<button id="btnDownload" class="toolbar-button" onClick="Toolbar.download();">
|
||||||
<img src="/res/img/floppy_small.png" alt="Download this file"/>
|
<img src="/res/img/floppy_small.png" alt="Download this file"/>
|
||||||
|
@@ -21,6 +21,7 @@
|
|||||||
<script src="res/script/jquery-cookie.js"></script>
|
<script src="res/script/jquery-cookie.js"></script>
|
||||||
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css"/>
|
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css"/>
|
||||||
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
|
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
|
||||||
|
<script>var APIURL = "{{apiUrl}}";</script>
|
||||||
|
|
||||||
<meta name="description" content="PixelDrain is a free file sharing service, you
|
<meta name="description" content="PixelDrain is a free file sharing service, you
|
||||||
can upload any file and you will be given a shareable link right away.
|
can upload any file and you will be given a shareable link right away.
|
||||||
|
@@ -39,8 +39,8 @@ type FilePreview struct {
|
|||||||
|
|
||||||
func (f FilePreview) Run(inf *pixelapi.FileInfo) string {
|
func (f FilePreview) Run(inf *pixelapi.FileInfo) string {
|
||||||
f.FileInfo = inf
|
f.FileInfo = inf
|
||||||
f.FileURL = conf.ApiURL() + "/file/" + f.FileInfo.ID
|
f.FileURL = conf.ApiUrlExternal() + "/file/" + f.FileInfo.ID
|
||||||
f.DownloadURL = conf.ApiURL() + "/file/" + f.FileInfo.ID + "/download"
|
f.DownloadURL = conf.ApiUrlExternal() + "/file/" + f.FileInfo.ID + "/download"
|
||||||
|
|
||||||
if strings.HasPrefix(f.FileInfo.MimeType, "image") {
|
if strings.HasPrefix(f.FileInfo.MimeType, "image") {
|
||||||
return f.image()
|
return f.image()
|
||||||
@@ -135,6 +135,6 @@ func (f FilePreview) def() string {
|
|||||||
f.FileInfo.FileName,
|
f.FileInfo.FileName,
|
||||||
f.FileInfo.MimeType,
|
f.FileInfo.MimeType,
|
||||||
f.DownloadURL,
|
f.DownloadURL,
|
||||||
f.FileInfo.Thumbnail,
|
conf.ApiUrlExternal()+f.FileInfo.ThumbnailHREF,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@@ -3,16 +3,14 @@ package webcontroller
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"fornaxian.com/pixeldrain-web/conf"
|
|
||||||
"fornaxian.com/pixeldrain-web/log"
|
"fornaxian.com/pixeldrain-web/log"
|
||||||
"fornaxian.com/pixeldrain-web/webcontroller/templates"
|
"fornaxian.com/pixeldrain-web/webcontroller/templates"
|
||||||
"github.com/julienschmidt/httprouter"
|
"github.com/julienschmidt/httprouter"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ServeHistory is the controller for the upload history viewer
|
||||||
func ServeHistory(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
|
func ServeHistory(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
|
||||||
err := templates.Get().ExecuteTemplate(w, "history-cookies", map[string]interface{}{
|
err := templates.Get().ExecuteTemplate(w, "history-cookies", nil)
|
||||||
"APIURL": conf.ApiURL(),
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error executing template history: %s", err)
|
log.Error("Error executing template history: %s", err)
|
||||||
}
|
}
|
||||||
|
@@ -35,6 +35,6 @@ func (d *OGData) FromList(l pixelapi.List) *OGData {
|
|||||||
d.SiteName = "Pixeldrain"
|
d.SiteName = "Pixeldrain"
|
||||||
d.Description = "View " + l.Title + " on Pixeldrain"
|
d.Description = "View " + l.Title + " on Pixeldrain"
|
||||||
d.URL = "/l/" + l.ID
|
d.URL = "/l/" + l.ID
|
||||||
d.Image = "/api/list/" + l.ID + "/thumbnail"
|
d.Image = "/api/file/" + l.Files[0].ID + "/thumbnail"
|
||||||
return d
|
return d
|
||||||
}
|
}
|
||||||
|
@@ -10,6 +10,7 @@ import (
|
|||||||
var funcMap = template.FuncMap{
|
var funcMap = template.FuncMap{
|
||||||
"bgPatternCount": bgPatternCount,
|
"bgPatternCount": bgPatternCount,
|
||||||
"debugMode": debugMode,
|
"debugMode": debugMode,
|
||||||
|
"apiUrl": apiURL,
|
||||||
}
|
}
|
||||||
|
|
||||||
func bgPatternCount() uint8 {
|
func bgPatternCount() uint8 {
|
||||||
@@ -19,3 +20,7 @@ func bgPatternCount() uint8 {
|
|||||||
func debugMode() bool {
|
func debugMode() bool {
|
||||||
return conf.DebugMode()
|
return conf.DebugMode()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func apiURL() string {
|
||||||
|
return conf.ApiUrlExternal()
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user