Update brave ad
This commit is contained in:
@@ -44,6 +44,7 @@ func adType() (i int) {
|
||||
adMaven = 5
|
||||
mediaNet = 6
|
||||
revenueHits = 7
|
||||
brave = 8
|
||||
)
|
||||
|
||||
switch i {
|
||||
@@ -53,11 +54,8 @@ func adType() (i int) {
|
||||
case 2:
|
||||
return adMaven
|
||||
|
||||
case 3:
|
||||
return mediaNet
|
||||
|
||||
case 4:
|
||||
return revenueHits
|
||||
case 3, 4:
|
||||
return brave
|
||||
|
||||
default:
|
||||
panic(fmt.Errorf(
|
||||
|
116
webcontroller/filesystem.go
Normal file
116
webcontroller/filesystem.go
Normal file
@@ -0,0 +1,116 @@
|
||||
package webcontroller
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"fornaxian.tech/pixeldrain_server/api/restapi/apitype"
|
||||
"github.com/Fornaxian/log"
|
||||
"github.com/julienschmidt/httprouter"
|
||||
)
|
||||
|
||||
type filesystemPath struct {
|
||||
Path []filesystemNode
|
||||
Children []filesystemNode
|
||||
}
|
||||
|
||||
type filesystemNode struct {
|
||||
HREF string
|
||||
Icon string
|
||||
Name string
|
||||
Type string
|
||||
FileSize int64
|
||||
FileType string
|
||||
}
|
||||
|
||||
func convFilesystemNode(bucketID string, v apitype.FilesystemNode) (node filesystemNode) {
|
||||
node = filesystemNode{
|
||||
HREF: "/fs/" + bucketID + v.Path,
|
||||
Type: v.Type,
|
||||
Name: v.Name,
|
||||
FileSize: v.FileSize,
|
||||
FileType: v.FileType,
|
||||
}
|
||||
if node.Type == "dir" {
|
||||
node.Icon = "/res/img/mime/folder.png"
|
||||
} else {
|
||||
node.Icon = "/res/img/mime/empty.png"
|
||||
}
|
||||
|
||||
return node
|
||||
}
|
||||
|
||||
func (wc *WebController) serveFilesystem(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
|
||||
var err error
|
||||
var td = wc.newTemplateData(w, r)
|
||||
var path = strings.TrimPrefix(p.ByName("path"), "/")
|
||||
var fsPath filesystemPath
|
||||
|
||||
if path == "" {
|
||||
buckets, err := td.PixelAPI.GetFilesystemBuckets()
|
||||
if err != nil {
|
||||
if err.Error() == "not_found" {
|
||||
wc.templates.Get().ExecuteTemplate(w, "404", td)
|
||||
} else if err.Error() == "authentication_required" {
|
||||
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
||||
} else {
|
||||
log.Error("Failed to get buckets: %s", err)
|
||||
wc.templates.Get().ExecuteTemplate(w, "500", td)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
for _, v := range buckets.Buckets {
|
||||
fsPath.Children = append(fsPath.Children, filesystemNode{
|
||||
HREF: "/fs/" + v.ID,
|
||||
Icon: "/res/img/mime/folder-remote.png",
|
||||
Type: "dir",
|
||||
Name: v.Name,
|
||||
FileSize: 0,
|
||||
FileType: "inode/directory",
|
||||
})
|
||||
}
|
||||
} else {
|
||||
log.Info("getting path %s", path)
|
||||
node, err := td.PixelAPI.GetFilesystemPath(path)
|
||||
if err != nil {
|
||||
if err.Error() == "not_found" || err.Error() == "path_not_found" {
|
||||
wc.templates.Get().ExecuteTemplate(w, "404", td)
|
||||
} else {
|
||||
log.Error("Failed to get path: %s", err)
|
||||
wc.templates.Get().ExecuteTemplate(w, "500", td)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if node.Path[node.NodeIndex].Type == "file" {
|
||||
http.Redirect(w, r, "/api/filesystem/"+path, http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
|
||||
for _, v := range node.Path {
|
||||
fsPath.Path = append(fsPath.Path, convFilesystemNode(node.Bucket.ID, v))
|
||||
}
|
||||
for _, v := range node.Children {
|
||||
fsPath.Children = append(fsPath.Children, convFilesystemNode(node.Bucket.ID, v))
|
||||
}
|
||||
}
|
||||
|
||||
sort.Slice(fsPath.Children, func(i, j int) (less bool) {
|
||||
// Directories always come first. Make sure we're comparing apples with
|
||||
// apples
|
||||
if fsPath.Children[i].Type != fsPath.Children[j].Type {
|
||||
return fsPath.Children[i].Type == "dir"
|
||||
}
|
||||
|
||||
return fsPath.Children[i].Name < fsPath.Children[j].Name
|
||||
})
|
||||
|
||||
td.Title = "Filesystem"
|
||||
td.Other = fsPath
|
||||
err = wc.templates.Get().ExecuteTemplate(w, "filesystem", td)
|
||||
if err != nil && !strings.Contains(err.Error(), "broken pipe") {
|
||||
log.Error("Error executing template filesystem: %s", err)
|
||||
}
|
||||
}
|
@@ -116,6 +116,7 @@ func New(
|
||||
{GET, "about" /* */, wc.serveMarkdown("about.md", false)},
|
||||
{GET, "appearance" /* */, wc.serveTemplate("appearance", false)},
|
||||
{GET, "hosting" /* */, wc.serveMarkdown("hosting.md", false)},
|
||||
{GET, "brave" /* */, wc.serveMarkdown("brave.md", false)},
|
||||
|
||||
// User account pages
|
||||
{GET, "register" /* */, wc.serveForm(wc.registerForm, false)},
|
||||
@@ -138,6 +139,9 @@ func New(
|
||||
{GET, "user/password_reset_confirm" /**/, wc.serveForm(wc.passwordResetConfirmForm, false)},
|
||||
{PST, "user/password_reset_confirm" /**/, wc.serveForm(wc.passwordResetConfirmForm, false)},
|
||||
|
||||
// Filesystem
|
||||
{GET, "fs/*path", wc.serveFilesystem},
|
||||
|
||||
{GET, "patreon_activate" /* */, wc.serveForm(wc.patreonLinkForm, true)},
|
||||
{PST, "patreon_activate" /* */, wc.serveForm(wc.patreonLinkForm, true)},
|
||||
|
||||
|
Reference in New Issue
Block a user