dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit 15c017647c1fb3ceb43918b2ee296ddde60d0fab
parent e118706dd2fdf7ffdc2acf01f565d204d92be0dd
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Mon, 30 Jan 2023 16:26:03 -0800

toggle local

Diffstat:
Mcmd/dkfupload/main.go | 20++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/cmd/dkfupload/main.go b/cmd/dkfupload/main.go @@ -20,9 +20,10 @@ import ( ) const ( - userAgent = "Mozilla/5.0 (Windows NT 10.0; rv:102.0) Gecko/20100101 Firefox/102.0" - torProxyAddr = "127.0.0.1:9050" - dkfBaseURL = "http://dkforestseeaaq2dqz2uflmlsybvnq2irzn4ygyvu53oazyorednviid.onion" + userAgent = "Mozilla/5.0 (Windows NT 10.0; rv:102.0) Gecko/20100101 Firefox/102.0" + dkfBaseURL = "http://dkforestseeaaq2dqz2uflmlsybvnq2irzn4ygyvu53oazyorednviid.onion" + torProxyAddr = "127.0.0.1:9050" + localhostAddr = "127.0.0.1:8080" ) func main() { @@ -31,6 +32,7 @@ func main() { var filedropUUID string var fileName string var dry bool + var local bool var maxChunkSize int64 flag.StringVar(&apiKey, "api-key", "", "dkf api key") flag.StringVar(&filedropUUID, "filedrop-uuid", "", "dkf filedrop uuid") @@ -39,8 +41,11 @@ func main() { flag.IntVar(&nbThreads, "threads", 20, "nb threads") flag.Int64Var(&maxChunkSize, "chunk-size", 10<<20, "chunk size") // 10MB flag.BoolVar(&dry, "dry", false, "dry run") + flag.BoolVar(&local, "local", false, "localhost development") flag.Parse() + baseUrl := Ternary(local, localhostAddr, dkfBaseURL) + f, err := os.Open(fileName) if err != nil { log.Fatalln(err.Error()) @@ -95,7 +100,7 @@ func main() { if !dry { // TODO: http post the chunk to server hasToSucceed(func() error { - req, _ := http.NewRequest(http.MethodPost, dkfBaseURL+"/file-drop/"+filedropUUID, nil) + req, _ := http.NewRequest(http.MethodPost, baseUrl+"/file-drop/"+filedropUUID, nil) req.Header.Set("User-Agent", userAgent) req.Header.Set("DKF_API_KEY", apiKey) _, err := client.Do(req) @@ -150,3 +155,10 @@ func GenerateTokenN(n int) string { _, _ = rand.Read(b) return hex.EncodeToString(b) } + +func Ternary[T any](predicate bool, a, b T) T { + if predicate { + return a + } + return b +}