Compare commits
27 Commits
firebase
...
a33e7f9896
Author | SHA1 | Date | |
---|---|---|---|
a33e7f9896 | |||
2b2ab0d428 | |||
c52e35bf0b | |||
cddd88d2f6 | |||
be467521d9 | |||
10d8fceb77 | |||
714cdd9aaf | |||
5474b17ce5 | |||
a318a265d4 | |||
365d5a68a1 | |||
b451da7e8e | |||
6a4a592714 | |||
806cfb01bd | |||
c2cadd1542 | |||
4cb2831e9a | |||
ee31a9f8e2 | |||
beec20cdda | |||
7ef957c2d7 | |||
d56cdc78eb | |||
151d89d9f0 | |||
8d2944d00c | |||
9ddd8198ee | |||
ff6c7a66d7 | |||
129c85929c | |||
b1a6359473 | |||
b5d979dbf8 | |||
77e8edbe16 |
@ -256,3 +256,21 @@ func (db *DB) AddArticleToCurrentIssue(id int64) error {
|
|||||||
|
|
||||||
return fmt.Errorf("error: %v unsuccessful retries for DB operation, aborting", TxMaxRetries)
|
return fmt.Errorf("error: %v unsuccessful retries for DB operation, aborting", TxMaxRetries)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (db *DB) DeleteArticle(id int64) error {
|
||||||
|
articlesTagsQuery := "DELETE FROM articles_tags WHERE article_id = ?"
|
||||||
|
|
||||||
|
_, err := db.Exec(articlesTagsQuery, id)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error deleting article %v from DB: %v", id, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
articlesQuery := "DELETE FROM articles WHERE id = ?"
|
||||||
|
|
||||||
|
_, err = db.Exec(articlesQuery, id)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error deleting article %v from DB: %v", id, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -14,6 +14,7 @@ type Config struct {
|
|||||||
DBName string
|
DBName string
|
||||||
Description string
|
Description string
|
||||||
Domain string
|
Domain string
|
||||||
|
FirebaseKey string
|
||||||
KeyFile string
|
KeyFile string
|
||||||
Link string
|
Link string
|
||||||
LogFile string
|
LogFile string
|
||||||
@ -27,13 +28,14 @@ type Config struct {
|
|||||||
|
|
||||||
func newConfig() *Config {
|
func newConfig() *Config {
|
||||||
return &Config{
|
return &Config{
|
||||||
DBName: "cpolis",
|
DBName: "cpolis",
|
||||||
KeyFile: "/var/www/cpolis/cpolis.key",
|
FirebaseKey: "/var/www/cpolis/serviceAccountKey.json",
|
||||||
LogFile: "/var/log/cpolis.log",
|
KeyFile: "/var/www/cpolis/cpolis.key",
|
||||||
PDFDir: "/var/www/cpolis/pdfs",
|
LogFile: "/var/log/cpolis.log",
|
||||||
PicsDir: "/var/www/cpolis/pics",
|
PDFDir: "/var/www/cpolis/pdfs",
|
||||||
RSSFile: "/var/www/cpolis/cpolis.rss",
|
PicsDir: "/var/www/cpolis/pics",
|
||||||
WebDir: "/var/www/cpolis/web",
|
RSSFile: "/var/www/cpolis/cpolis.rss",
|
||||||
|
WebDir: "/var/www/cpolis/web",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,19 +78,25 @@ func (c *Config) handleCliArgs() error {
|
|||||||
port := 8080
|
port := 8080
|
||||||
|
|
||||||
flag.StringVar(&c.DBName, "db", c.DBName, "DB name")
|
flag.StringVar(&c.DBName, "db", c.DBName, "DB name")
|
||||||
flag.StringVar(&c.Description, "desc", c.Description, "Channel description")
|
flag.StringVar(&c.Description, "desc", c.Description, "channel description")
|
||||||
flag.StringVar(&c.Domain, "domain", c.Domain, "domain name")
|
flag.StringVar(&c.Domain, "domain", c.Domain, "domain name")
|
||||||
|
flag.StringVar(&c.FirebaseKey, "firebase", c.FirebaseKey, "Firebase service account key file")
|
||||||
flag.StringVar(&c.KeyFile, "key", c.KeyFile, "key file")
|
flag.StringVar(&c.KeyFile, "key", c.KeyFile, "key file")
|
||||||
flag.StringVar(&c.Link, "link", c.Link, "Channel Link")
|
flag.StringVar(&c.Link, "link", c.Link, "channel Link")
|
||||||
flag.StringVar(&c.LogFile, "log", c.LogFile, "log file")
|
flag.StringVar(&c.LogFile, "log", c.LogFile, "log file")
|
||||||
flag.StringVar(&c.PDFDir, "pdfs", c.PDFDir, "pdf directory")
|
flag.StringVar(&c.PDFDir, "pdfs", c.PDFDir, "pdf directory")
|
||||||
flag.StringVar(&c.PicsDir, "pics", c.PicsDir, "pictures directory")
|
flag.StringVar(&c.PicsDir, "pics", c.PicsDir, "pictures directory")
|
||||||
flag.StringVar(&c.RSSFile, "rss", c.RSSFile, "RSS file")
|
flag.StringVar(&c.RSSFile, "rss", c.RSSFile, "RSS file")
|
||||||
flag.StringVar(&c.Title, "title", c.Title, "Channel title")
|
flag.StringVar(&c.Title, "title", c.Title, "channel title")
|
||||||
flag.StringVar(&c.WebDir, "web", c.WebDir, "web directory")
|
flag.StringVar(&c.WebDir, "web", c.WebDir, "web directory")
|
||||||
flag.IntVar(&port, "port", port, "port")
|
flag.IntVar(&port, "port", port, "port")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
c.FirebaseKey, err = filepath.Abs(c.FirebaseKey)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error finding absolute path for Firebase service account key file: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
c.KeyFile, err = filepath.Abs(c.KeyFile)
|
c.KeyFile, err = filepath.Abs(c.KeyFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error finding absolute path for key file: %v", err)
|
return fmt.Errorf("error finding absolute path for key file: %v", err)
|
||||||
|
@ -12,12 +12,12 @@ type Client struct {
|
|||||||
*auth.Client
|
*auth.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClient() (*Client, error) {
|
func NewClient(c *Config) (*Client, error) {
|
||||||
var err error
|
var err error
|
||||||
client := new(Client)
|
|
||||||
|
|
||||||
|
client := new(Client)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
opt := option.WithCredentialsFile("path/to/serviceAccountKey.json")
|
opt := option.WithCredentialsFile(c.FirebaseKey)
|
||||||
|
|
||||||
app, err := firebase.NewApp(ctx, nil, opt)
|
app, err := firebase.NewApp(ctx, nil, opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -50,11 +50,11 @@ func GetChannel(db *DB, title, link, description string) (*rss.Channel, error) {
|
|||||||
return channel, nil
|
return channel, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenerateRSS(db *DB, title, link, desc string) (*string, error) {
|
func GenerateRSS(c *Config, db *DB) (*string, error) {
|
||||||
channel := &rss.Channel{
|
channel := &rss.Channel{
|
||||||
Title: title,
|
Title: c.Title,
|
||||||
Link: link,
|
Link: c.Link,
|
||||||
Description: desc,
|
Description: c.Description,
|
||||||
Items: make([]*rss.Item, 0),
|
Items: make([]*rss.Item, 0),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,18 +89,13 @@ func GenerateRSS(db *DB, title, link, desc string) (*string, error) {
|
|||||||
return nil, fmt.Errorf("error converting description to plain text for RSS feed: %v", err)
|
return nil, fmt.Errorf("error converting description to plain text for RSS feed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
articleContent, err := ConvertToHTML(article.Content)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("error converting content to HTML for RSS feed: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
channel.Items = append(channel.Items, &rss.Item{
|
channel.Items = append(channel.Items, &rss.Item{
|
||||||
Title: articleTitle,
|
Author: fmt.Sprint(user.FirstName, user.LastName),
|
||||||
Author: user.FirstName + " " + user.LastName,
|
|
||||||
PubDate: article.Created.Format(time.RFC1123Z),
|
|
||||||
Description: articleDescription,
|
|
||||||
Content: &rss.Content{Value: articleContent},
|
|
||||||
Categories: tagNames,
|
Categories: tagNames,
|
||||||
|
Description: articleDescription,
|
||||||
|
Link: fmt.Sprintf("http://%s/article/serve/%d", c.Domain, article.ID),
|
||||||
|
PubDate: article.Created.Format(time.RFC1123Z),
|
||||||
|
Title: articleTitle,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
33
cmd/calls/articles.go
Normal file
33
cmd/calls/articles.go
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package calls
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
b "streifling.com/jason/cpolis/cmd/backend"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ServeArticle(c *b.Config, db *b.DB) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if tokenIsVerified(w, r, c) {
|
||||||
|
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.GetArticle(id)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Fprint(w, article.Content)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
24
cmd/calls/images.go
Normal file
24
cmd/calls/images.go
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package calls
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
b "streifling.com/jason/cpolis/cmd/backend"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ServeImage(c *b.Config, s *b.CookieStore) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if tokenIsVerified(w, r, c) {
|
||||||
|
absFilepath, err := filepath.Abs(c.PicsDir)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
http.ServeFile(w, r, absFilepath+"/"+r.PathValue("pic"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -12,7 +12,7 @@ import (
|
|||||||
|
|
||||||
func ServePDFList(c *b.Config) http.HandlerFunc {
|
func ServePDFList(c *b.Config) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
if tokenIsVerified(w, r) {
|
if tokenIsVerified(w, r, c) {
|
||||||
files, err := os.ReadDir(c.PDFDir)
|
files, err := os.ReadDir(c.PDFDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
@ -37,7 +37,7 @@ func ServePDFList(c *b.Config) http.HandlerFunc {
|
|||||||
|
|
||||||
func ServePDF(c *b.Config) http.HandlerFunc {
|
func ServePDF(c *b.Config) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
if tokenIsVerified(w, r) {
|
if tokenIsVerified(w, r, c) {
|
||||||
http.ServeFile(w, r, fmt.Sprint(c.PDFDir, "/", r.PathValue("id")))
|
http.ServeFile(w, r, fmt.Sprint(c.PDFDir, "/", r.PathValue("id")))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
func ServeRSS(c *b.Config) http.HandlerFunc {
|
func ServeRSS(c *b.Config) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
if tokenIsVerified(w, r) {
|
if tokenIsVerified(w, r, c) {
|
||||||
http.ServeFile(w, r, c.RSSFile)
|
http.ServeFile(w, r, c.RSSFile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// tokenIsVerified verifies that a request is authorized. It returns a bool.
|
// tokenIsVerified verifies that a request is authorized. It returns a bool.
|
||||||
func tokenIsVerified(w http.ResponseWriter, r *http.Request) bool {
|
func tokenIsVerified(w http.ResponseWriter, r *http.Request, c *b.Config) bool {
|
||||||
idToken := r.Header.Get("Authorization")
|
idToken := r.Header.Get("Authorization")
|
||||||
if idToken == "" {
|
if idToken == "" {
|
||||||
log.Println("Authorization header missing")
|
log.Println("Authorization header missing")
|
||||||
@ -16,7 +16,7 @@ func tokenIsVerified(w http.ResponseWriter, r *http.Request) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
client, err := b.NewClient()
|
client, err := b.NewClient(c)
|
||||||
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)
|
||||||
|
@ -23,25 +23,6 @@ const (
|
|||||||
PreviewMode
|
PreviewMode
|
||||||
)
|
)
|
||||||
|
|
||||||
func ShowHub(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
session, err := getSession(w, r, c, s)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
session.Values["article"] = nil
|
|
||||||
if err = session.Save(r, w); err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html")
|
|
||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", session.Values["role"].(int))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func WriteArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
func WriteArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
session, err := getSession(w, r, c, s)
|
session, err := getSession(w, r, c, s)
|
||||||
@ -382,7 +363,7 @@ func PublishArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
feed, err := b.GenerateRSS(db, c.Title, c.Link, c.Description)
|
feed, err := b.GenerateRSS(c, db)
|
||||||
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)
|
||||||
@ -495,3 +476,126 @@ func UploadImage(c *b.Config, s *b.CookieStore) http.HandlerFunc {
|
|||||||
json.NewEncoder(w).Encode(url)
|
json.NewEncoder(w).Encode(url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ShowPublishedArticles(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if _, err := getSession(w, r, c, s); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
publishedArticles, err := db.GetCertainArticles(true, false)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpl, err := template.ParseFiles(c.WebDir + "/templates/published-articles.html")
|
||||||
|
tmpl = template.Must(tmpl, err)
|
||||||
|
tmpl.ExecuteTemplate(w, "page-content", publishedArticles)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ReviewArticleForDeletion(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if _, err := getSession(w, r, c, s); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
type htmlData struct {
|
||||||
|
Title string
|
||||||
|
Description string
|
||||||
|
Content template.HTML
|
||||||
|
Tags []*b.Tag
|
||||||
|
ID int64
|
||||||
|
}
|
||||||
|
|
||||||
|
var err error
|
||||||
|
data := new(htmlData)
|
||||||
|
|
||||||
|
data.ID, err = strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
article, err := db.GetArticle(data.ID)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
data.Title, err = b.ConvertToPlain(article.Title)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
data.Description, err = b.ConvertToPlain(article.Description)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
content, err := b.ConvertToHTML(article.Content)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
data.Content = template.HTML(content)
|
||||||
|
|
||||||
|
data.Tags, err = db.GetArticleTags(data.ID)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpl, err := template.ParseFiles(c.WebDir + "/templates/to-be-deleted.html")
|
||||||
|
tmpl = template.Must(tmpl, err)
|
||||||
|
tmpl.ExecuteTemplate(w, "page-content", data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func DeleteArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
session, err := getSession(w, r, c, s)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
feed, err := b.GenerateRSS(c, db)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = b.SaveRSS(c.RSSFile, feed); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html")
|
||||||
|
tmpl = template.Must(tmpl, err)
|
||||||
|
tmpl.ExecuteTemplate(w, "page-content", session.Values["role"].(int))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,26 +0,0 @@
|
|||||||
package frontend
|
|
||||||
|
|
||||||
import (
|
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
"path/filepath"
|
|
||||||
|
|
||||||
b "streifling.com/jason/cpolis/cmd/backend"
|
|
||||||
)
|
|
||||||
|
|
||||||
func ServeImage(c *b.Config, s *b.CookieStore) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
if _, err := getSession(w, r, c, s); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
absFilepath, err := filepath.Abs(c.PicsDir)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
http.ServeFile(w, r, absFilepath+"/"+r.PathValue("pic"))
|
|
||||||
}
|
|
||||||
}
|
|
@ -107,3 +107,22 @@ func Logout(c *b.Config, s *b.CookieStore) http.HandlerFunc {
|
|||||||
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", nil)
|
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ShowHub(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
session, err := getSession(w, r, c, s)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
session.Values["article"] = nil
|
||||||
|
if err = session.Save(r, w); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html")
|
||||||
|
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", session.Values["role"].(int))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
58
cmd/main.go
58
cmd/main.go
@ -49,38 +49,42 @@ func main() {
|
|||||||
http.FileServer(http.Dir(config.WebDir+"/static/"))))
|
http.FileServer(http.Dir(config.WebDir+"/static/"))))
|
||||||
mux.HandleFunc("/", f.HomePage(config, db, store))
|
mux.HandleFunc("/", f.HomePage(config, db, store))
|
||||||
|
|
||||||
mux.HandleFunc("GET /create-tag", f.CreateTag(config, store))
|
mux.HandleFunc("GET /article/all-published", f.ShowPublishedArticles(config, db, store))
|
||||||
mux.HandleFunc("GET /create-user", f.CreateUser(config, store))
|
mux.HandleFunc("GET /article/all-rejected", f.ShowRejectedArticles(config, db, store))
|
||||||
mux.HandleFunc("GET /edit-self", f.EditSelf(config, db, store))
|
mux.HandleFunc("GET /article/all-unpublished", f.ShowUnpublishedArticles(config, db, store))
|
||||||
mux.HandleFunc("GET /edit-user/{id}", f.EditUser(config, db, store))
|
mux.HandleFunc("GET /article/delete/{id}", f.DeleteArticle(config, db, store))
|
||||||
mux.HandleFunc("GET /delete-user/{id}", f.DeleteUser(config, db, store))
|
mux.HandleFunc("GET /article/publish/{id}", f.PublishArticle(config, db, store))
|
||||||
|
mux.HandleFunc("GET /article/reject/{id}", f.RejectArticle(config, db, store))
|
||||||
|
mux.HandleFunc("GET /article/review-deletion/{id}", f.ReviewArticleForDeletion(config, db, store))
|
||||||
|
mux.HandleFunc("GET /article/review-rejected/{id}", f.ReviewRejectedArticle(config, db, store))
|
||||||
|
mux.HandleFunc("GET /article/review-unpublished/{id}", f.ReviewUnpublishedArticle(config, db, store))
|
||||||
|
mux.HandleFunc("GET /article/serve/{id}", c.ServeArticle(config, db))
|
||||||
|
mux.HandleFunc("GET /article/write", f.WriteArticle(config, db, store))
|
||||||
mux.HandleFunc("GET /hub", f.ShowHub(config, db, store))
|
mux.HandleFunc("GET /hub", f.ShowHub(config, db, store))
|
||||||
|
mux.HandleFunc("GET /image/serve/{pic}", c.ServeImage(config, store))
|
||||||
|
mux.HandleFunc("GET /issue/publish", f.PublishLatestIssue(config, db, store))
|
||||||
|
mux.HandleFunc("GET /issue/this", f.ShowCurrentArticles(config, db, store))
|
||||||
mux.HandleFunc("GET /logout", f.Logout(config, store))
|
mux.HandleFunc("GET /logout", f.Logout(config, store))
|
||||||
mux.HandleFunc("GET /pdf/get-list", c.ServePDFList(config))
|
mux.HandleFunc("GET /pdf/get-list", c.ServePDFList(config))
|
||||||
mux.HandleFunc("GET /pdf/{id}", c.ServePDF(config))
|
mux.HandleFunc("GET /pdf/serve/{id}", c.ServePDF(config))
|
||||||
mux.HandleFunc("GET /pics/{pic}", f.ServeImage(config, store))
|
mux.HandleFunc("GET /rss/serve", c.ServeRSS(config))
|
||||||
mux.HandleFunc("GET /publish-article/{id}", f.PublishArticle(config, db, store))
|
mux.HandleFunc("GET /tag/create", f.CreateTag(config, store))
|
||||||
mux.HandleFunc("GET /publish-issue", f.PublishLatestIssue(config, db, store))
|
mux.HandleFunc("GET /user/create", f.CreateUser(config, store))
|
||||||
mux.HandleFunc("GET /reject-article/{id}", f.RejectArticle(config, db, store))
|
mux.HandleFunc("GET /user/delete/{id}", f.DeleteUser(config, db, store))
|
||||||
mux.HandleFunc("GET /rejected-articles", f.ShowRejectedArticles(config, db, store))
|
mux.HandleFunc("GET /user/edit/{id}", f.EditUser(config, db, store))
|
||||||
mux.HandleFunc("GET /review-rejected-article/{id}", f.ReviewRejectedArticle(config, db, store))
|
mux.HandleFunc("GET /user/edit/self", f.EditSelf(config, db, store))
|
||||||
mux.HandleFunc("GET /review-unpublished-article/{id}", f.ReviewUnpublishedArticle(config, db, store))
|
mux.HandleFunc("GET /user/show-all/delete", f.ShowAllUsers(config, db, store, "delete"))
|
||||||
mux.HandleFunc("GET /rss", c.ServeRSS(config))
|
mux.HandleFunc("GET /user/show-all/edit", f.ShowAllUsers(config, db, store, "edit"))
|
||||||
mux.HandleFunc("GET /show-all-users-edit", f.ShowAllUsers(config, db, store, "edit-user"))
|
|
||||||
mux.HandleFunc("GET /show-all-users-delete", f.ShowAllUsers(config, db, store, "delete-user"))
|
|
||||||
mux.HandleFunc("GET /this-issue", f.ShowCurrentArticles(config, db, store))
|
|
||||||
mux.HandleFunc("GET /unpublished-articles", f.ShowUnpublishedArticles(config, db, store))
|
|
||||||
mux.HandleFunc("GET /write-article", f.WriteArticle(config, db, store))
|
|
||||||
|
|
||||||
mux.HandleFunc("POST /add-first-user", f.AddFirstUser(config, db, store))
|
mux.HandleFunc("POST /article/resubmit/{id}", f.ResubmitArticle(config, db, store))
|
||||||
mux.HandleFunc("POST /add-tag", f.AddTag(config, db, store))
|
mux.HandleFunc("POST /article/submit", f.SubmitArticle(config, db, store))
|
||||||
mux.HandleFunc("POST /add-user", f.AddUser(config, db, store))
|
mux.HandleFunc("POST /image/upload", f.UploadImage(config, store))
|
||||||
mux.HandleFunc("POST /login", f.Login(config, db, store))
|
mux.HandleFunc("POST /login", f.Login(config, db, store))
|
||||||
mux.HandleFunc("POST /resubmit-article/{id}", f.ResubmitArticle(config, db, store))
|
mux.HandleFunc("POST /tag/add", f.AddTag(config, db, store))
|
||||||
mux.HandleFunc("POST /submit-article", f.SubmitArticle(config, db, store))
|
mux.HandleFunc("POST /user/add", f.AddUser(config, db, store))
|
||||||
mux.HandleFunc("POST /update-self", f.UpdateSelf(config, db, store))
|
mux.HandleFunc("POST /user/add-first", f.AddFirstUser(config, db, store))
|
||||||
mux.HandleFunc("POST /update-user/{id}", f.UpdateUser(config, db, store))
|
mux.HandleFunc("POST /user/update/{id}", f.UpdateUser(config, db, store))
|
||||||
mux.HandleFunc("POST /upload-image", f.UploadImage(config, store))
|
mux.HandleFunc("POST /user/update/self", f.UpdateSelf(config, db, store))
|
||||||
|
|
||||||
log.Fatalln(http.ListenAndServe(config.Port, mux))
|
log.Fatalln(http.ListenAndServe(config.Port, mux))
|
||||||
}
|
}
|
||||||
|
9
cpolis.service
Normal file
9
cpolis.service
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=cpolis
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
ExecStart=/usr/local/bin/cpolis
|
||||||
|
Restart=on-failure
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=default.target
|
@ -11,13 +11,13 @@ CREATE TABLE users (
|
|||||||
first_name VARCHAR(50) NOT NULL,
|
first_name VARCHAR(50) NOT NULL,
|
||||||
last_name VARCHAR(50) NOT NULL,
|
last_name VARCHAR(50) NOT NULL,
|
||||||
role INT NOT NULL,
|
role INT NOT NULL,
|
||||||
PRIMARY KEY(id)
|
PRIMARY KEY (id)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE issues (
|
CREATE TABLE issues (
|
||||||
id INT AUTO_INCREMENT,
|
id INT AUTO_INCREMENT,
|
||||||
published BOOL NOT NULL,
|
published BOOL NOT NULL,
|
||||||
PRIMARY KEY(id)
|
PRIMARY KEY (id)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE articles (
|
CREATE TABLE articles (
|
||||||
@ -30,21 +30,21 @@ CREATE TABLE articles (
|
|||||||
rejected BOOL NOT NULL,
|
rejected BOOL NOT NULL,
|
||||||
author_id INT NOT NULL,
|
author_id INT NOT NULL,
|
||||||
issue_id INT NOT NULL,
|
issue_id INT NOT NULL,
|
||||||
PRIMARY KEY(id),
|
PRIMARY KEY (id),
|
||||||
FOREIGN KEY(author_id) REFERENCES users(id),
|
FOREIGN KEY (author_id) REFERENCES users (id),
|
||||||
FOREIGN KEY(issue_id) REFERENCES issues(id)
|
FOREIGN KEY (issue_id) REFERENCES issues (id)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE tags (
|
CREATE TABLE tags (
|
||||||
id INT AUTO_INCREMENT,
|
id INT AUTO_INCREMENT,
|
||||||
name VARCHAR(50) NOT NULL UNIQUE,
|
name VARCHAR(50) NOT NULL UNIQUE,
|
||||||
PRIMARY KEY(id)
|
PRIMARY KEY (id)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE articles_tags (
|
CREATE TABLE articles_tags (
|
||||||
article_id INT,
|
article_id INT,
|
||||||
tag_id INT,
|
tag_id INT,
|
||||||
PRIMARY KEY(article_id, tag_id),
|
PRIMARY KEY (article_id, tag_id),
|
||||||
FOREIGN KEY(article_id) REFERENCES articles(id),
|
FOREIGN KEY (article_id) REFERENCES articles (id),
|
||||||
FOREIGN KEY(tag_id) REFERENCES tags(id)
|
FOREIGN KEY (tag_id) REFERENCES tags (id)
|
||||||
);
|
);
|
||||||
|
56
update.sh
Executable file
56
update.sh
Executable file
@ -0,0 +1,56 @@
|
|||||||
|
#! /bin/sh -
|
||||||
|
|
||||||
|
CPOLIS_REPO_URL="https://git.streifling.com/api/v1/repos/jason/cpolis/releases"
|
||||||
|
EXTRACTION_DIR=$HOME
|
||||||
|
CPOLIS_DIR=$EXTRACTION_DIR/cpolis
|
||||||
|
TAILWINDCSS_REPO_URL=https://api.github.com/repos/tailwindlabs/tailwindcss/releases/latest
|
||||||
|
TMP_DIR=/tmp
|
||||||
|
BIN_DIR=/usr/local/bin
|
||||||
|
SYSTEMD_DIR=/etc/systemd/system
|
||||||
|
|
||||||
|
check_dependency() {
|
||||||
|
if ! which $1 >/dev/null 2>&1; then
|
||||||
|
echo "$1 needs to be installed" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
if ! groups | grep -E 'root|wheel|sudo' >/dev/null; then
|
||||||
|
echo "You need administrative privileges for this script" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
check_dependency curl
|
||||||
|
check_dependency go
|
||||||
|
check_dependency jq
|
||||||
|
check_dependency tar
|
||||||
|
check_dependency xargs
|
||||||
|
|
||||||
|
echo '\nDownloading cpolis...' >&2
|
||||||
|
rm -fr $CPOLIS_DIR/*
|
||||||
|
latest_release=$(curl -s $CPOLIS_REPO_URL | jq -r '.[0].tag_name')
|
||||||
|
curl -Lo $TMP_DIR/cpolis.tar.gz https://git.streifling.com/jason/cpolis/archive/$latest_release.tar.gz
|
||||||
|
tar -xzf $TMP_DIR/cpolis.tar.gz -C $EXTRACTION_DIR
|
||||||
|
rm $TMP_DIR/cpolis.tar.gz
|
||||||
|
|
||||||
|
echo '\nDownloading TailwindCSS...' >&2
|
||||||
|
curl -s $TAILWINDCSS_REPO_URL |
|
||||||
|
grep -F browser_download_url |
|
||||||
|
grep -F linux-x64 |
|
||||||
|
cut -d'"' -f4 |
|
||||||
|
xargs -r curl -Lo $CPOLIS_DIR/tailwindcss
|
||||||
|
chmod +x $CPOLIS_DIR/tailwindcss
|
||||||
|
$CPOLIS_DIR/tailwindcss -i $CPOLIS_DIR/web/static/css/input.css -o $CPOLIS_DIR/web/static/css/style.css
|
||||||
|
|
||||||
|
echo '\nBuilding cpolis...' >&2
|
||||||
|
go build -o $TMP_DIR/cpolis $CPOLIS_DIR/cmd/main.go
|
||||||
|
|
||||||
|
echo '\nSetting system files up...' >&2
|
||||||
|
sudo mv $TMP_DIR/cpolis $BIN_DIR/cpolis
|
||||||
|
sudo chown root:root $BIN_DIR/cpolis
|
||||||
|
chmod +x $BIN_DIR/cpolis
|
||||||
|
|
||||||
|
sudo mv $CPOLIS_DIR/cpolis.service $SYSTEMD_DIR
|
||||||
|
sudo chown root:root $SYSTEMD_DIR/cpolis.service
|
||||||
|
sudo systemctl daemon-reload
|
||||||
|
sudo systemctl is-active --quiet cpolis.service && sudo systemctl restart cpolis.service
|
@ -4,7 +4,7 @@
|
|||||||
<form>
|
<form>
|
||||||
<input required name="tag" placeholder="Tag eingeben" type="text" />
|
<input required name="tag" placeholder="Tag eingeben" type="text" />
|
||||||
<div class="btn-area">
|
<div class="btn-area">
|
||||||
<input class="action-btn" type="submit" value="Anlegen" hx-post="/add-tag" hx-target="#page-content" />
|
<input class="action-btn" type="submit" value="Anlegen" hx-post="/tag/add" hx-target="#page-content" />
|
||||||
<button class="btn" hx-get="/hub" hx-target="#page-content">Abbrechen</button>
|
<button class="btn" hx-get="/hub" hx-target="#page-content">Abbrechen</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
@ -45,7 +45,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="btn-area">
|
<div class="btn-area">
|
||||||
<input class="action-btn" type="submit" value="Anlegen" hx-post="/add-user" hx-target="#page-content" />
|
<input class="action-btn" type="submit" value="Anlegen" hx-post="/user/add" hx-target="#page-content" />
|
||||||
<button class="btn" hx-get="/hub" hx-target="#page-content">Abbrechen</button>
|
<button class="btn" hx-get="/hub" hx-target="#page-content">Abbrechen</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="btn-area">
|
<div class="btn-area">
|
||||||
<button class="action-btn" hx-get="/publish-issue" hx-target="#page-content">Ausgabe publizieren</button>
|
<button class="action-btn" hx-get="/issue/publish" hx-target="#page-content">Ausgabe publizieren</button>
|
||||||
<button class="btn" hx-get="/hub" hx-target="#page-content">Abbrechen</button>
|
<button class="btn" hx-get="/hub" hx-target="#page-content">Abbrechen</button>
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="btn-area">
|
<div class="btn-area">
|
||||||
<input class="action-btn" type="submit" value="Aktualisieren" hx-post="/update-self"
|
<input class="action-btn" type="submit" value="Aktualisieren" hx-post="/user/update/self"
|
||||||
hx-target="#page-content" />
|
hx-target="#page-content" />
|
||||||
<button class="btn" hx-get="/hub" hx-target="#page-content">Abbrechen</button>
|
<button class="btn" hx-get="/hub" hx-target="#page-content">Abbrechen</button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -49,7 +49,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="btn-area">
|
<div class="btn-area">
|
||||||
<input class="action-btn" type="submit" value="Aktualisieren" hx-post="/update-user/{{.ID}}"
|
<input class="action-btn" type="submit" value="Aktualisieren" hx-post="/user/update/{{.ID}}"
|
||||||
hx-target="#page-content" />
|
hx-target="#page-content" />
|
||||||
<button class="btn" hx-get="/hub" hx-target="#page-content">Abbrechen</button>
|
<button class="btn" hx-get="/hub" hx-target="#page-content">Abbrechen</button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="btn-area">
|
<div class="btn-area">
|
||||||
<input class="action-btn" type="submit" value="Senden" hx-post="/submit-article" hx-target="#page-content" />
|
<input class="action-btn" type="submit" value="Senden" hx-post="/article/submit" hx-target="#page-content" />
|
||||||
<button class="btn" hx-get="/hub" hx-target="#page-content">Abbrechen</button>
|
<button class="btn" hx-get="/hub" hx-target="#page-content">Abbrechen</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
@ -46,7 +46,7 @@
|
|||||||
var formData = new FormData();
|
var formData = new FormData();
|
||||||
formData.append('article-image', file);
|
formData.append('article-image', file);
|
||||||
|
|
||||||
fetch('/upload-image', {
|
fetch('/image/upload', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: formData
|
body: formData
|
||||||
})
|
})
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="btn-area">
|
<div class="btn-area">
|
||||||
<input class="action-btn" type="submit" value="Anlegen" hx-post="/add-first-user" hx-target="#page-content" />
|
<input class="action-btn" type="submit" value="Anlegen" hx-post="/user/add-first" hx-target="#page-content" />
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
@ -6,10 +6,9 @@
|
|||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<h2>Autor</h2>
|
<h2>Autor</h2>
|
||||||
<div class="grid grid-cols-2 gap-x-4 gap-y-2">
|
<div class="grid grid-cols-2 gap-x-4 gap-y-2">
|
||||||
<button class="btn" hx-get="/write-article" hx-target="#page-content">Artikel schreiben</button>
|
<button class="btn" hx-get="/article/write" hx-target="#page-content">Artikel schreiben</button>
|
||||||
<button class="btn" hx-get="/rejected-articles" hx-target="#page-content">Abgelehnte Artikel</button>
|
<button class="btn" hx-get="/article/all-rejected" hx-target="#page-content">Abgelehnte Artikel</button>
|
||||||
<a class="btn text-center" href="/rss">RSS Feed</a>
|
<button class="btn" hx-get="/user/edit/self" hx-target="#page-content">Profil bearbeiten</button>
|
||||||
<button class="btn" hx-get="/edit-self" hx-target="#page-content">Profil bearbeiten</button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
@ -18,10 +17,10 @@
|
|||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<h2>Redakteur</h2>
|
<h2>Redakteur</h2>
|
||||||
<div class="grid grid-cols-2 gap-4">
|
<div class="grid grid-cols-2 gap-4">
|
||||||
<button class="btn" hx-get="/unpublished-articles" hx-target="#page-content">
|
<button class="btn" hx-get="/article/all-unpublished" hx-target="#page-content">
|
||||||
Unveröffentlichte Artikel
|
Unveröffentlichte Artikel
|
||||||
</button>
|
</button>
|
||||||
<button class="btn" hx-get="/create-tag" hx-target="#page-content">Neuer Tag</button>
|
<button class="btn" hx-get="/tag/create" hx-target="#page-content">Neuer Tag</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
@ -30,7 +29,8 @@
|
|||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<h2>Herausgeber</h2>
|
<h2>Herausgeber</h2>
|
||||||
<div class="grid grid-cols-2 gap-4">
|
<div class="grid grid-cols-2 gap-4">
|
||||||
<button class="btn" hx-get="/this-issue" hx-target="#page-content">Diese Ausgabe</button>
|
<button class="btn" hx-get="/issue/this" hx-target="#page-content">Diese Ausgabe</button>
|
||||||
|
<button class="btn" hx-get="/article/all-published" hx-target="#page-content">Artikel löschen</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
@ -38,10 +38,10 @@
|
|||||||
{{if eq . 0}}
|
{{if eq . 0}}
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<h2>Administrator</h2>
|
<h2>Administrator</h2>
|
||||||
<div class="grid grid-cols-3 gap-4">
|
<div class="grid grid-cols-2 gap-4">
|
||||||
<button class="btn" hx-get="/create-user" hx-target="#page-content">Benutzer hinzufügen</button>
|
<button class="btn" hx-get="/user/create" hx-target="#page-content">Benutzer hinzufügen</button>
|
||||||
<button class="btn" hx-get="/show-all-users-edit" hx-target="#page-content">Benutzer bearbeiten</button>
|
<button class="btn" hx-get="/user/show-all/edit" hx-target="#page-content">Benutzer bearbeiten</button>
|
||||||
<button class="btn" hx-get="/show-all-users-delete" hx-target="#page-content">Benutzer löschen</button>
|
<button class="btn" hx-get="/user/show-all/delete" hx-target="#page-content">Benutzer löschen</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
13
web/templates/published-articles.html
Normal file
13
web/templates/published-articles.html
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{{define "page-content"}}
|
||||||
|
<h2>Artikel löschen</h2>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-4">
|
||||||
|
{{range .}}
|
||||||
|
<button class="btn" hx-get="/article/review-deletion/{{.ID}}" hx-target="#page-content">
|
||||||
|
<h1 class="font-bold text-2xl">{{.Title}}</h1>
|
||||||
|
<p>{{.Description}}</p>
|
||||||
|
</button>
|
||||||
|
{{end}}
|
||||||
|
<button class="action-btn" hx-get="/hub" hx-target="#page-content">Zurück</button>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
@ -4,7 +4,7 @@
|
|||||||
<div class="flex flex-col gap-4">
|
<div class="flex flex-col gap-4">
|
||||||
{{range .RejectedArticles}}
|
{{range .RejectedArticles}}
|
||||||
{{if index $.MyIDs .ID}}
|
{{if index $.MyIDs .ID}}
|
||||||
<button class="btn" hx-get="/review-rejected-article/{{.ID}}" hx-target="#page-content">
|
<button class="btn" hx-get="/article/review-rejected/{{.ID}}" hx-target="#page-content">
|
||||||
<h1 class="font-bold text-2xl">{{.Title}}</h1>
|
<h1 class="font-bold text-2xl">{{.Title}}</h1>
|
||||||
<p>{{.Description}}</p>
|
<p>{{.Description}}</p>
|
||||||
</button>
|
</button>
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="btn-area">
|
<div class="btn-area">
|
||||||
<input class="action-btn" type="submit" value="Senden" hx-post="/resubmit-article/{{.Article.ID}}"
|
<input class="action-btn" type="submit" value="Senden" hx-post="/article/resubmit/{{.Article.ID}}"
|
||||||
hx-target="#page-content" />
|
hx-target="#page-content" />
|
||||||
<button class="btn" hx-get="/hub" hx-target="#page-content">Zurück</button>
|
<button class="btn" hx-get="/hub" hx-target="#page-content">Zurück</button>
|
||||||
</div>
|
</div>
|
||||||
@ -48,7 +48,7 @@
|
|||||||
var formData = new FormData();
|
var formData = new FormData();
|
||||||
formData.append('article-image', file);
|
formData.append('article-image', file);
|
||||||
|
|
||||||
fetch('/upload-image', {
|
fetch('/image/upload', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: formData
|
body: formData
|
||||||
})
|
})
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
<div class="flex flex-col gap-4">
|
<div class="flex flex-col gap-4">
|
||||||
{{range .Users}}
|
{{range .Users}}
|
||||||
<button class="btn" hx-get="/{{$.Action}}/{{.ID}}" hx-target="#page-content">
|
<button class="btn" hx-get="/user/{{$.Action}}/{{.ID}}" hx-target="#page-content">
|
||||||
<h1 class="font-bold text-2xl">
|
<h1 class="font-bold text-2xl">
|
||||||
{{.UserName}}
|
{{.UserName}}
|
||||||
({{if eq .Role 0}}
|
({{if eq .Role 0}}
|
||||||
|
36
web/templates/to-be-deleted.html
Normal file
36
web/templates/to-be-deleted.html
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
{{define "page-content"}}
|
||||||
|
<h2>Artikel löschen</h2>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<span>Titel</span>
|
||||||
|
<div class="bg-white border mb-3 px-2 py-2 rounded-md w-full">
|
||||||
|
{{.Title}}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<span>Beschreibung</span>
|
||||||
|
<div class="bg-white border mb-3 px-2 py-2 rounded-md w-full">
|
||||||
|
{{.Description}}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<span>Artikel</span>
|
||||||
|
<div class="bg-white border mb-3 px-2 py-2 rounded-md w-full">
|
||||||
|
<div class="prose">
|
||||||
|
{{.Content}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<span>Tags</span>
|
||||||
|
<div class="bg-white border mb-3 px-2 py-2 rounded-md w-full">
|
||||||
|
{{range .Tags}}
|
||||||
|
{{.Name}}
|
||||||
|
<br>
|
||||||
|
{{end}}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="btn-area">
|
||||||
|
<input class="action-btn" type="submit" value="Löschen" hx-get="/article/delete/{{.ID}}"
|
||||||
|
hx-target="#page-content" />
|
||||||
|
<button class="btn" hx-get="/hub" hx-target="#page-content">Zurück</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
@ -28,9 +28,9 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="btn-area">
|
<div class="btn-area">
|
||||||
<input class="action-btn" type="submit" value="Veröffentlichen" hx-get="/publish-article/{{.ID}}"
|
<input class="action-btn" type="submit" value="Veröffentlichen" hx-get="/article/publish/{{.ID}}"
|
||||||
hx-target="#page-content" />
|
hx-target="#page-content" />
|
||||||
<input class="btn" type="submit" value="Ablehnen" hx-get="/reject-article/{{.ID}}" hx-target="#page-content" />
|
<input class="btn" type="submit" value="Ablehnen" hx-get="/article/reject/{{.ID}}" hx-target="#page-content" />
|
||||||
<button class="btn" hx-get="/hub" hx-target="#page-content">Zurück</button>
|
<button class="btn" hx-get="/hub" hx-target="#page-content">Zurück</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
<div class="flex flex-col gap-4">
|
<div class="flex flex-col gap-4">
|
||||||
{{range .}}
|
{{range .}}
|
||||||
<button class="btn" hx-get="/review-unpublished-article/{{.ID}}" hx-target="#page-content">
|
<button class="btn" hx-get="/article/review-unpublished/{{.ID}}" hx-target="#page-content">
|
||||||
<h1 class="font-bold text-2xl">{{.Title}}</h1>
|
<h1 class="font-bold text-2xl">{{.Title}}</h1>
|
||||||
<p>{{.Description}}</p>
|
<p>{{.Description}}</p>
|
||||||
</button>
|
</button>
|
||||||
|
Reference in New Issue
Block a user