id length selection in upload
This commit is contained in:
+8
-5
@@ -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"))
|
returnType := strings.TrimSpace(r.URL.Query().Get("return"))
|
||||||
if returnType == "" {
|
if returnType == "" {
|
||||||
returnType = "json"
|
returnType = "json"
|
||||||
@@ -175,6 +170,14 @@ func uploadHandler(db *gorm.DB, cfg Config, pages *template.Template) http.Handl
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
idLength := 16
|
||||||
|
if r.URL.Query().Get("idlength") == "short" {
|
||||||
|
idLength = 10
|
||||||
|
}
|
||||||
|
if r.PostForm.Get("idlength") == "short" {
|
||||||
|
idLength = 10
|
||||||
|
}
|
||||||
|
|
||||||
id := generateId(idLength)
|
id := generateId(idLength)
|
||||||
path := getStoragePath(cfg.UploadDir, id)
|
path := getStoragePath(cfg.UploadDir, id)
|
||||||
if err := os.MkdirAll(filepath.Dir(path), 0700); err != nil {
|
if err := os.MkdirAll(filepath.Dir(path), 0700); err != nil {
|
||||||
|
|||||||
+1
-2
@@ -142,8 +142,7 @@ input[type="file"]::file-selector-button {
|
|||||||
font: inherit;
|
font: inherit;
|
||||||
}
|
}
|
||||||
|
|
||||||
label[for="file-expiry"],
|
.muted {
|
||||||
label[for="paste-expiry"] {
|
|
||||||
color: var(--text-muted);
|
color: var(--text-muted);
|
||||||
}
|
}
|
||||||
select {
|
select {
|
||||||
|
|||||||
+12
-2
@@ -26,24 +26,34 @@
|
|||||||
<label for="type-paste">paste</label>
|
<label for="type-paste">paste</label>
|
||||||
<div class="file-panel">
|
<div class="file-panel">
|
||||||
<form action="/upload?return=html" method="post" enctype="multipart/form-data">
|
<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">
|
<select id="file-expiry" name="expiry">
|
||||||
{{range .Expiries}}
|
{{range .Expiries}}
|
||||||
<option value="{{.Label}}">{{.Label}}</option>
|
<option value="{{.Label}}">{{.Label}}</option>
|
||||||
{{end}}
|
{{end}}
|
||||||
</select>
|
</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" />
|
<input id="upload-file" type="file" required name="file" />
|
||||||
<button type="submit" class="btn">upload file</button>
|
<button type="submit" class="btn">upload file</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div class="paste-panel">
|
<div class="paste-panel">
|
||||||
<form action="/upload?return=html" method="post">
|
<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">
|
<select id="paste-expiry" name="expiry">
|
||||||
{{range .Expiries}}
|
{{range .Expiries}}
|
||||||
<option value="{{.Label}}">{{.Label}}</option>
|
<option value="{{.Label}}">{{.Label}}</option>
|
||||||
{{end}}
|
{{end}}
|
||||||
</select>
|
</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>
|
<textarea id="content" name="content" rows="10" required placeholder="{{.PastePlaceholder}}"></textarea>
|
||||||
<button type="submit" class="btn">upload paste</button>
|
<button type="submit" class="btn">upload paste</button>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
Reference in New Issue
Block a user