aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Hurst <ark@mansus.space>2023-08-10 17:02:00 +0200
committerJulian Hurst <ark@mansus.space>2023-08-10 17:02:00 +0200
commit1d47646d99e7da71d04c49b0d16bfb21ecf78308 (patch)
tree0d5f3950ded04ad6ff83335050481bbbb519ffa8
parente0444c96749d016b003443087481c67592a4893d (diff)
downloaddocspace-1d47646d99e7da71d04c49b0d16bfb21ecf78308.tar.gz
Support a custom docs folder path (-f option)
-rw-r--r--imgs.go6
-rw-r--r--main.go7
2 files changed, 8 insertions, 5 deletions
diff --git a/imgs.go b/imgs.go
index 4e614e9..fcccc7d 100644
--- a/imgs.go
+++ b/imgs.go
@@ -58,7 +58,7 @@ func imgs(w http.ResponseWriter, r *http.Request) {
//})
start := page * pageSize
//imgs := extractImgs(files, start)
- imgs, err := extractImgsGlob(userDocPath)
+ imgs, err := extractImgsGlob(userDocPath, username)
if err != nil {
sendError(w, r, err.Error(), http.StatusInternalServerError)
return
@@ -105,7 +105,7 @@ func imgs(w http.ResponseWriter, r *http.Request) {
unauthorized(w, r)
}
-func extractImgsGlob(userDocPath string) ([]Doc, error) {
+func extractImgsGlob(userDocPath string, username string) ([]Doc, error) {
var typs []string = []string {
"image/jpeg",
"image/png",
@@ -142,7 +142,7 @@ func extractImgsGlob(userDocPath string) ([]Doc, error) {
info.Name(),
humanize(info.Size()),
info.ModTime(),
- path.Join(userDocPath, info.Name()),
+ path.Join("/docs/", username, info.Name()),
})
}
}
diff --git a/main.go b/main.go
index 91d6fb7..f2aed1f 100644
--- a/main.go
+++ b/main.go
@@ -28,7 +28,7 @@ var nonce []byte = nil
var db *sql.DB
-const baseDocDir string = "docs"
+var baseDocDir string = "docs"
const NOTFOUND string = "Not found"
const UNAUTH string = "Unauthorized"
@@ -273,7 +273,7 @@ func index(w http.ResponseWriter, r *http.Request) {
file.Name(),
humanize(info.Size()),
info.ModTime(),
- path.Join(baseDocDir, username, file.Name()),
+ path.Join("/docs/", username, file.Name()),
})
}
flasherr := consumeFlash(w, r, "error")
@@ -635,6 +635,7 @@ func upload(w http.ResponseWriter, r *http.Request) {
func main() {
p := flag.Int("p", 8080, "the port to bind to")
dbPath := flag.String("d", "./db/test.db", "the db to connect to")
+ docPath := flag.String("f", "docs", "the path of the docs folder")
flag.Parse()
var err error
log.Printf("Connecting to db: %s\n", *dbPath)
@@ -644,6 +645,8 @@ func main() {
}
defer db.Close()
+ baseDocDir = *docPath
+ log.Printf("baseDocDir: %s\n", baseDocDir)
http.HandleFunc("/docs/", handleFileServer(baseDocDir, "/docs/"))
//http.Handle("/docs/", http.StripPrefix("/docs/", http.FileServer(http.Dir("docs"))))
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))