ready for v1.0rc1
This commit is contained in:
parent
84d48a6eea
commit
ce5764840f
15 changed files with 140 additions and 49 deletions
|
|
@ -66,7 +66,7 @@ type webData struct {
|
|||
|
||||
Login bool
|
||||
|
||||
Key string
|
||||
NotFound string
|
||||
|
||||
User string
|
||||
Token string
|
||||
|
|
|
|||
|
|
@ -280,7 +280,7 @@ func newDirHandler(ctx *Context) {
|
|||
|
||||
func moveHandler(ctx *Context) {
|
||||
path := strings.TrimPrefix(ctx.Path(), core.MovePrefix)
|
||||
mode, err := ctx.Srv.FS.Mode(path)
|
||||
mode, _, err := ctx.Srv.FS.Mode(path)
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
return
|
||||
|
|
@ -323,11 +323,12 @@ func moveHandler(ctx *Context) {
|
|||
return
|
||||
}
|
||||
for _, m := range moved {
|
||||
log.Debugf("move: %s to %s", m.Old, m.New)
|
||||
err = ctx.Srv.DB.MoveFile(m.Old, m.New)
|
||||
if err != nil {
|
||||
log.Printf("move: %s: %s", m, err)
|
||||
continue
|
||||
}
|
||||
log.Debugf("move: %s to %s", m.Old, m.New)
|
||||
}
|
||||
ctx.Redirect(newfile, http.StatusFound)
|
||||
}
|
||||
|
|
@ -335,8 +336,8 @@ func moveHandler(ctx *Context) {
|
|||
|
||||
func deleteHandler(ctx *Context) {
|
||||
path := strings.TrimPrefix(ctx.Path(), core.DeletePrefix)
|
||||
mode, err := ctx.Srv.FS.Mode(path)
|
||||
if err != nil {
|
||||
mode, enoent, err := ctx.Srv.FS.Mode(path)
|
||||
if !enoent && err != nil {
|
||||
ctx.Error(err)
|
||||
return
|
||||
}
|
||||
|
|
@ -352,12 +353,14 @@ func deleteHandler(ctx *Context) {
|
|||
BodyTitle: "Delete Directory",
|
||||
}
|
||||
default:
|
||||
ctx.Data = webData{
|
||||
Title: "Delete",
|
||||
BodyTitle: "Delete",
|
||||
if ctx.Method() == "GET" {
|
||||
ctx.Data = webData{
|
||||
Title: "Delete",
|
||||
BodyTitle: "Delete",
|
||||
}
|
||||
ctx.Error(noSuchFile)
|
||||
return
|
||||
}
|
||||
ctx.Error(noSuchFile)
|
||||
return
|
||||
}
|
||||
ctx.Data.Path = path
|
||||
ctx.Data.Data = mode
|
||||
|
|
@ -369,6 +372,27 @@ func deleteHandler(ctx *Context) {
|
|||
if !ctx.CheckXsrf() {
|
||||
return
|
||||
}
|
||||
p, _ := filepath.Split(path)
|
||||
p = filepath.Dir(p)
|
||||
clean := ctx.Form("clean")
|
||||
if clean == "true" {
|
||||
f := fs.Clean(path)
|
||||
id, err := ctx.Srv.DB.DeleteFile(f)
|
||||
if err != nil {
|
||||
log.Printf("db: delete: %s %s", f, err)
|
||||
}
|
||||
if id == "" {
|
||||
ctx.Redirect(p, http.StatusFound)
|
||||
return
|
||||
}
|
||||
log.Debugf("delete %s id: %s from index", f, id)
|
||||
err = ctx.Srv.DB.Index.Delete(id)
|
||||
if err != nil {
|
||||
log.Printf("index: delete: %s %s", f, err)
|
||||
}
|
||||
ctx.Redirect(p, http.StatusFound)
|
||||
return
|
||||
}
|
||||
files, err := ctx.Srv.FS.Delete(path)
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
|
|
@ -379,17 +403,15 @@ func deleteHandler(ctx *Context) {
|
|||
if err != nil {
|
||||
log.Printf("db: delete: %s %s", f, err)
|
||||
}
|
||||
log.Debugf("delete %s id: %s from index", f, id)
|
||||
if id == "" {
|
||||
continue
|
||||
}
|
||||
log.Debugf("delete %s id: %s from index", f, id)
|
||||
err = ctx.Srv.DB.Index.Delete(id)
|
||||
if err != nil {
|
||||
log.Printf("index: delete: %s %s", f, err)
|
||||
}
|
||||
}
|
||||
p, _ := filepath.Split(path)
|
||||
p = filepath.Dir(p)
|
||||
ctx.Redirect(p, http.StatusFound)
|
||||
}
|
||||
}
|
||||
|
|
@ -399,8 +421,8 @@ func dirHandler(ctx *Context) {
|
|||
path := ctx.Path()
|
||||
switch ctx.Method() {
|
||||
case "GET":
|
||||
mode, err := ctx.Srv.FS.Mode(path)
|
||||
if err != nil {
|
||||
mode, enoent, err := ctx.Srv.FS.Mode(path)
|
||||
if !enoent && err != nil {
|
||||
ctx.Error(err)
|
||||
return
|
||||
}
|
||||
|
|
@ -429,10 +451,17 @@ func dirHandler(ctx *Context) {
|
|||
ctx.Data.Paths = fs.Paths(path)
|
||||
ctx.Exec()
|
||||
default:
|
||||
ctx.Data = webData{
|
||||
Title: "Viewer",
|
||||
p := fs.Clean(path)
|
||||
if enoent && ctx.Srv.DB.IsIndexed(p) {
|
||||
ctx.Template("enoentHandler")
|
||||
ctx.Data = webData{
|
||||
Title: "Stalled File",
|
||||
}
|
||||
ctx.Data.Path = p
|
||||
ctx.Exec()
|
||||
return
|
||||
}
|
||||
ctx.Error(noSuchFile)
|
||||
ctx.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,6 +96,18 @@ const (
|
|||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{{end}}`
|
||||
enoent = `{{define "body"}}
|
||||
<div class="alert alert-danger msg">
|
||||
<h4>File missing!</h4>
|
||||
<p>This file is indexed but has been removed from the file system.</p>
|
||||
<p>Do you want to delete this entry from the index?</p>
|
||||
</div>
|
||||
<form class="form-horizontal" action="/delete{{.Path}}" method="post">
|
||||
<input type="hidden" name="token" value="{{.Token}}">
|
||||
<input type="hidden" name="clean" value="true">
|
||||
<button class="btn btn-sm btn-danger" type="submit">Delete</button>
|
||||
</form>
|
||||
{{end}}`
|
||||
file = `{{define "body"}}
|
||||
<div class="row">
|
||||
|
|
@ -427,7 +439,7 @@ const (
|
|||
<input type="hidden" name="token" value="{{.Token}}">
|
||||
<div class="form-group">
|
||||
<label class="col-form-label" for="name">Name</label>
|
||||
<input class="form-control input-sm" type="text" id="name" name="name" autocomplete="off" value="{{.Data}}">
|
||||
<input class="form-control input-sm" type="text" id="name" name="name" autocomplete="off" value="{{.Data}}" placeholder="optional">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="input-group mb-3">
|
||||
|
|
@ -721,6 +733,7 @@ func (s *HTTPServer) loadTemplates() {
|
|||
s.templ["uploadHandler"] = parse(index, menu, upload)
|
||||
s.templ["newDirHandler"] = parse(index, menu, newDir)
|
||||
s.templ["moveHandler"] = parse(index, menu, move)
|
||||
s.templ["enoentHandler"] = parse(index, menu, enoent)
|
||||
s.templ["deleteHandler"] = parse(index, menu, delete)
|
||||
s.templ["notFoundHandler"] = parse(index, menu, notFound)
|
||||
s.templ["forbiddenHandler"] = parse(index, menu, forbidden)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue