id length selection in upload

This commit is contained in:
2026-11-14 14:39:21 -05:00
parent 507ff7359c
commit c4222a16b2
3 changed files with 21 additions and 9 deletions
+8 -5
View File
@@ -81,11 +81,6 @@ func uploadHandler(db *gorm.DB, cfg Config, pages *template.Template) http.Handl
}
}
idLength := 16
if r.URL.Query().Get("idlength") == "short" {
idLength = 10
}
returnType := strings.TrimSpace(r.URL.Query().Get("return"))
if returnType == "" {
returnType = "json"
@@ -175,6 +170,14 @@ func uploadHandler(db *gorm.DB, cfg Config, pages *template.Template) http.Handl
return
}
idLength := 16
if r.URL.Query().Get("idlength") == "short" {
idLength = 10
}
if r.PostForm.Get("idlength") == "short" {
idLength = 10
}
id := generateId(idLength)
path := getStoragePath(cfg.UploadDir, id)
if err := os.MkdirAll(filepath.Dir(path), 0700); err != nil {
+1 -2
View File
@@ -142,8 +142,7 @@ input[type="file"]::file-selector-button {
font: inherit;
}
label[for="file-expiry"],
label[for="paste-expiry"] {
.muted {
color: var(--text-muted);
}
select {
+12 -2
View File
@@ -26,24 +26,34 @@
<label for="type-paste">paste</label>
<div class="file-panel">
<form action="/upload?return=html" method="post" enctype="multipart/form-data">
<label for="file-expiry">expiry</label>
<label class="muted" for="file-expiry">expiry</label>
<select id="file-expiry" name="expiry">
{{range .Expiries}}
<option value="{{.Label}}">{{.Label}}</option>
{{end}}
</select>
<label class="muted" for="file-id-length">id length</label>
<select id="file-id-length" name="idlength">
<option value="long">16 characters</option>
<option value="short">10 characters</option>
</select>
<input id="upload-file" type="file" required name="file" />
<button type="submit" class="btn">upload file</button>
</form>
</div>
<div class="paste-panel">
<form action="/upload?return=html" method="post">
<label for="paste-expiry">expiry</label>
<label class="muted" for="paste-expiry">expiry</label>
<select id="paste-expiry" name="expiry">
{{range .Expiries}}
<option value="{{.Label}}">{{.Label}}</option>
{{end}}
</select>
<label class="muted" for="paste-id-length">id length</label>
<select id="paste-id-length" name="idlength">
<option value="long">16 characters</option>
<option value="short">10 characters</option>
</select>
<textarea id="content" name="content" rows="10" required placeholder="{{.PastePlaceholder}}"></textarea>
<button type="submit" class="btn">upload paste</button>
</form>