Fixing more stuff

This commit is contained in:
2022-02-06 18:27:30 +01:00
parent 8bc01e0984
commit e582a75d9e
13 changed files with 56 additions and 38 deletions

View File

@@ -36,7 +36,7 @@ func Article(w http.ResponseWriter, r *http.Request) {
Error500(w, r)
} else {
var authors, tags []string
database.GetDB().Table("author").Select("id").Where("id IN (?)", database.GetDB().Table("article_author").Select("author_id").Where("article_id = ?", article.Id)).Find(&authors)
database.GetDB().Table("author").Select("name").Where("id IN (?)", database.GetDB().Table("article_author").Select("author_id").Where("article_id = ?", article.Id)).Find(&authors)
database.GetDB().Table("article_tag").Where("article_id = ?", article.Id).Find(&tags)
ta := tmplArticle{

23
server/assets.go Normal file
View File

@@ -0,0 +1,23 @@
package server
import (
"TheAdversary/database"
"github.com/gorilla/mux"
"mime"
"net/http"
"path"
)
func Assets(w http.ResponseWriter, r *http.Request) {
assetName := mux.Vars(r)["asset"]
var buf []interface{}
database.GetDB().Table("assets").Select("data").Find(&buf, "link = ?", assetName)
if buf == nil {
Error404(w, r)
} else {
data := buf[0].([]byte)
w.Header().Set("Content-Type", mime.TypeByExtension(path.Ext(assetName)))
w.Write(data)
}
}