all repos — fsrv @ 8945f5c8af583e39abfd7c5f1922ee005b01aa71

filehost server for x.icyphox.sh

Add -storepath flag
Anirudh Oppiliappan x@icyphox.sh
Sun, 06 Jun 2021 22:39:27 +0530
commit

8945f5c8af583e39abfd7c5f1922ee005b01aa71

parent

60a9765e785e277e7e697dcc73855da94aab74b7

1 files changed, 10 insertions(+), 7 deletions(-)

jump to
M main.gomain.go

@@ -13,10 +13,11 @@ "time"

) type settings struct { - url string - port string - namelen int - key string + url string + port string + namelen int + key string + storepath string } func randName(n int) string {

@@ -44,9 +45,10 @@ if err != nil {

log.Println(err) } - newFile := "uploads/" + randName(5) + ext - os.WriteFile(newFile, fileBytes, 0644) - log.Printf("wrote: %+v", newFile) + newFile := randName(5) + ext + diskFile := filepath.Join(s.storepath, newFile) + os.WriteFile(diskFile, fileBytes, 0644) + log.Printf("wrote: %+v", diskFile) fileUrl := s.url + "/" + newFile fmt.Fprintf(w, "%v", fileUrl)

@@ -55,6 +57,7 @@

func (s *settings) readSettings() { flag.StringVar(&s.url, "url", "localhost", "url for fsrv to serve files") flag.StringVar(&s.port, "port", "9393", "port to listen on") + flag.StringVar(&s.storepath, "storepath", "uploads", "path to store uploaded files") flag.IntVar(&s.namelen, "namelen", 5, "length of random filename") flag.StringVar(&s.key, "key", "secret", "secret key; generate this yourself") flag.Parse()