diff options
| -rw-r--r-- | imgs.go | 6 | ||||
| -rw-r--r-- | main.go | 7 |
2 files changed, 8 insertions, 5 deletions
@@ -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()), }) } } @@ -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")))) |
