More work on stuff

This commit is contained in:
Caleb Gardner
2024-06-28 07:04:10 -05:00
parent 5db8692ec8
commit 5af5de7719
8 changed files with 34 additions and 24 deletions
-1
View File
@@ -75,7 +75,6 @@ Must have a auth token for a user with the `"blog": "admin"` permission.
```json
{
author: "authorID",
favicon: "favicon url",
title: "blog title",
blog: "blog", // blog will have been converted to HTML
+1
View File
@@ -12,6 +12,7 @@ import (
type Author struct {
ID string `json:"id" bson:"_id"`
Name string `json:"name" bson:"name"`
About string `json:"about" bson:"about"`
PicURL string `json:"picurl" bson:"picurl"`
}
+13 -5
View File
@@ -23,9 +23,9 @@ type Blog struct {
UpdateTime int `json:"updateTime" bson:"updateTime"`
}
func (b *Blog) ConvertBlog() {
func (b *BlogApp) ConvertBlog(blog *Blog) {
//TODO: parse BBCode/Markdown from blog
//b.Blog = bbCodeConvert(b.Blog)
blog.Blog = b.conv.Convert(blog.Blog)
}
func (b *BlogApp) GetAuthor(blog *Blog) (*Author, error) {
@@ -54,7 +54,7 @@ func (b *BlogApp) GetBlog(ID string) (*Blog, error) {
if err != nil {
return nil, err
}
blog.ConvertBlog()
b.ConvertBlog(&blog)
return &blog, nil
}
@@ -78,7 +78,15 @@ func (b *BlogApp) Blog(w http.ResponseWriter, r *http.Request) {
}
func (b *BlogApp) CreateBlog(w http.ResponseWriter, r *http.Request) {
//TODO
hdr, err := b.back.ParseHeader(r)
if err != nil{
if err == backend.ErrApiKeyUnauthorized{
backend.ReturnError(w, http.StatusUnauthorized, "invalidKey", "Application unauthorized")
return
}else if err == backend.ErrTokenUnauthorized{
backend.ReturnError(w, http.StatusUnauthorized, "")
}
}
}
func (b *BlogApp) UpdateBlog(w http.ResponseWriter, r *http.Request) {
@@ -102,7 +110,7 @@ func (b *BlogApp) GetLatestBlogs(page int64) ([]Blog, error) {
return nil, err
}
for i := range out {
out[i].ConvertBlog()
b.ConvertBlog(&out[i])
}
return out, nil
}
+4
View File
@@ -3,6 +3,7 @@ package blog
import (
"net/http"
"github.com/CalebQ42/bbConvert"
"github.com/CalebQ42/darkstorm-server/internal/backend"
"go.mongodb.org/mongo-driver/mongo"
)
@@ -11,6 +12,7 @@ type BlogApp struct {
back *backend.Backend
blogCol *mongo.Collection
authCol *mongo.Collection
conv *bbConvert.HTMLConverter
}
func NewBlogApp(b *backend.Backend, db *mongo.Database, mux *http.ServeMux) *BlogApp {
@@ -18,7 +20,9 @@ func NewBlogApp(b *backend.Backend, db *mongo.Database, mux *http.ServeMux) *Blo
back: b,
blogCol: db.Collection("blog"),
authCol: db.Collection("author"),
conv: &bbConvert.HTMLConverter{},
}
out.conv.ImplementDefaults()
// setup mux
mux.HandleFunc("GET /blog", out.LatestBlogs)
mux.HandleFunc("GET /blog/list", out.BlogList)