2024-02-18 07:20:51 +01:00
|
|
|
package main
|
|
|
|
|
2024-02-18 10:07:49 +01:00
|
|
|
import (
|
2024-03-03 09:16:49 +01:00
|
|
|
"encoding/gob"
|
2024-02-18 10:07:49 +01:00
|
|
|
"log"
|
|
|
|
"net/http"
|
2024-02-24 11:41:01 +01:00
|
|
|
"os"
|
2024-02-18 10:07:49 +01:00
|
|
|
|
2024-07-13 14:09:11 +02:00
|
|
|
b "streifling.com/jason/cpolis/cmd/backend"
|
2024-08-18 11:20:06 +02:00
|
|
|
c "streifling.com/jason/cpolis/cmd/calls"
|
2024-07-13 14:09:11 +02:00
|
|
|
f "streifling.com/jason/cpolis/cmd/frontend"
|
2024-02-18 10:07:49 +01:00
|
|
|
)
|
2024-02-18 07:20:51 +01:00
|
|
|
|
2024-03-03 09:16:49 +01:00
|
|
|
func init() {
|
2024-07-13 14:09:11 +02:00
|
|
|
gob.Register(b.User{})
|
2024-03-03 09:16:49 +01:00
|
|
|
}
|
|
|
|
|
2024-02-18 07:20:51 +01:00
|
|
|
func main() {
|
2024-07-13 14:09:11 +02:00
|
|
|
config, err := b.HandleConfig()
|
2024-03-29 09:07:17 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
|
2024-04-12 07:17:13 +02:00
|
|
|
logFile, err := os.OpenFile(config.LogFile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
|
2024-02-24 11:41:01 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
defer logFile.Close()
|
2024-03-29 09:07:17 +01:00
|
|
|
log.SetOutput(logFile)
|
2024-02-24 11:41:01 +01:00
|
|
|
|
2024-07-13 14:09:11 +02:00
|
|
|
db, err := b.OpenDB(config.DBName)
|
2024-02-18 16:37:13 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
2024-02-22 19:27:41 +01:00
|
|
|
defer db.Close()
|
2024-02-18 16:37:13 +01:00
|
|
|
|
2024-10-27 13:29:46 +01:00
|
|
|
key, err := b.LoadKey(config.GOBKeyFile)
|
2024-03-03 09:16:49 +01:00
|
|
|
if err != nil {
|
2024-07-13 14:09:11 +02:00
|
|
|
key, err = b.NewKey()
|
2024-03-03 09:16:49 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
2024-10-27 13:29:46 +01:00
|
|
|
if err = b.SaveKey(key, config.GOBKeyFile); err != nil {
|
2024-10-27 07:20:23 +01:00
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
2024-03-03 09:16:49 +01:00
|
|
|
}
|
2024-07-13 14:09:11 +02:00
|
|
|
store := b.NewCookieStore(key)
|
2024-03-03 09:16:49 +01:00
|
|
|
|
2024-02-18 14:31:28 +01:00
|
|
|
mux := http.NewServeMux()
|
2024-03-07 15:31:00 +01:00
|
|
|
mux.Handle("/web/static/", http.StripPrefix("/web/static/",
|
2024-04-12 07:17:13 +02:00
|
|
|
http.FileServer(http.Dir(config.WebDir+"/static/"))))
|
2024-07-13 14:09:11 +02:00
|
|
|
mux.HandleFunc("/", f.HomePage(config, db, store))
|
2024-02-24 10:56:12 +01:00
|
|
|
|
2024-09-28 12:17:03 +02:00
|
|
|
mux.HandleFunc("GET /article/allow-edit/{id}", f.AllowEditArticle(config, db, store))
|
|
|
|
mux.HandleFunc("GET /article/all-published/review-edit", f.ShowPublishedArticles(config, db, store, "review-edit"))
|
|
|
|
mux.HandleFunc("GET /article/all-published/delete", f.ShowPublishedArticles(config, db, store, "review-delete"))
|
2024-08-30 15:42:53 +02:00
|
|
|
mux.HandleFunc("GET /article/all-rejected", f.ShowRejectedArticles(config, db, store))
|
2024-09-28 12:17:03 +02:00
|
|
|
mux.HandleFunc("GET /article/all-unpublished-unrejected-and-published-rejected", f.ShowUnpublishedUnrejectedAndPublishedRejectedArticles(config, db, store))
|
2024-08-30 15:42:53 +02:00
|
|
|
mux.HandleFunc("GET /article/delete/{id}", f.DeleteArticle(config, db, store))
|
2024-09-28 12:17:03 +02:00
|
|
|
mux.HandleFunc("GET /article/edit/{id}", f.EditArticle(config, db, store))
|
2024-08-30 15:42:53 +02:00
|
|
|
mux.HandleFunc("GET /article/publish/{id}", f.PublishArticle(config, db, store))
|
|
|
|
mux.HandleFunc("GET /article/reject/{id}", f.RejectArticle(config, db, store))
|
2024-09-28 12:17:03 +02:00
|
|
|
mux.HandleFunc("GET /article/review-delete/{id}", f.ReviewArticle(config, db, store, "delete", "Artikel löschen", "Löschen"))
|
|
|
|
mux.HandleFunc("GET /article/review-edit/{id}", f.ReviewArticle(config, db, store, "allow-edit", "Artikel bearbeiten", "Bearbeiten erlauben"))
|
2024-08-30 15:42:53 +02:00
|
|
|
mux.HandleFunc("GET /article/review-rejected/{id}", f.ReviewRejectedArticle(config, db, store))
|
2024-09-28 12:17:03 +02:00
|
|
|
mux.HandleFunc("GET /article/review-unpublished/{id}", f.ReviewArticle(config, db, store, "publish", "Artikel veröffentlichen", "Veröffentlichen"))
|
2024-08-30 15:17:14 +02:00
|
|
|
mux.HandleFunc("GET /article/serve/{id}", c.ServeArticle(config, db))
|
2024-12-27 11:09:36 +01:00
|
|
|
mux.HandleFunc("GET /article/serve/{id}/clicks", c.ServeClicks(db))
|
2024-08-30 15:42:53 +02:00
|
|
|
mux.HandleFunc("GET /article/write", f.WriteArticle(config, db, store))
|
2024-10-27 15:12:30 +01:00
|
|
|
mux.HandleFunc("GET /atom/serve", c.ServeAtomFeed(config))
|
2024-07-13 14:09:11 +02:00
|
|
|
mux.HandleFunc("GET /hub", f.ShowHub(config, db, store))
|
2024-10-30 03:24:29 +01:00
|
|
|
mux.HandleFunc("GET /image/serve/{pic}", c.ServeImage(config, store))
|
2024-10-27 07:21:36 +01:00
|
|
|
mux.HandleFunc("GET /issue/this", f.ShowCurrentIssue(config, db, store))
|
2024-07-13 14:09:11 +02:00
|
|
|
mux.HandleFunc("GET /logout", f.Logout(config, store))
|
2024-08-18 11:20:06 +02:00
|
|
|
mux.HandleFunc("GET /pdf/get-list", c.ServePDFList(config))
|
2024-08-30 15:42:53 +02:00
|
|
|
mux.HandleFunc("GET /pdf/serve/{id}", c.ServePDF(config))
|
|
|
|
mux.HandleFunc("GET /tag/create", f.CreateTag(config, store))
|
|
|
|
mux.HandleFunc("GET /user/create", f.CreateUser(config, store))
|
|
|
|
mux.HandleFunc("GET /user/delete/{id}", f.DeleteUser(config, db, store))
|
|
|
|
mux.HandleFunc("GET /user/edit/{id}", f.EditUser(config, db, store))
|
|
|
|
mux.HandleFunc("GET /user/edit/self", f.EditSelf(config, db, store))
|
2024-08-30 15:58:09 +02:00
|
|
|
mux.HandleFunc("GET /user/show-all/delete", f.ShowAllUsers(config, db, store, "delete"))
|
|
|
|
mux.HandleFunc("GET /user/show-all/edit", f.ShowAllUsers(config, db, store, "edit"))
|
2024-03-01 11:30:31 +01:00
|
|
|
|
2024-08-30 15:42:53 +02:00
|
|
|
mux.HandleFunc("POST /article/resubmit/{id}", f.ResubmitArticle(config, db, store))
|
|
|
|
mux.HandleFunc("POST /article/submit", f.SubmitArticle(config, db, store))
|
2024-11-01 16:31:47 +01:00
|
|
|
mux.HandleFunc("POST /article/upload-banner", f.UploadImage(config, store, "article-banner", "editor.html", "article-banner-template"))
|
|
|
|
mux.HandleFunc("POST /article/upload-image", f.UploadEasyMDEImage(config, store))
|
2024-08-30 21:20:29 +02:00
|
|
|
mux.HandleFunc("POST /issue/publish", f.PublishLatestIssue(config, db, store))
|
2024-11-01 16:31:47 +01:00
|
|
|
mux.HandleFunc("POST /issue/upload-banner", f.UploadImage(config, store, "issue-banner", "current-issue.html", "issue-banner-template"))
|
2024-07-13 14:09:11 +02:00
|
|
|
mux.HandleFunc("POST /login", f.Login(config, db, store))
|
2024-09-01 18:16:26 +02:00
|
|
|
mux.HandleFunc("POST /pdf/upload", f.UploadPDF(config, store))
|
2024-08-30 15:42:53 +02:00
|
|
|
mux.HandleFunc("POST /tag/add", f.AddTag(config, db, store))
|
|
|
|
mux.HandleFunc("POST /user/add", f.AddUser(config, db, store))
|
|
|
|
mux.HandleFunc("POST /user/add-first", f.AddFirstUser(config, db, store))
|
|
|
|
mux.HandleFunc("POST /user/update/{id}", f.UpdateUser(config, db, store))
|
|
|
|
mux.HandleFunc("POST /user/update/self", f.UpdateSelf(config, db, store))
|
2024-11-01 16:31:47 +01:00
|
|
|
mux.HandleFunc("POST /user/upload-profile-pic", f.UploadImage(config, store, "upload-profile-pic", "edit-user.html", "profile-pic-template"))
|
2024-02-18 10:07:49 +01:00
|
|
|
|
2024-04-12 07:17:13 +02:00
|
|
|
log.Fatalln(http.ListenAndServe(config.Port, mux))
|
2024-02-18 07:20:51 +01:00
|
|
|
}
|