Compare commits
4 Commits
v0.12.0
...
2751a8c972
Author | SHA1 | Date | |
---|---|---|---|
2751a8c972 | |||
750184b8ef | |||
f28c204c52 | |||
70d403d7d7 |
@ -3,6 +3,7 @@ package backend
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
@ -19,10 +20,30 @@ func CopyFile(src, dst string) error {
|
||||
}
|
||||
defer dstFile.Close()
|
||||
|
||||
_, err = io.Copy(dstFile, srcFile)
|
||||
if err != nil {
|
||||
if _, err = io.Copy(dstFile, srcFile); err != nil {
|
||||
return fmt.Errorf("error copying file: %v", err)
|
||||
}
|
||||
|
||||
return dstFile.Sync()
|
||||
}
|
||||
|
||||
func WriteFile(path string, src io.Reader) error {
|
||||
file, err := os.Create(path)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return fmt.Errorf("error creating file: %v", err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
if _, err = io.Copy(file, src); err != nil {
|
||||
log.Println(err)
|
||||
return fmt.Errorf("error copying file: %v", err)
|
||||
}
|
||||
|
||||
if err = file.Sync(); err != nil {
|
||||
log.Println(err)
|
||||
return fmt.Errorf("error syncing file: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ func GenerateRSS(c *Config, db *DB) (*string, error) {
|
||||
}
|
||||
|
||||
item := &rss.Item{
|
||||
Author: fmt.Sprint(user.FirstName, " ", user.LastName),
|
||||
Author: user.FirstName + " " + user.LastName,
|
||||
Categories: tagNames,
|
||||
Description: articleDescription,
|
||||
Guid: string(article.ID),
|
||||
|
@ -2,7 +2,6 @@ package calls
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
@ -43,6 +42,6 @@ func ServePDF(c *b.Config) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
http.ServeFile(w, r, fmt.Sprint(c.PDFDir, "/", r.PathValue("id")))
|
||||
http.ServeFile(w, r, c.PDFDir+"/"+r.PathValue("id"))
|
||||
}
|
||||
}
|
||||
|
@ -547,7 +547,7 @@ func UploadArticleImage(c *b.Config, s *b.CookieStore) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
url := fmt.Sprint(c.Domain, "/image/serve/", filename)
|
||||
url := c.Domain + "/image/serve/" + filename
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(url)
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ func PublishLatestIssue(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFun
|
||||
|
||||
article := &b.Article{
|
||||
Title: title,
|
||||
EncURL: fmt.Sprint(c.Domain, "/image/serve/", imgFileName),
|
||||
EncURL: c.Domain + "/image/serve/" + imgFileName,
|
||||
EncLength: int(imgInfo.Size()),
|
||||
EncType: mime.TypeByExtension(filepath.Ext(imgAbsName)),
|
||||
Published: true,
|
||||
|
@ -2,10 +2,8 @@ package frontend
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@ -48,27 +46,19 @@ func UploadPDF(c *b.Config, s *b.CookieStore) http.HandlerFunc {
|
||||
}
|
||||
|
||||
if http.DetectContentType(buffer) != "application/pdf" {
|
||||
http.Error(w, "Die Datei ist kein PDF.", http.StatusInternalServerError)
|
||||
http.Error(w, "Die Datei ist kein PDF.", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
filename := fmt.Sprint(uuid.New(), ".pdf")
|
||||
absFilepath, err := filepath.Abs(fmt.Sprint(c.PDFDir, "/", filename))
|
||||
absFilepath, err := filepath.Abs(c.PDFDir + "/" + filename)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
pdf, err := os.Create(absFilepath)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
defer pdf.Close()
|
||||
|
||||
if _, err = io.Copy(pdf, file); err != nil {
|
||||
if err = b.WriteFile(absFilepath, file); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
|
@ -19,7 +19,7 @@
|
||||
<h3>Titelseite</h3>
|
||||
<div class="grid grid-cols-2 gap-4 items-center">
|
||||
<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">Titelbild</label>
|
||||
<input class="hidden" id="image-upload" name="issue-image" type="file" required
|
||||
hx-post="/issue/upload-image" />
|
||||
</div>
|
||||
|
@ -4,7 +4,13 @@
|
||||
<form id="edit-area">
|
||||
<div class="flex flex-col gap-y-1">
|
||||
<label for="article-title">Titel</label>
|
||||
<input name="article-title" type="text" value="{{.Article.Title}}" />
|
||||
<div class="grid grid-cols-2 gap-4 items-center">
|
||||
<input name="article-title" type="text" value="{{.Article.Title}}" />
|
||||
<label class="btn text-center" for="image-upload">Titelbild</label>
|
||||
<input class="hidden" id="image-upload" name="issue-image" type="file" required
|
||||
hx-post="/issue/upload-image" />
|
||||
<!-- TODO: Route einfügen -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-y-1">
|
||||
|
Reference in New Issue
Block a user