basic functions working

This commit is contained in:
ston1th 2019-05-02 14:17:24 +02:00
commit ffeeae5702
22 changed files with 420 additions and 129 deletions

View file

@ -216,18 +216,85 @@ func indexHandler(ctx *Context) {
}
}
func uploadHandler(ctx *Context) {
path := strings.TrimPrefix(ctx.Path(), core.UploadPrefix)
ctx.Data = webData{
Title: "Upload",
BodyTitle: "Upload",
}
ctx.Data.Path = path
ctx.Template("uploadHandler")
switch ctx.Method() {
case "GET":
ctx.Exec()
case "POST":
f, orig, err := ctx.File("file")
if err != nil {
ctx.Error(err)
return
}
newfile, err := ctx.Srv.FS.NewFile(f, path, orig, ctx.Form("name"))
if err != nil {
ctx.Error(err)
return
}
ctx.Redirect(newfile, http.StatusFound)
}
}
func newDirHandler(ctx *Context) {
path := strings.TrimPrefix(ctx.Path(), core.NewPrefix)
ctx.Data = webData{
Title: "Create Directory",
BodyTitle: "Create Directory",
}
ctx.Data.Path = path
ctx.Template("newDirHandler")
switch ctx.Method() {
case "GET":
ctx.Exec()
case "POST":
err := ctx.Srv.FS.Mkdir(path, ctx.Form("name"))
if err != nil {
ctx.Error(err)
return
}
ctx.Redirect(path, http.StatusFound)
}
}
func moveHandler(ctx *Context) {
path := strings.TrimPrefix(ctx.Path(), core.MovePrefix)
ctx.Data = webData{
Title: "Move File",
BodyTitle: "Move File",
mode, err := ctx.Srv.FS.Mode(path)
if err != nil {
ctx.Error(err)
return
}
switch mode {
case fs.IsFile:
ctx.Data = webData{
Title: "Move File",
BodyTitle: "Move File",
}
case fs.IsDir:
ctx.Data = webData{
Title: "Move Directory",
BodyTitle: "Move Directory",
}
default:
ctx.Data = webData{
Title: "Move",
BodyTitle: "Move",
}
ctx.Error(noSuchFile)
return
}
ctx.Data.Path = path
ctx.Data.Paths = ctx.Srv.FS.Recursive(path)
_, ctx.Data.Data = filepath.Split(path)
ctx.Template("moveHandler")
switch ctx.Method() {
case "GET":
ctx.Data.Path = path
ctx.Data.Paths = ctx.Srv.FS.Recursive()
_, ctx.Data.Data = filepath.Split(path)
ctx.Exec()
case "POST":
name := ctx.Form("name")
@ -320,6 +387,7 @@ func dirHandler(ctx *Context) {
}
dir := ctx.Srv.FS.ReadDir(path)
ctx.Srv.DB.GetIndexed(dir.Files)
ctx.Data.Path = path
ctx.Data.Data = dir
ctx.Data.Paths = fs.Paths(path)
ctx.Exec()
@ -328,11 +396,14 @@ func dirHandler(ctx *Context) {
Title: "Document Viewer",
}
ctx.Template("fileHandler")
ctx.Data.Data = core.RawPrefix + path
ctx.Data.Data = core.Path{
Name: path,
Abs: core.RawPrefix + path,
Flag: ctx.Srv.DB.IsIndexed(path),
}
ctx.Data.Paths = fs.Paths(path)
ctx.Exec()
}
case "POST":
}
}