Compare commits
50 Commits
5552e6d2eb
...
v0.15.0
Author | SHA1 | Date | |
---|---|---|---|
1b100483de | |||
e03fd78ea9 | |||
370ef205a9 | |||
d328ddb749 | |||
5dc5590da9 | |||
364112a0a4 | |||
a38523e933 | |||
200672dae2 | |||
3d3aad88c8 | |||
e4e43d1a83 | |||
737a9ec314 | |||
1ebe0380ee | |||
d62d71b5d1 | |||
b36e0ea503 | |||
bc4d8fa37e | |||
d2b21e7405 | |||
e3c192359f | |||
46532e4c85 | |||
c722135a56 | |||
887fa863bc | |||
74d71cfb6a | |||
ca7e7cddd3 | |||
94431a2aa9 | |||
5b1f20c5bc | |||
d0c566f8df | |||
5e586aa49a | |||
66b2743d3d | |||
3723b2b5e6 | |||
ce788bfd50 | |||
230a6278cc | |||
42d6e0c198 | |||
e1af2979af | |||
f6dedc6f10 | |||
cdf0a49550 | |||
c3c0650210 | |||
d077f700d8 | |||
ec752b1c66 | |||
46aef4f12f | |||
1b29e328cf | |||
e50cb819f3 | |||
c32e38ca10 | |||
d7c8c7a43a | |||
1cd3edc90c | |||
0e768c9f61 | |||
1fcd775cc5 | |||
203a1ed147 | |||
ef1914ee5c | |||
084b101e31 | |||
b2db128aa9 | |||
081e880fb6 |
@ -115,31 +115,6 @@ func (db *DB) GetArticle(id int64) (*Article, error) {
|
||||
return article, nil
|
||||
}
|
||||
|
||||
func (db *DB) GetArticleByUUID(u uuid.UUID) (*Article, error) {
|
||||
query := `
|
||||
SELECT id, title, created, banner_link, summary, published, creator_id, issue_id, edited_id, clicks, is_in_issue, auto_generated
|
||||
FROM articles
|
||||
WHERE uuid = ?
|
||||
`
|
||||
row := db.QueryRow(query, u.String())
|
||||
|
||||
article := new(Article)
|
||||
var created []byte
|
||||
var err error
|
||||
|
||||
if err := row.Scan(&article.ID, &article.Title, &created, &article.BannerLink, &article.Summary, &article.Published, &article.CreatorID, &article.IssueID, &article.EditedID, &article.Clicks, &article.IsInIssue, &article.AutoGenerated); err != nil {
|
||||
return nil, fmt.Errorf("error scanning article row: %v", err)
|
||||
}
|
||||
|
||||
article.UUID = u
|
||||
article.Created, err = time.Parse("2006-01-02 15:04:05", string(created))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error parsing created: %v", err)
|
||||
}
|
||||
|
||||
return article, nil
|
||||
}
|
||||
|
||||
func (db *DB) GetCertainArticles(attribute string, value bool) ([]*Article, error) {
|
||||
query := fmt.Sprintf(`
|
||||
SELECT id, title, created, banner_link, summary, creator_id, issue_id, clicks, published, rejected, is_in_issue, auto_generated, uuid
|
||||
|
@ -52,7 +52,7 @@ func ConvertToMarkdown(c *Config, filename string) ([]byte, error) {
|
||||
return nil, fmt.Errorf("error saving image %v: %v", name, err)
|
||||
}
|
||||
|
||||
articleContent = regexp.MustCompile(name).ReplaceAll(articleContent, []byte(c.Domain+"/image/serve/"+newImageName))
|
||||
articleContent = regexp.MustCompile(name).ReplaceAll(articleContent, []byte(c.PicsDir+"/"+newImageName))
|
||||
}
|
||||
|
||||
return articleContent, nil
|
||||
|
@ -7,7 +7,6 @@ import (
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/google/uuid"
|
||||
b "streifling.com/jason/cpolis/cmd/backend"
|
||||
)
|
||||
|
||||
@ -38,15 +37,15 @@ func ServeArticle(c *b.Config, db *b.DB) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
uuidString := r.PathValue("uuid")
|
||||
uuid, err := uuid.Parse(uuidString)
|
||||
idString := r.PathValue("id")
|
||||
id, err := strconv.ParseInt(idString, 10, 64)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
article, err := db.GetArticleByUUID(uuid)
|
||||
article, err := db.GetArticle(id)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
@ -57,7 +56,7 @@ func ServeArticle(c *b.Config, db *b.DB) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
articleAbsName := fmt.Sprint(c.ArticleDir, "/", article.UUID, ".md")
|
||||
articleAbsName := fmt.Sprint(c.ArticleDir, "/", article.ID, ".md")
|
||||
contentBytes, err := os.ReadFile(articleAbsName)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
|
@ -5,7 +5,6 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/google/uuid"
|
||||
b "streifling.com/jason/cpolis/cmd/backend"
|
||||
@ -18,7 +17,7 @@ func UploadPDF(c *b.Config, s map[string]*Session) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
file, header, err := r.FormFile("pdf-upload")
|
||||
file, _, err := r.FormFile("pdf-upload")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
@ -44,9 +43,7 @@ func UploadPDF(c *b.Config, s map[string]*Session) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
oldFilename := header.Filename
|
||||
oldFilename = strings.Join(strings.Split(oldFilename, ".")[:len(oldFilename)-1], ".")
|
||||
filename := fmt.Sprint(oldFilename, ".", uuid.New(), ".pdf")
|
||||
filename := fmt.Sprint(uuid.New(), ".pdf")
|
||||
absFilepath, err := filepath.Abs(c.PDFDir + "/" + filename)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
|
@ -52,7 +52,7 @@ func main() {
|
||||
mux.HandleFunc("GET /article/review-edit/{id}", f.ReviewArticle(config, db, sessions, "allow-edit", "Artikel bearbeiten", "Bearbeiten erlauben"))
|
||||
mux.HandleFunc("GET /article/review-rejected/{id}", f.ReviewRejectedArticle(config, db, sessions))
|
||||
mux.HandleFunc("GET /article/review-unpublished/{id}", f.ReviewArticle(config, db, sessions, "publish", "Artikel veröffentlichen", "Veröffentlichen"))
|
||||
mux.HandleFunc("GET /article/serve/{uuid}", c.ServeArticle(config, db))
|
||||
mux.HandleFunc("GET /article/serve/{id}", c.ServeArticle(config, db))
|
||||
mux.HandleFunc("GET /article/serve/{id}/clicks", c.ServeClicks(db))
|
||||
mux.HandleFunc("GET /article/write", f.WriteArticle(config, db, sessions))
|
||||
mux.HandleFunc("GET /atom/serve", c.ServeAtomFeed(config))
|
||||
|
Reference in New Issue
Block a user