diff --git a/internal/file/zip.go b/internal/file/zip.go index df73ced..545fde4 100644 --- a/internal/file/zip.go +++ b/internal/file/zip.go @@ -2,9 +2,11 @@ package file import ( "archive/zip" + "crypto/rand" "errors" "fmt" "io" + "math/big" "mime/multipart" "os" "path/filepath" @@ -36,6 +38,36 @@ func dedupeName(name string, seen map[string]int) string { return fmt.Sprintf("%s (%d)%s", base, seen[name], ext) } +func randIndex(n int) int { + if n <= 0 { + return 0 + } + x, err := rand.Int(rand.Reader, big.NewInt(int64(n))) + if err != nil { + return 0 + } + return int(x.Int64()) +} + +func cuteZipName(fileCount int) string { + adjectives := []string{ + "Cool", "Super", "Hot", "Spicy", "Sneaky", "Sleepy", "Tiny", "Mega", "Cosmic", "Silly", + "Cursed", "Blessed", "Wiggly", "Giga", "Chonky", "Shiny", "Angry", "Happy", "Soft", "Turbo", + } + things := []string{ + "Potato", "Griefers", "Raccoons", "Pigeons", "Wizards", "Ninjas", "Pickles", "Dragons", "Goblins", "Burgers", + "Pancakes", "Hamsters", "Bananas", "Comets", "Robots", "Cats", "Kiwis", "Frogs", "Cupcakes", "Sprites", + } + verbs := []string{ + "Zoom", "Bonk", "Yeet", "Vibe", "Hack", "Spark", "Bounce", "Nibble", "Smuggle", "Cook", + } + + a := adjectives[randIndex(len(adjectives))] + v := verbs[randIndex(len(verbs))] + t := things[randIndex(len(things))] + return fmt.Sprintf("%d%s%s%s.zip", fileCount, a, v, t) +} + // UploadBundle zips multiple uploaded files into a single .zip stored on disk and tracked as one FileRecord. func (s *Service) UploadBundle(files []*multipart.FileHeader, deleteAfterDownload bool, expiresAfter time.Duration) (*FileRecord, error) { if len(files) == 0 { @@ -105,7 +137,7 @@ func (s *Service) UploadBundle(files []*multipart.FileHeader, deleteAfterDownloa return nil, closeErr } - zipDisplayName := fmt.Sprintf("bundle-%d-files.zip", len(files)) + zipDisplayName := cuteZipName(len(files)) f := &FileRecord{ ID: folderID,