docstore/pkg/fs/helper.go
2019-08-20 23:57:43 +02:00

48 lines
807 B
Go

// Copyright (C) 2019 Marius Schellenberger
package fs
import (
"errors"
"git.giftfish.de/ston1th/docstore/pkg/core"
"path/filepath"
"strings"
)
const sep = "/"
func Clean(path string) string {
return filepath.FromSlash(filepath.Clean(sep + path))
}
func File(path string) string {
_, f := filepath.Split(Clean(path))
return f
}
var reserved = []string{
core.TotpURI,
core.LoginURI,
core.LogoutURI,
core.SearchURI,
core.TagsURI,
core.UserURI,
core.RawPrefix,
core.IndexPrefix,
core.UploadPrefix,
core.NewPrefix,
core.MovePrefix,
core.DeletePrefix,
core.Favicon,
core.BootstrapCSS,
core.CustomCSS,
}
func checkPath(path string) error {
for _, p := range reserved {
if strings.HasPrefix(path, p) {
return errors.New("base path '" + p + "' is reserved")
}
}
return nil
}