aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorveradec <glitchmill.dyj3d@simplelogin.co>2026-11-12 10:13:24 +0530
committerveradec <glitchmill.dyj3d@simplelogin.co>2026-11-12 10:13:24 +0530
commit7af53656c4b6a4e024a6618fc122fda06257d554 (patch)
treefde9d05643925d27036c6b456192a294d58e7e82 /main.go
parent282c26ce8411e17d75c3ca47fbd3876a9e1c9cb9 (diff)
add: creates a /random_dir/file_name just to have some de-duplicates
Diffstat (limited to 'main.go')
-rw-r--r--main.go34
1 files changed, 27 insertions, 7 deletions
diff --git a/main.go b/main.go
index 9af9e21..3a72a89 100644
--- a/main.go
+++ b/main.go
@@ -1,15 +1,36 @@
package main
import (
+ "math/rand"
"net/http"
"fmt"
"log"
"path/filepath"
"github.com/gin-gonic/gin"
+ "flag"
+ "time"
+ "os"
)
+func randomString(length int) string {
+ rand.Seed(time.Now().UnixNano())
+
+ const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
+ result := make([]byte, length)
+
+ for i := range result {
+ result[i] = charset[rand.Intn(len(charset))]
+ }
+
+ return string(result)
+}
+
func main(){
router := gin.Default()
+
+ domain := flag.String("domain", "Domain", "Website Link")
+
+ flag.Parse()
router.POST("/", func(c *gin.Context) {
// single file
@@ -19,10 +40,10 @@ func main(){
return
}
log.Println(file.Filename)
-
- dst := filepath.Join("./files/", filepath.Base(file.Filename))
+ random_string := randomString(6)
+ dst := filepath.Join("./files/", random_string, filepath.Base(file.Filename))
c.SaveUploadedFile(file, dst)
- c.String(http.StatusOK, fmt.Sprintf("%s/%s\n", domain , file.Filename))
+ c.String(http.StatusOK, fmt.Sprintf("%s/%s/%s\n", *domain, random_string ,file.Filename))
})
router.LoadHTMLFiles("index.html")
@@ -31,10 +52,9 @@ func main(){
c.HTML(http.StatusOK, "index.html", gin.H{})
})
- var safeFS http.FileSystem = http.Dir("./files")
- router.GET("/:name", func(c *gin.Context) {
- c.FileFromFS(c.Param("name"), safeFS)
- })
+ files := http.FileServer(http.FS(os.DirFS("./files")))
+
+ router.GET("/:random_string/:name", gin.WrapH(files))
router.Run(":8080")
}