- Timestamp:
- Oct 13, 2021, 2:57:27 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/go.mod
r1 r11 2 2 3 3 go 1.17 4 5 require github.com/dustin/go-humanize v1.0.0 // indirect -
trunk/partage.go
r10 r11 9 9 "path" 10 10 "path/filepath" 11 "html/template" 12 13 "github.com/dustin/go-humanize" 11 14 ) 15 16 type templatedata struct { 17 Maxsize string 18 } 12 19 13 20 var conf struct { 14 21 bind string 22 baseuri string 15 23 filepath string 16 24 rootdir string 17 baseuristring25 templatedir string 18 26 filectx string 19 27 maxsize int64 20 28 } 29 21 30 22 31 func contenttype(f *os.File) string { … … 93 102 } 94 103 104 func servetemplate(w http.ResponseWriter, f string, d templatedata) { 105 t, err := template.ParseFiles(conf.templatedir + "/" + f) 106 if err != nil { 107 w.WriteHeader(http.StatusInternalServerError) 108 return 109 } 110 111 err = t.Execute(w, d) 112 if err != nil { 113 fmt.Println(err) 114 } 115 } 116 95 117 func uploaderPut(w http.ResponseWriter, r *http.Request) { 96 118 // Max 15 Gb uploads … … 120 142 // r.URL.Path is sanitized regarding "." and ".." 121 143 filename := r.URL.Path 122 if r.URL.Path == "/" { 123 filename = "/index.html" 144 if r.URL.Path == "/" || r.URL.Path == "/index" { 145 data := templatedata{ Maxsize: humanize.IBytes(uint64(conf.maxsize))} 146 servetemplate(w, "/index.html", data) 147 return 124 148 } 125 149 … … 146 170 func main() { 147 171 conf.bind = "0.0.0.0:8080" 148 conf.maxsize = 28 * 1024 * 1024172 conf.maxsize = 30064771072 // 28Gib 149 173 conf.filepath = "/tmp" 150 174 conf.rootdir = "./static" 151 175 conf.baseuri = "http://192.168.0.3:8080" 152 176 conf.filectx = "/f/" 177 conf.templatedir = "./templates" 153 178 154 179 http.HandleFunc("/", uploader)
Note:
See TracChangeset
for help on using the changeset viewer.