Zip bundles: generate cutesy zip display names

This commit is contained in:
root
2026-03-23 17:10:15 +01:00
parent 09d919ca27
commit db5c2558f8

View File

@@ -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,