Tweaks
This commit is contained in:
@@ -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")
|
||||
|
@@ -19,12 +19,12 @@ type FileInfo struct {
|
||||
MimeType string `json:"mime_type"`
|
||||
Description string `json:"description"`
|
||||
MimeImage string `json:"mime_image"`
|
||||
Thumbnail string `json:"thumbnail"`
|
||||
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)
|
||||
|
@@ -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)
|
||||
|
@@ -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 = "<div class=\"uploadItem\" >"
|
||||
+ "<a href=\"/u/" + json.id + "\" target=\"_blank\">"
|
||||
+ "<img src=\"" + json.thumbnail + "\" "
|
||||
+ "<img src=\"" + APIURL + json.thumbnail_href + "\" "
|
||||
+ "alt=\"" + json.file_name + "\" "
|
||||
+ "class=\"uploadItemImage\" />"
|
||||
+ json.file_name
|
||||
|
@@ -49,7 +49,7 @@
|
||||
|
||||
<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();">
|
||||
<img src="/res/img/floppy_small.png" alt="Download this file"/>
|
||||
|
@@ -21,6 +21,7 @@
|
||||
<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"/>
|
||||
<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
|
||||
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 {
|
||||
f.FileInfo = inf
|
||||
f.FileURL = conf.ApiURL() + "/file/" + f.FileInfo.ID
|
||||
f.DownloadURL = conf.ApiURL() + "/file/" + f.FileInfo.ID + "/download"
|
||||
f.FileURL = conf.ApiUrlExternal() + "/file/" + f.FileInfo.ID
|
||||
f.DownloadURL = conf.ApiUrlExternal() + "/file/" + f.FileInfo.ID + "/download"
|
||||
|
||||
if strings.HasPrefix(f.FileInfo.MimeType, "image") {
|
||||
return f.image()
|
||||
@@ -135,6 +135,6 @@ func (f FilePreview) def() string {
|
||||
f.FileInfo.FileName,
|
||||
f.FileInfo.MimeType,
|
||||
f.DownloadURL,
|
||||
f.FileInfo.Thumbnail,
|
||||
conf.ApiUrlExternal()+f.FileInfo.ThumbnailHREF,
|
||||
)
|
||||
}
|
||||
|
@@ -3,16 +3,14 @@ package webcontroller
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"fornaxian.com/pixeldrain-web/conf"
|
||||
"fornaxian.com/pixeldrain-web/log"
|
||||
"fornaxian.com/pixeldrain-web/webcontroller/templates"
|
||||
"github.com/julienschmidt/httprouter"
|
||||
)
|
||||
|
||||
// ServeHistory is the controller for the upload history viewer
|
||||
func ServeHistory(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
|
||||
err := templates.Get().ExecuteTemplate(w, "history-cookies", map[string]interface{}{
|
||||
"APIURL": conf.ApiURL(),
|
||||
})
|
||||
err := templates.Get().ExecuteTemplate(w, "history-cookies", nil)
|
||||
if err != nil {
|
||||
log.Error("Error executing template history: %s", err)
|
||||
}
|
||||
|
@@ -35,6 +35,6 @@ func (d *OGData) FromList(l pixelapi.List) *OGData {
|
||||
d.SiteName = "Pixeldrain"
|
||||
d.Description = "View " + l.Title + " on Pixeldrain"
|
||||
d.URL = "/l/" + l.ID
|
||||
d.Image = "/api/list/" + l.ID + "/thumbnail"
|
||||
d.Image = "/api/file/" + l.Files[0].ID + "/thumbnail"
|
||||
return d
|
||||
}
|
||||
|
@@ -10,6 +10,7 @@ import (
|
||||
var funcMap = template.FuncMap{
|
||||
"bgPatternCount": bgPatternCount,
|
||||
"debugMode": debugMode,
|
||||
"apiUrl": apiURL,
|
||||
}
|
||||
|
||||
func bgPatternCount() uint8 {
|
||||
@@ -19,3 +20,7 @@ func bgPatternCount() uint8 {
|
||||
func debugMode() bool {
|
||||
return conf.DebugMode()
|
||||
}
|
||||
|
||||
func apiURL() string {
|
||||
return conf.ApiUrlExternal()
|
||||
}
|
||||
|
Reference in New Issue
Block a user