// 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.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
}
