Strictly require title for issue

This commit is contained in:
Jason Streifling 2024-09-28 12:34:15 +02:00
parent 2743899b65
commit 4bd255a7c4
3 changed files with 13 additions and 8 deletions

View File

@ -30,6 +30,14 @@ func PublishLatestIssue(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFun
return return
} }
title := r.PostFormValue("issue-title")
if len(title) == 0 {
err = fmt.Errorf("error: no title for issue specified")
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if session.Values["issue-image"] == nil { if session.Values["issue-image"] == nil {
err := "error: Image required" err := "error: Image required"
log.Println(err) log.Println(err)
@ -55,14 +63,11 @@ func PublishLatestIssue(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFun
return return
} }
imgSize := imgInfo.Size()
mimeType := mime.TypeByExtension(filepath.Ext(imgAbsName))
article := &b.Article{ article := &b.Article{
Title: r.PostFormValue("issue-title"), Title: title,
EncURL: fmt.Sprint(c.Domain, "/image/serve/", imgFileName), EncURL: fmt.Sprint(c.Domain, "/image/serve/", imgFileName),
EncLength: int(imgSize), EncLength: int(imgInfo.Size()),
EncType: mimeType, EncType: mime.TypeByExtension(filepath.Ext(imgAbsName)),
Published: true, Published: true,
Rejected: false, Rejected: false,
Created: time.Now(), Created: time.Now(),

View File

@ -18,7 +18,7 @@
<div> <div>
<h3>Titelseite</h3> <h3>Titelseite</h3>
<div class="grid grid-cols-2 gap-4 items-center"> <div class="grid grid-cols-2 gap-4 items-center">
<input class="h-full" name="issue-title" placeholder="Titel" type="text" /> <input class="h-full" name="issue-title" placeholder="Titel" required type="text" />
<label class="btn text-center" for="image-upload">Bild hochladen</label> <label class="btn text-center" for="image-upload">Bild hochladen</label>
<input class="hidden" id="image-upload" name="issue-image" type="file" required <input class="hidden" id="image-upload" name="issue-image" type="file" required
hx-post="/issue/upload-image" /> hx-post="/issue/upload-image" />

View File

@ -35,7 +35,7 @@
<footer class="text-center text-gray-500 my-8"> <footer class="text-center text-gray-500 my-8">
<p>&copy; 2024 Jason Streifling. Alle Rechte vorbehalten.</p> <p>&copy; 2024 Jason Streifling. Alle Rechte vorbehalten.</p>
<p>v0.11.0 - <strong>Alpha: Änderungen und Fehler möglich.</strong></p> <p>v0.11.0 - <strong>Alpha: Drastische Änderungen und Fehler vorbehalten.</strong></p>
</footer> </footer>
<script src="https://unpkg.com/htmx.org@2.0.2"></script> <script src="https://unpkg.com/htmx.org@2.0.2"></script>