Merge branch 'master' into easy-forms
This commit is contained in:
@@ -187,11 +187,10 @@ seamless="seamless" frameborder="0" allowtransparency="true"
|
||||
|
||||
func (f filePreview) def() string {
|
||||
return fmt.Sprintf(
|
||||
`%s<br/>%s<br/><a href="%s"><img src="%s" class="image"></a>`,
|
||||
`<br/><br/><img src="%s" class="image"><br/><br/>%s<br/>Type: '%s'`,
|
||||
f.APIURL+f.FileInfo.ThumbnailHREF,
|
||||
f.FileInfo.Name,
|
||||
f.FileInfo.MimeType,
|
||||
f.DownloadURL,
|
||||
f.APIURL+f.FileInfo.ThumbnailHREF,
|
||||
)
|
||||
}
|
||||
|
||||
|
@@ -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.captchaKey(),
|
||||
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.captchaKey(),
|
||||
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",
|
||||
|
@@ -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,
|
||||
|
@@ -44,14 +44,20 @@ func (wc *WebController) newTemplateData(w http.ResponseWriter, r *http.Request)
|
||||
t.PixelAPI = pixelapi.New(wc.conf.APIURLInternal, key)
|
||||
uinf, err := t.PixelAPI.UserInfo()
|
||||
if err != nil {
|
||||
// This session key doesn't work, delete it
|
||||
// This session key doesn't work, or the backend is down, user
|
||||
// cannot be authenticated
|
||||
log.Debug("Session check for key '%s' failed: %s", key, err)
|
||||
http.SetCookie(w, &http.Cookie{
|
||||
Name: "pd_auth_key",
|
||||
Value: "",
|
||||
Path: "/",
|
||||
Expires: time.Unix(0, 0),
|
||||
})
|
||||
|
||||
if err.Error() == "authentication_required" || err.Error() == "authentication_failed" {
|
||||
// This key is invalid, delete it
|
||||
log.Debug("Deleting invalid API key")
|
||||
http.SetCookie(w, &http.Cookie{
|
||||
Name: "pd_auth_key",
|
||||
Value: "",
|
||||
Path: "/",
|
||||
Expires: time.Unix(0, 0),
|
||||
})
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
|
@@ -16,23 +16,7 @@ func (wc *WebController) serveRegister(
|
||||
p httprouter.Params,
|
||||
) {
|
||||
var tpld = wc.newTemplateData(w, r)
|
||||
|
||||
// This only runs on the first request
|
||||
if wc.captchaSiteKey == "" {
|
||||
capt, err := tpld.PixelAPI.GetRecaptcha()
|
||||
if err != nil {
|
||||
log.Error("Error getting recaptcha key: %s", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if capt.SiteKey == "" {
|
||||
wc.captchaSiteKey = "none"
|
||||
} else {
|
||||
wc.captchaSiteKey = capt.SiteKey
|
||||
}
|
||||
}
|
||||
|
||||
tpld.Other = wc.captchaSiteKey
|
||||
tpld.Other = wc.captchaKey()
|
||||
|
||||
err := wc.templates.Get().ExecuteTemplate(w, "register", tpld)
|
||||
if err != nil {
|
||||
|
@@ -15,15 +15,14 @@ func userStyle(r *http.Request) (style template.CSS) {
|
||||
switch cookie.Value {
|
||||
case "solarized_dark":
|
||||
selectedStyle = solarizedDarkStyle
|
||||
break
|
||||
case "maroon":
|
||||
selectedStyle = maroonStyle
|
||||
break
|
||||
case "hacker":
|
||||
selectedStyle = hackerStyle
|
||||
case "default":
|
||||
fallthrough // use default case
|
||||
default:
|
||||
selectedStyle = defaultPixeldrainStyle
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,3 +204,24 @@ var maroonStyle = pixeldrainStyleSheet{
|
||||
ShadowSpread: 50,
|
||||
ShadowIntensity: 5,
|
||||
}
|
||||
|
||||
var hackerStyle = pixeldrainStyleSheet{
|
||||
TextColor: hsl{0, 0, 1},
|
||||
InputColor: hsl{0, 0, .25},
|
||||
InputTextColor: hsl{0, 0, 1},
|
||||
HighlightColor: hsl{120, 1, .6},
|
||||
HighlightTextColor: hsl{0, 0, 0},
|
||||
DangerColor: hsl{0, .65, .31},
|
||||
DangerColorDark: hsl{0, .64, .23},
|
||||
FileBackgroundColor: hsl{120, .8, .06},
|
||||
|
||||
BackgroundColor: hsl{0, 0, 0},
|
||||
BodyColor: hsl{0, 0, 0},
|
||||
AccentColorDark: hsl{0, 0, .05},
|
||||
AccentColorMedium: hsl{0, 0, .10},
|
||||
AccentColorLight: hsl{0, 0, .15},
|
||||
|
||||
ShadowColor: hsl{120, 1, .1},
|
||||
ShadowSpread: 50,
|
||||
ShadowIntensity: 5,
|
||||
}
|
||||
|
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/google/uuid"
|
||||
|
||||
"fornaxian.com/pixeldrain-web/init/conf"
|
||||
"fornaxian.com/pixeldrain-web/pixelapi"
|
||||
"fornaxian.com/pixeldrain-web/webcontroller/forms"
|
||||
"github.com/Fornaxian/log"
|
||||
"github.com/julienschmidt/httprouter"
|
||||
@@ -176,3 +177,22 @@ func (wc *WebController) getAPIKey(r *http.Request) (key string, err error) {
|
||||
}
|
||||
return "", errors.New("not a valid pixeldrain authentication cookie")
|
||||
}
|
||||
|
||||
func (wc *WebController) captchaKey() string {
|
||||
// This only runs on the first request
|
||||
if wc.captchaSiteKey == "" {
|
||||
var api = pixelapi.New(wc.conf.APIURLInternal, "")
|
||||
capt, err := api.GetRecaptcha()
|
||||
if err != nil {
|
||||
log.Error("Error getting recaptcha key: %s", err)
|
||||
return ""
|
||||
}
|
||||
if capt.SiteKey == "" {
|
||||
wc.captchaSiteKey = "none"
|
||||
} else {
|
||||
wc.captchaSiteKey = capt.SiteKey
|
||||
}
|
||||
}
|
||||
|
||||
return wc.captchaSiteKey
|
||||
}
|
||||
|
Reference in New Issue
Block a user