Compare commits
No commits in common. "f28c204c524d251828abb28c00f102a4069f0539" and "863581f5909f35d6016c0e1145d623597dbb3d7d" have entirely different histories.
f28c204c52
...
863581f590
@ -3,7 +3,6 @@ package backend
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -20,30 +19,10 @@ func CopyFile(src, dst string) error {
|
|||||||
}
|
}
|
||||||
defer dstFile.Close()
|
defer dstFile.Close()
|
||||||
|
|
||||||
if _, err = io.Copy(dstFile, srcFile); err != nil {
|
_, err = io.Copy(dstFile, srcFile)
|
||||||
|
if err != nil {
|
||||||
return fmt.Errorf("error copying file: %v", err)
|
return fmt.Errorf("error copying file: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return dstFile.Sync()
|
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{
|
item := &rss.Item{
|
||||||
Author: user.FirstName + " " + user.LastName,
|
Author: fmt.Sprint(user.FirstName, " ", user.LastName),
|
||||||
Categories: tagNames,
|
Categories: tagNames,
|
||||||
Description: articleDescription,
|
Description: articleDescription,
|
||||||
Guid: string(article.ID),
|
Guid: string(article.ID),
|
||||||
|
@ -2,6 +2,7 @@ package calls
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@ -42,6 +43,6 @@ func ServePDF(c *b.Config) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
http.ServeFile(w, r, c.PDFDir+"/"+r.PathValue("id"))
|
http.ServeFile(w, r, fmt.Sprint(c.PDFDir, "/", r.PathValue("id")))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -547,7 +547,7 @@ func UploadArticleImage(c *b.Config, s *b.CookieStore) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
url := c.Domain + "/image/serve/" + filename
|
url := fmt.Sprint(c.Domain, "/image/serve/", filename)
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
json.NewEncoder(w).Encode(url)
|
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{
|
article := &b.Article{
|
||||||
Title: title,
|
Title: title,
|
||||||
EncURL: c.Domain + "/image/serve/" + imgFileName,
|
EncURL: fmt.Sprint(c.Domain, "/image/serve/", imgFileName),
|
||||||
EncLength: int(imgInfo.Size()),
|
EncLength: int(imgInfo.Size()),
|
||||||
EncType: mime.TypeByExtension(filepath.Ext(imgAbsName)),
|
EncType: mime.TypeByExtension(filepath.Ext(imgAbsName)),
|
||||||
Published: true,
|
Published: true,
|
||||||
|
@ -2,8 +2,10 @@ package frontend
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
@ -51,14 +53,22 @@ func UploadPDF(c *b.Config, s *b.CookieStore) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
filename := fmt.Sprint(uuid.New(), ".pdf")
|
filename := fmt.Sprint(uuid.New(), ".pdf")
|
||||||
absFilepath, err := filepath.Abs(c.PDFDir + "/" + filename)
|
absFilepath, err := filepath.Abs(fmt.Sprint(c.PDFDir, "/", filename))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = b.WriteFile(absFilepath, file); err != nil {
|
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 {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user