commit 6890cca621d442b16c78d92db77bf35a252da222
parent da5ad8fd29f0bd99cfceb6439913d307e2b49c8a
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Mon, 30 Jan 2023 20:53:12 -0800
fast uploader
Diffstat:
3 files changed, 38 insertions(+), 4 deletions(-)
diff --git a/cmd/dkfupload/main.go b/cmd/dkfupload/main.go
@@ -36,6 +36,7 @@ func main() {
var local bool
var maxChunkSize int64
flag.StringVar(&filedropUUID, "filedrop-uuid", "", "dkf filedrop uuid")
+ flag.StringVar(&filedropUUID, "u", "", "dkf filedrop uuid")
flag.StringVar(&fileName, "file", "", "file to upload")
flag.StringVar(&fileName, "f", "", "file to upload")
flag.IntVar(&nbThreads, "threads", 20, "nb threads")
@@ -85,9 +86,13 @@ func main() {
hasToSucceed(func() error {
username := fmt.Sprintf("user_%d", i)
password := GenerateTokenN(8)
- client, err = GetHttpClient(&proxy.Auth{User: username, Password: password})
- if err != nil {
- return err
+ if local {
+ client = http.DefaultClient
+ } else {
+ client, err = GetHttpClient(&proxy.Auth{User: username, Password: password})
+ if err != nil {
+ return err
+ }
}
return nil
})
@@ -114,8 +119,9 @@ func main() {
return err
}
- req, _ := http.NewRequest(http.MethodPost, baseUrl+"/file-drop/"+filedropUUID, body)
+ req, _ := http.NewRequest(http.MethodPost, baseUrl+"/file-drop/"+filedropUUID+"/tmp", body)
req.Header.Set("User-Agent", userAgent)
+ req.Header.Set("Content-Type", w.FormDataContentType())
resp, err := client.Do(req)
if err != nil {
return err
diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go
@@ -4305,6 +4305,32 @@ func FileDropHandler(c echo.Context) error {
return c.Render(http.StatusOK, filedropTmplName, data)
}
+func FileDropTmpInitHandler(c echo.Context) error {
+ return c.NoContent(http.StatusOK)
+}
+
+func FileDropTmpHandler(c echo.Context) error {
+ filedropUUID := c.Param("uuid")
+ file, handler, err := c.Request().FormFile("file")
+ if err != nil {
+ logrus.Error(err)
+ return c.NoContent(http.StatusInternalServerError)
+ }
+ defer file.Close()
+ fileName := handler.Filename
+ by, _ := io.ReadAll(file)
+ if err := os.MkdirAll(filepath.Join(config.Global.ProjectFiledropPath(), filedropUUID), 0755); err != nil {
+ logrus.Error(err)
+ return c.NoContent(http.StatusInternalServerError)
+ }
+ p := filepath.Join(config.Global.ProjectFiledropPath(), filedropUUID, fileName)
+ if err := os.WriteFile(p, by, 0644); err != nil {
+ logrus.Error(err)
+ return c.NoContent(http.StatusInternalServerError)
+ }
+ return c.NoContent(http.StatusOK)
+}
+
func Stego1ChallengeHandler(c echo.Context) error {
const flagHash = "05b456689a9f8de69416d21cbb97157588b8491d07551167a95b93a1c7d61e7b"
authUser := c.Get("authUser").(*database.User)
diff --git a/pkg/web/web.go b/pkg/web/web.go
@@ -300,6 +300,8 @@ func getBaseServer() *echo.Echo {
e.Use(middlewares.I18nMiddleware(i18nBundle, "en"))
e.GET("/file-drop/:uuid", handlers.FileDropHandler)
e.POST("/file-drop/:uuid", handlers.FileDropHandler)
+ e.POST("/file-drop/:uuid/tmp-init", handlers.FileDropTmpInitHandler)
+ e.POST("/file-drop/:uuid/tmp", handlers.FileDropTmpHandler)
e.Any("*", getMainServer(i18nBundle, renderer))
return e
}