Fix filesystem error handler
This commit is contained in:
@@ -1,11 +1,13 @@
|
|||||||
package webcontroller
|
package webcontroller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"fornaxian.tech/log"
|
"fornaxian.tech/log"
|
||||||
|
"fornaxian.tech/pixeldrain_api_client/pixelapi"
|
||||||
"fornaxian.tech/util"
|
"fornaxian.tech/util"
|
||||||
"github.com/julienschmidt/httprouter"
|
"github.com/julienschmidt/httprouter"
|
||||||
)
|
)
|
||||||
@@ -25,16 +27,19 @@ func (wc *WebController) serveDirectory(w http.ResponseWriter, r *http.Request,
|
|||||||
|
|
||||||
node, err := td.PixelAPI.GetFilesystemPath(path)
|
node, err := td.PixelAPI.GetFilesystemPath(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err.Error() == "not_found" || err.Error() == "path_not_found" {
|
if apiErr, ok := errors.AsType[pixelapi.Error](err); ok {
|
||||||
|
switch apiErr.StatusCode {
|
||||||
|
case "not_found", "path_not_found":
|
||||||
wc.serveNotFound(w, r)
|
wc.serveNotFound(w, r)
|
||||||
} else if err.Error() == "forbidden" {
|
case "forbidden":
|
||||||
wc.serveForbidden(w, r)
|
wc.serveForbidden(w, r)
|
||||||
} else if err.Error() == "authentication_required" {
|
case "authentication_required":
|
||||||
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
||||||
} else if err.Error() == "unavailable_for_legal_reasons" {
|
case "unavailable_for_legal_reasons":
|
||||||
wc.serveUnavailableForLegalReasons(w, r)
|
wc.serveUnavailableForLegalReasons(w, r)
|
||||||
} else if err.Error() == "permission_denied" {
|
case "permission_denied":
|
||||||
wc.serveForbidden(w, r)
|
wc.serveForbidden(w, r)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Error("Failed to get path: %s", err)
|
log.Error("Failed to get path: %s", err)
|
||||||
wc.templates.Run(w, r, "500", td)
|
wc.templates.Run(w, r, "500", td)
|
||||||
|
|||||||
@@ -262,7 +262,7 @@ func (s styleSheet) String() string {
|
|||||||
s.BodyBackground.CSS(),
|
s.BodyBackground.CSS(),
|
||||||
s.BodyText.CSS(),
|
s.BodyText.CSS(),
|
||||||
s.Separator.CSS(),
|
s.Separator.CSS(),
|
||||||
s.BodyColor.WithAlpha(0.7).CSS(), // shaded_background
|
s.BodyColor.WithAlpha(0.9).CSS(), // shaded_background
|
||||||
s.CardColor.CSS(),
|
s.CardColor.CSS(),
|
||||||
s.Chart1.CSS(),
|
s.Chart1.CSS(),
|
||||||
s.Chart2.CSS(),
|
s.Chart2.CSS(),
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ type TemplateData struct {
|
|||||||
Title string
|
Title string
|
||||||
OGData ogData
|
OGData ogData
|
||||||
|
|
||||||
Other interface{}
|
Other any
|
||||||
URLQuery url.Values
|
URLQuery url.Values
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,15 +232,15 @@ func (tm *TemplateManager) pageNr(s string) (nr int) {
|
|||||||
}
|
}
|
||||||
return nr
|
return nr
|
||||||
}
|
}
|
||||||
func (tm *TemplateManager) add(a, b interface{}) float64 { return toFloat(a) + toFloat(b) }
|
func (tm *TemplateManager) add(a, b any) float64 { return toFloat(a) + toFloat(b) }
|
||||||
func (tm *TemplateManager) sub(a, b interface{}) float64 { return toFloat(a) - toFloat(b) }
|
func (tm *TemplateManager) sub(a, b any) float64 { return toFloat(a) - toFloat(b) }
|
||||||
func (tm *TemplateManager) mul(a, b interface{}) float64 { return toFloat(a) * toFloat(b) }
|
func (tm *TemplateManager) mul(a, b any) float64 { return toFloat(a) * toFloat(b) }
|
||||||
func (tm *TemplateManager) div(a, b interface{}) float64 { return toFloat(a) / toFloat(b) }
|
func (tm *TemplateManager) div(a, b any) float64 { return toFloat(a) / toFloat(b) }
|
||||||
|
|
||||||
func (tm *TemplateManager) formatData(i interface{}) string {
|
func (tm *TemplateManager) formatData(i any) string {
|
||||||
return util.FormatData(detectInt(i))
|
return util.FormatData(detectInt(i))
|
||||||
}
|
}
|
||||||
func (tm *TemplateManager) formatDataBits(i interface{}) string {
|
func (tm *TemplateManager) formatDataBits(i any) string {
|
||||||
var size = detectInt(i) * 8
|
var size = detectInt(i) * 8
|
||||||
var sizef = float64(size)
|
var sizef = float64(size)
|
||||||
|
|
||||||
@@ -302,7 +302,7 @@ func (tm *TemplateManager) noEscape(t string) template.HTML { return template.HT
|
|||||||
func (tm *TemplateManager) noEscapeJS(t string) template.JS { return template.JS(t) }
|
func (tm *TemplateManager) noEscapeJS(t string) template.JS { return template.JS(t) }
|
||||||
func (tm *TemplateManager) slashes() template.HTML { return template.HTML("//") }
|
func (tm *TemplateManager) slashes() template.HTML { return template.HTML("//") }
|
||||||
|
|
||||||
func detectInt(i interface{}) int {
|
func detectInt(i any) int {
|
||||||
switch v := i.(type) {
|
switch v := i.(type) {
|
||||||
case int:
|
case int:
|
||||||
return int(v)
|
return int(v)
|
||||||
@@ -332,7 +332,7 @@ func detectInt(i interface{}) int {
|
|||||||
panic(fmt.Sprintf("%v is not an int", i))
|
panic(fmt.Sprintf("%v is not an int", i))
|
||||||
}
|
}
|
||||||
|
|
||||||
func toFloat(i interface{}) float64 {
|
func toFloat(i any) float64 {
|
||||||
switch v := i.(type) {
|
switch v := i.(type) {
|
||||||
case int:
|
case int:
|
||||||
return float64(v)
|
return float64(v)
|
||||||
|
|||||||
Reference in New Issue
Block a user