Compare commits
No commits in common. "3d3cda319df5b04739543450110886c63b372947" and "88776337e43c546b5bb139232bc8f7d7bbeaff1a" have entirely different histories.
3d3cda319d
...
88776337e4
@ -7,8 +7,6 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type Article struct {
|
||||
@ -16,7 +14,6 @@ type Article struct {
|
||||
Title string
|
||||
BannerLink string
|
||||
Summary string
|
||||
UUID uuid.UUID
|
||||
ID int64
|
||||
CreatorID int64
|
||||
IssueID int64
|
||||
@ -34,8 +31,8 @@ func (db *DB) AddArticle(a *Article) (int64, error) {
|
||||
selectQuery := "SELECT id FROM issues WHERE published = false"
|
||||
insertQuery := `
|
||||
INSERT INTO articles
|
||||
(title, banner_link, summary, published, rejected, creator_id, issue_id, edited_id, clicks, is_in_issue, auto_generated, uuid)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
(title, banner_link, summary, published, rejected, creator_id, issue_id, edited_id, clicks, is_in_issue, auto_generated)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`
|
||||
|
||||
for i := 0; i < TxMaxRetries; i++ {
|
||||
@ -52,7 +49,7 @@ func (db *DB) AddArticle(a *Article) (int64, error) {
|
||||
return 0, fmt.Errorf("error getting issue ID when adding article to DB: %v", err)
|
||||
}
|
||||
|
||||
result, err := tx.Exec(insertQuery, a.Title, a.BannerLink, a.Summary, a.Published, a.Rejected, a.CreatorID, id, a.EditedID, 0, a.IsInIssue, a.AutoGenerated, a.UUID.String())
|
||||
result, err := tx.Exec(insertQuery, a.Title, a.BannerLink, a.Summary, a.Published, a.Rejected, a.CreatorID, id, a.EditedID, 0, a.IsInIssue, a.AutoGenerated)
|
||||
if err != nil {
|
||||
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||
@ -86,7 +83,7 @@ func (db *DB) AddArticle(a *Article) (int64, error) {
|
||||
|
||||
func (db *DB) GetArticle(id int64) (*Article, error) {
|
||||
query := `
|
||||
SELECT title, created, banner_link, summary, published, creator_id, issue_id, edited_id, clicks, is_in_issue, auto_generated, uuid
|
||||
SELECT title, created, banner_link, summary, published, creator_id, issue_id, edited_id, clicks, is_in_issue, auto_generated
|
||||
FROM articles
|
||||
WHERE id = ?
|
||||
`
|
||||
@ -94,10 +91,9 @@ func (db *DB) GetArticle(id int64) (*Article, error) {
|
||||
|
||||
article := new(Article)
|
||||
var created []byte
|
||||
var uuidString string
|
||||
var err error
|
||||
|
||||
if err := row.Scan(&article.Title, &created, &article.BannerLink, &article.Summary, &article.Published, &article.CreatorID, &article.IssueID, &article.EditedID, &article.Clicks, &article.IsInIssue, &article.AutoGenerated, &uuidString); err != nil {
|
||||
if err := row.Scan(&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)
|
||||
}
|
||||
|
||||
@ -107,17 +103,12 @@ func (db *DB) GetArticle(id int64) (*Article, error) {
|
||||
return nil, fmt.Errorf("error parsing created: %v", err)
|
||||
}
|
||||
|
||||
article.UUID, err = uuid.Parse(uuidString)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error parsing uuid: %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
|
||||
SELECT id, title, created, banner_link, summary, creator_id, issue_id, clicks, published, rejected, is_in_issue, auto_generated
|
||||
FROM articles
|
||||
WHERE %s = ?
|
||||
`, attribute)
|
||||
@ -130,9 +121,8 @@ func (db *DB) GetCertainArticles(attribute string, value bool) ([]*Article, erro
|
||||
for rows.Next() {
|
||||
article := new(Article)
|
||||
var created []byte
|
||||
var uuidString string
|
||||
|
||||
if err = rows.Scan(&article.ID, &article.Title, &created, &article.BannerLink, &article.Summary, &article.CreatorID, &article.IssueID, &article.Clicks, &article.Published, &article.Rejected, &article.IsInIssue, &article.AutoGenerated, &uuidString); err != nil {
|
||||
if err = rows.Scan(&article.ID, &article.Title, &created, &article.BannerLink, &article.Summary, &article.CreatorID, &article.IssueID, &article.Clicks, &article.Published, &article.Rejected, &article.IsInIssue, &article.AutoGenerated); err != nil {
|
||||
return nil, fmt.Errorf("error scanning article row: %v", err)
|
||||
}
|
||||
|
||||
@ -141,11 +131,6 @@ func (db *DB) GetCertainArticles(attribute string, value bool) ([]*Article, erro
|
||||
return nil, fmt.Errorf("error parsing created: %v", err)
|
||||
}
|
||||
|
||||
article.UUID, err = uuid.Parse(uuidString)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error parsing uuid: %v", err)
|
||||
}
|
||||
|
||||
articleList = append(articleList, article)
|
||||
}
|
||||
|
||||
@ -157,7 +142,7 @@ func (db *DB) GetCurrentIssueArticles() ([]*Article, error) {
|
||||
txOptions := &sql.TxOptions{Isolation: sql.LevelSerializable}
|
||||
issueQuery := "SELECT id FROM issues WHERE published = false"
|
||||
articlesQuery := `
|
||||
SELECT id, title, created, banner_link, summary, clicks, auto_generated, uuid
|
||||
SELECT id, title, created, banner_link, summary, clicks, auto_generated
|
||||
FROM articles
|
||||
WHERE issue_id = ? AND published = true AND is_in_issue = true
|
||||
`
|
||||
@ -189,9 +174,8 @@ func (db *DB) GetCurrentIssueArticles() ([]*Article, error) {
|
||||
for rows.Next() {
|
||||
article := new(Article)
|
||||
var created []byte
|
||||
var uuidString string
|
||||
|
||||
if err = rows.Scan(&article.ID, &article.Title, &created, &article.BannerLink, &article.Summary, &article.Clicks, &article.AutoGenerated, &uuidString); err != nil {
|
||||
if err = rows.Scan(&article.ID, &article.Title, &created, &article.BannerLink, &article.Summary, &article.Clicks, &article.AutoGenerated); err != nil {
|
||||
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||
}
|
||||
@ -206,14 +190,6 @@ func (db *DB) GetCurrentIssueArticles() ([]*Article, error) {
|
||||
return nil, fmt.Errorf("error parsing created: %v", err)
|
||||
}
|
||||
|
||||
article.UUID, err = uuid.Parse(uuidString)
|
||||
if err != nil {
|
||||
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||
log.Fatalf("transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||
}
|
||||
return nil, fmt.Errorf("error parsing uuid: %v", err)
|
||||
}
|
||||
|
||||
articleList = append(articleList, article)
|
||||
}
|
||||
|
||||
@ -308,11 +284,11 @@ func (db *DB) DeleteArticle(id int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func WriteArticleToFile(c *Config, articleUUID uuid.UUID, content []byte) error {
|
||||
articleAbsName := fmt.Sprint(c.ArticleDir, "/", articleUUID, ".md")
|
||||
func WriteArticleToFile(c *Config, articleID int64, content []byte) error {
|
||||
articleAbsName := fmt.Sprint(c.ArticleDir, "/", articleID, ".md")
|
||||
|
||||
if err := os.WriteFile(articleAbsName, content, 0644); err != nil {
|
||||
return fmt.Errorf("error writing article %v to file: %v", articleUUID, err)
|
||||
return fmt.Errorf("error writing article %v to file: %v", articleID, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -33,7 +33,7 @@ func GenerateAtomFeed(c *Config, db *DB) (*string, error) {
|
||||
entry := atom.NewEntry(articleTitle)
|
||||
entry.ID = atom.NewID(fmt.Sprint("urn:entry:", article.ID))
|
||||
entry.Published = atom.NewDate(article.Created)
|
||||
entry.Content = atom.NewContent(atom.OutOfLine, "text/html", fmt.Sprint(c.Domain, "/article/serve/", article.UUID))
|
||||
entry.Content = atom.NewContent(atom.OutOfLine, "text/hmtl", fmt.Sprint(c.Domain, "/article/serve/", article.ID))
|
||||
|
||||
if article.AutoGenerated {
|
||||
entry.Summary = atom.NewText("text", "automatically generated")
|
||||
|
@ -1,59 +0,0 @@
|
||||
package backend
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func ConvertToMarkdown(c *Config, filename string) ([]byte, error) {
|
||||
var stderr bytes.Buffer
|
||||
|
||||
articleID := uuid.New()
|
||||
articleFileName := fmt.Sprint("/tmp/", articleID, ".md")
|
||||
|
||||
tmpDir, err := os.MkdirTemp("/tmp", "cpolis_images")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error creating temporary directory: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
cmd := exec.Command("pandoc", "-s", "-f", "docx", "-t", "commonmark_x", "-o", articleFileName, "--extract-media", tmpDir, filename) // TODO: Is writing to a file necessary?
|
||||
cmd.Stderr = &stderr
|
||||
if err = cmd.Run(); err != nil {
|
||||
return nil, fmt.Errorf("error converting docx to markdown: %v: %v", err, stderr.String())
|
||||
}
|
||||
defer os.Remove(articleFileName)
|
||||
|
||||
articleContent, err := os.ReadFile(articleFileName)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error reading markdown file: %v", err)
|
||||
}
|
||||
|
||||
imageNames, err := filepath.Glob(filepath.Join(tmpDir, "/media/*"))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error getting docx images from temporary directory: %v", err)
|
||||
}
|
||||
|
||||
for _, name := range imageNames {
|
||||
image, err := os.Open(name)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error opening image file %v: %v", name, err)
|
||||
}
|
||||
defer image.Close()
|
||||
|
||||
newImageName, err := SaveImage(image, c.MaxImgHeight, c.MaxImgWidth, c.PicsDir)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error saving image %v: %v", name, err)
|
||||
}
|
||||
|
||||
articleContent = regexp.MustCompile(name).ReplaceAll(articleContent, []byte(c.PicsDir+"/"+newImageName))
|
||||
}
|
||||
|
||||
return articleContent, nil
|
||||
}
|
@ -10,7 +10,6 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
b "streifling.com/jason/cpolis/cmd/backend"
|
||||
)
|
||||
|
||||
@ -110,7 +109,6 @@ func SubmitArticle(c *b.Config, db *b.DB, s map[string]*Session) http.HandlerFun
|
||||
IsInIssue: r.PostFormValue("issue") == "on",
|
||||
AutoGenerated: false,
|
||||
EditedID: 0,
|
||||
UUID: uuid.New(),
|
||||
}
|
||||
|
||||
if len(article.Title) == 0 {
|
||||
@ -166,7 +164,7 @@ func SubmitArticle(c *b.Config, db *b.DB, s map[string]*Session) http.HandlerFun
|
||||
http.Error(w, "Bitte den Artikel eingeben.", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if err := b.WriteArticleToFile(c, article.UUID, content); err != nil {
|
||||
if err := b.WriteArticleToFile(c, article.ID, content); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@ -223,26 +221,14 @@ func ResubmitArticle(c *b.Config, db *b.DB, s map[string]*Session) http.HandlerF
|
||||
return
|
||||
}
|
||||
|
||||
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
article := &b.Article{
|
||||
Title: r.PostFormValue("article-title"),
|
||||
BannerLink: r.PostFormValue("article-banner-url"),
|
||||
Summary: r.PostFormValue("article-summary"),
|
||||
CreatorID: session.User.ID,
|
||||
IsInIssue: r.PostFormValue("issue") == "on",
|
||||
}
|
||||
|
||||
article, err := db.GetArticle(id)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
article.Title = r.PostFormValue("article-title")
|
||||
article.BannerLink = r.PostFormValue("article-banner-url")
|
||||
article.Summary = r.PostFormValue("article-summary")
|
||||
article.CreatorID = session.User.ID
|
||||
article.IsInIssue = r.PostFormValue("issue") == "on"
|
||||
|
||||
if len(article.Title) == 0 {
|
||||
http.Error(w, "Bitte den Titel eingeben.", http.StatusBadRequest)
|
||||
return
|
||||
@ -284,13 +270,20 @@ func ResubmitArticle(c *b.Config, db *b.DB, s map[string]*Session) http.HandlerF
|
||||
return
|
||||
}
|
||||
|
||||
article.ID, err = strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
content := r.PostFormValue("article-content")
|
||||
if len(content) == 0 {
|
||||
http.Error(w, "Bitte den Artikel eingeben.", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if err = b.WriteArticleToFile(c, article.UUID, []byte(content)); err != nil {
|
||||
contentLink := fmt.Sprint(c.ArticleDir, "/", article.ID, ".md")
|
||||
if err = os.WriteFile(contentLink, []byte(content), 0644); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@ -455,7 +448,7 @@ func ReviewRejectedArticle(c *b.Config, db *b.DB, s map[string]*Session) http.Ha
|
||||
|
||||
data.Image = data.Article.BannerLink
|
||||
|
||||
articleAbsName := fmt.Sprint(c.ArticleDir, "/", data.Article.UUID, ".md")
|
||||
articleAbsName := fmt.Sprint(c.ArticleDir, "/", data.Article.ID, ".md")
|
||||
content, err := os.ReadFile(articleAbsName)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
@ -586,7 +579,7 @@ func PublishArticle(c *b.Config, db *b.DB, s map[string]*Session) http.HandlerFu
|
||||
return
|
||||
}
|
||||
|
||||
if err = os.Remove(fmt.Sprint(c.ArticleDir, "/", oldArticle.UUID, ".md")); err != nil {
|
||||
if err = os.Remove(fmt.Sprint(c.ArticleDir, "/", oldArticle.ID, ".md")); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@ -764,7 +757,7 @@ func ReviewArticle(c *b.Config, db *b.DB, s map[string]*Session, action, title,
|
||||
return
|
||||
}
|
||||
|
||||
articleAbsName := fmt.Sprint(c.ArticleDir, "/", article.UUID, ".md")
|
||||
articleAbsName := fmt.Sprint(c.ArticleDir, "/", article.ID, ".md")
|
||||
content, err := os.ReadFile(articleAbsName)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
@ -826,20 +819,13 @@ func DeleteArticle(c *b.Config, db *b.DB, s map[string]*Session) http.HandlerFun
|
||||
return
|
||||
}
|
||||
|
||||
article, err := db.GetArticle(id)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if err = db.DeleteArticle(id); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if err = os.Remove(fmt.Sprint(c.ArticleDir, "/", article.UUID, ".md")); err != nil {
|
||||
if err = os.Remove(fmt.Sprint(c.ArticleDir, "/", id, ".md")); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@ -910,8 +896,8 @@ func AllowEditArticle(c *b.Config, db *b.DB, s map[string]*Session) http.Handler
|
||||
return
|
||||
}
|
||||
|
||||
src := fmt.Sprint(c.ArticleDir, "/", oldArticle.UUID, ".md")
|
||||
dst := fmt.Sprint(c.ArticleDir, "/", newArticle.UUID, ".md")
|
||||
src := fmt.Sprint(c.ArticleDir, "/", oldArticle.ID, ".md")
|
||||
dst := fmt.Sprint(c.ArticleDir, "/", newArticle.ID, ".md")
|
||||
if err = b.CopyFile(src, dst); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
@ -987,7 +973,7 @@ func EditArticle(c *b.Config, db *b.DB, s map[string]*Session) http.HandlerFunc
|
||||
|
||||
data.Image = data.Article.BannerLink
|
||||
|
||||
content, err := os.ReadFile(fmt.Sprint(c.ArticleDir, "/", data.Article.UUID, ".md"))
|
||||
content, err := os.ReadFile(fmt.Sprint(c.ArticleDir, "/", data.Article.ID, ".md"))
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
|
@ -1,107 +0,0 @@
|
||||
package frontend
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/gabriel-vasile/mimetype"
|
||||
"github.com/google/uuid"
|
||||
b "streifling.com/jason/cpolis/cmd/backend"
|
||||
)
|
||||
|
||||
func UploadDocx(c *b.Config, db *b.DB, s map[string]*Session) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
session, err := ManageSession(w, r, c, s)
|
||||
if err != nil {
|
||||
http.Error(w, "Die Session ist abgelaufen. Bitte erneut anmelden.", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
file, fileHeader, err := r.FormFile("docx-upload")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
var buf bytes.Buffer
|
||||
if _, err = io.Copy(&buf, file); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
mime := mimetype.Detect(buf.Bytes())
|
||||
if !mime.Is("application/vnd.openxmlformats-officedocument.wordprocessingml.document") {
|
||||
http.Error(w, "Die Datei ist kein DOCX Worddokument.", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
docxFilename := fmt.Sprint(uuid.New(), ".docx")
|
||||
absDocxFilepath, err := filepath.Abs("/tmp/" + docxFilename)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if err = os.WriteFile(absDocxFilepath, buf.Bytes(), 0644); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
defer os.Remove(absDocxFilepath)
|
||||
|
||||
mdString, err := b.ConvertToMarkdown(c, absDocxFilepath)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
uuidName := uuid.New()
|
||||
mdFilename := fmt.Sprint(uuidName, ".md")
|
||||
absMdFilepath, err := filepath.Abs(c.ArticleDir + "/" + mdFilename)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if err = os.WriteFile(absMdFilepath, mdString, 0644); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
article := &b.Article{
|
||||
Created: time.Now(),
|
||||
UUID: uuidName,
|
||||
CreatorID: session.User.ID,
|
||||
Rejected: true,
|
||||
}
|
||||
article.Title = fmt.Sprint(fileHeader.Filename, "-", article.UUID)
|
||||
|
||||
id, err := db.AddArticle(article)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if err = db.WriteArticleAuthors(id, []int64{session.User.ID}); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
}
|
@ -8,7 +8,6 @@ import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
b "streifling.com/jason/cpolis/cmd/backend"
|
||||
)
|
||||
|
||||
@ -27,7 +26,6 @@ func PublishLatestIssue(c *b.Config, db *b.DB, s map[string]*Session) http.Handl
|
||||
Rejected: false,
|
||||
Created: time.Now(),
|
||||
AutoGenerated: true,
|
||||
UUID: uuid.New(),
|
||||
}
|
||||
|
||||
if len(article.Title) == 0 {
|
||||
@ -57,7 +55,7 @@ func PublishLatestIssue(c *b.Config, db *b.DB, s map[string]*Session) http.Handl
|
||||
return
|
||||
}
|
||||
|
||||
articleAbsName := fmt.Sprint(c.ArticleDir, "/", article.UUID, ".md")
|
||||
articleAbsName := fmt.Sprint(c.ArticleDir, "/", article.ID, ".md")
|
||||
if err = os.WriteFile(articleAbsName, content, 0644); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
|
@ -252,7 +252,7 @@ func UpdateSelf(c *b.Config, db *b.DB, s map[string]*Session) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func AddFirstUser(c *b.Config, db *b.DB, s map[string]*Session, sessionExpiryChan chan string) http.HandlerFunc {
|
||||
func AddFirstUser(c *b.Config, db *b.DB, s map[string]*Session) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var err error
|
||||
user := &b.User{
|
||||
@ -305,12 +305,8 @@ func AddFirstUser(c *b.Config, db *b.DB, s map[string]*Session, sessionExpiryCha
|
||||
return
|
||||
}
|
||||
|
||||
session := newSession(w, c, sessionExpiryChan, user)
|
||||
s[session.cookie.Value] = session
|
||||
http.SetCookie(w, session.cookie)
|
||||
|
||||
data := new(struct{ Role int })
|
||||
data.Role = user.Role
|
||||
data.Role = 0
|
||||
|
||||
tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html")
|
||||
if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", data); err != nil {
|
||||
|
@ -32,8 +32,6 @@ func main() {
|
||||
sessions, sessionExpiryChan := f.StartSessions()
|
||||
defer close(sessionExpiryChan)
|
||||
|
||||
go b.CleanUpImages(config)
|
||||
|
||||
mux := http.NewServeMux()
|
||||
mux.Handle("/web/static/", http.StripPrefix("/web/static/",
|
||||
http.FileServer(http.Dir(config.WebDir+"/static/"))))
|
||||
@ -74,14 +72,13 @@ func main() {
|
||||
mux.HandleFunc("POST /article/submit", f.SubmitArticle(config, db, sessions))
|
||||
mux.HandleFunc("POST /article/upload-banner", f.UploadImage(config, sessions, "article-banner", "editor.html", "article-banner-template"))
|
||||
mux.HandleFunc("POST /article/upload-image", f.UploadEasyMDEImage(config, sessions))
|
||||
mux.HandleFunc("POST /docx/upload", f.UploadDocx(config, db, sessions))
|
||||
mux.HandleFunc("POST /issue/publish", f.PublishLatestIssue(config, db, sessions))
|
||||
mux.HandleFunc("POST /issue/upload-banner", f.UploadImage(config, sessions, "issue-banner", "current-issue.html", "issue-banner-template"))
|
||||
mux.HandleFunc("POST /login", f.Login(config, db, sessions, sessionExpiryChan))
|
||||
mux.HandleFunc("POST /pdf/upload", f.UploadPDF(config, sessions))
|
||||
mux.HandleFunc("POST /tag/add", f.AddTag(config, db, sessions))
|
||||
mux.HandleFunc("POST /user/add", f.AddUser(config, db, sessions))
|
||||
mux.HandleFunc("POST /user/add-first", f.AddFirstUser(config, db, sessions, sessionExpiryChan))
|
||||
mux.HandleFunc("POST /user/add-first", f.AddFirstUser(config, db, sessions))
|
||||
mux.HandleFunc("POST /user/update/{id}", f.UpdateUser(config, db, sessions))
|
||||
mux.HandleFunc("POST /user/update/self", f.UpdateSelf(config, db, sessions))
|
||||
mux.HandleFunc("POST /user/upload-profile-pic", f.UploadImage(config, sessions, "upload-profile-pic", "edit-user.html", "profile-pic-template"))
|
||||
|
@ -38,7 +38,6 @@ CREATE TABLE articles (
|
||||
clicks INT NOT NULL,
|
||||
is_in_issue BOOL NOT NULL,
|
||||
auto_generated BOOL NOT NULL,
|
||||
uuid VARCHAR(36) NOT NULL,
|
||||
PRIMARY KEY (id),
|
||||
FOREIGN KEY (creator_id) REFERENCES users (id),
|
||||
FOREIGN KEY (issue_id) REFERENCES issues (id)
|
||||
|
1
go.mod
1
go.mod
@ -8,7 +8,6 @@ require (
|
||||
github.com/BurntSushi/toml v1.4.0
|
||||
github.com/chai2010/webp v1.1.1
|
||||
github.com/disintegration/imaging v1.6.2
|
||||
github.com/gabriel-vasile/mimetype v1.4.8
|
||||
github.com/go-sql-driver/mysql v1.8.1
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/microcosm-cc/bluemonday v1.0.27
|
||||
|
2
go.sum
2
go.sum
@ -62,8 +62,6 @@ github.com/envoyproxy/protoc-gen-validate v1.1.0 h1:tntQDh69XqOCOZsDz0lVJQez/2L6
|
||||
github.com/envoyproxy/protoc-gen-validate v1.1.0/go.mod h1:sXRDRVmzEbkM7CVcM06s9shE/m23dg3wzjl0UWqJ2q4=
|
||||
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
|
||||
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
|
||||
github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM=
|
||||
github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8=
|
||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
|
||||
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
|
@ -7,11 +7,6 @@
|
||||
<h2>Artikel</h2>
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-x-4 gap-y-2">
|
||||
<button class="btn" hx-get="/article/write" hx-target="#page-content">Artikel schreiben</button>
|
||||
<form class="flex" hx-encoding="multipart/form-data">
|
||||
<label class="btn text-center" for="docx-upload">Word-Dokument hochladen</label>
|
||||
<input accept=".docx" class="hidden" id="docx-upload" name="docx-upload" type="file"
|
||||
hx-post="/docx/upload" />
|
||||
</form>
|
||||
<button class="btn" hx-get="/article/all-rejected" hx-target="#page-content">Artikel bearbeiten</button>
|
||||
{{if lt .Role 3}}<button class="btn" hx-get="/article/all-unpublished-unrejected-and-published-rejected"
|
||||
hx-target="#page-content">Artikel veröffentlichen</button>{{end}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user