Progress
This commit is contained in:
parent
cbc66c5651
commit
2ab930d892
5 changed files with 72 additions and 1 deletions
12
internal/server/controllers/browse.go
Normal file
12
internal/server/controllers/browse.go
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
package controllers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.zervo.org/zervo/fileserver/internal/config"
|
||||||
|
"github.com/kataras/iris/v12"
|
||||||
|
)
|
||||||
|
|
||||||
|
// BrowseRoute registers all routes under '/b' (aka browse).
|
||||||
|
func BrowseRoute(app *iris.Application, cfg *config.Config) {
|
||||||
|
party := app.Party("/b")
|
||||||
|
party.Get("/{directory}/{path:path}")
|
||||||
|
}
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"github.com/kataras/iris/v12"
|
"github.com/kataras/iris/v12"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DirectoriesRoute registers all routes under /directories
|
// DirectoriesRoute registers all routes under '/directories'.
|
||||||
func DirectoriesRoute(app *iris.Application, cfg *config.Config) {
|
func DirectoriesRoute(app *iris.Application, cfg *config.Config) {
|
||||||
party := app.Party("/directories")
|
party := app.Party("/directories")
|
||||||
|
|
||||||
|
|
24
internal/server/views/browse.go
Normal file
24
internal/server/views/browse.go
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
package views
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"git.zervo.org/zervo/fileserver/internal/config"
|
||||||
|
"git.zervo.org/zervo/fileserver/internal/util/data"
|
||||||
|
"github.com/kataras/iris/v12"
|
||||||
|
)
|
||||||
|
|
||||||
|
type browsepage struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func BrowseView(ctx iris.Context, cfg *config.Config) {
|
||||||
|
ctx.CompressWriter(true)
|
||||||
|
ctx.ViewData("", data.LayoutData{
|
||||||
|
ServerName: cfg.ServerName,
|
||||||
|
ServerVersion: "0.0.1",
|
||||||
|
})
|
||||||
|
if err := ctx.View("browse.html"); err != nil {
|
||||||
|
errorView(ctx, fmt.Errorf("Failed to render BrowseView: %v", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
15
internal/util/fs.go
Normal file
15
internal/util/fs.go
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
package util
|
||||||
|
|
||||||
|
import "os"
|
||||||
|
|
||||||
|
// FileExists returns whether the given file or directory exists.
|
||||||
|
func FileExists(path string) (bool, error) {
|
||||||
|
_, err := os.Stat(path)
|
||||||
|
if err != nil {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
return false, err
|
||||||
|
}
|
20
internal/validation/directories.go
Normal file
20
internal/validation/directories.go
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
package validation
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"git.zervo.org/zervo/fileserver/internal/config"
|
||||||
|
"git.zervo.org/zervo/fileserver/internal/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ValidateDirectories ensure the given directories meet the required criteria to be served.
|
||||||
|
// Any directory that doesn't meet the requirements gets removed from the slice.
|
||||||
|
func ValidateDirectories(dirs []config.Directory) {
|
||||||
|
for i, dir := range dirs {
|
||||||
|
exists, err := util.FileExists(dir.Path)
|
||||||
|
if !exists {
|
||||||
|
fmt.Printf("WARNING: The directory '%s' does not exist and will be delisted. %v", dir.Id, err)
|
||||||
|
dirs[i] = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue