first image \o/

This commit is contained in:
Niko Abeler 2023-07-08 14:32:20 +02:00
parent a90bcaaa2d
commit e9e17ed263
3 changed files with 12 additions and 7 deletions

View File

@ -26,7 +26,7 @@ func NewWebApp(
indexHandler := NewIndexHandler(entryService)
listHandler := NewListHandler(entryService)
entryHandler := NewEntryHandler(entryService, typeRegistry)
mediaHandler := NewMediaHandler(entryService)
mediaHandler := NewMediaHandler(binService)
rssHandler := NewRSSHandler(entryService)
loginHandler := NewLoginHandler(authorService)
editorListHandler := NewEditorListHandler(typeRegistry)
@ -47,7 +47,7 @@ func NewWebApp(
app.Get("/", indexHandler.Handle)
app.Get("/lists/:list/", listHandler.Handle)
// Media
app.Get("/media/*filepath", mediaHandler.Handle)
app.Get("/media/:id", mediaHandler.Handle)
// RSS
app.Get("/index.xml", rssHandler.Handle)
// Posts

View File

@ -7,13 +7,18 @@ import (
)
type MediaHandler struct {
entrySvc *app.EntryService
binaryService *app.BinaryService
}
func NewMediaHandler(entryService *app.EntryService) *MediaHandler {
return &MediaHandler{entrySvc: entryService}
func NewMediaHandler(binaryService *app.BinaryService) *MediaHandler {
return &MediaHandler{binaryService: binaryService}
}
func (h *MediaHandler) Handle(c *fiber.Ctx) error {
return c.SendString("Hello, Media!")
id := c.Params("id")
binary, err := h.binaryService.FindById(id)
if err != nil {
return err
}
return c.Send(binary.Data)
}

View File

@ -2,7 +2,7 @@
{{define "main"}}
{{.MetaData.ImageId}}
<img src="/media/{{.MetaData.ImageId}}">
<p>
{{.Content}}