More changes to uploads:

- Have got upload images appearing in the post list
- Allowed for deleting uploads
- Allowed for seeing the upload progress
- Fixed the setting of upload properties like the MIME type
- Removed the stripe exif logic with just re-encoding PNGs and JPEGs by loading them and saving them
This commit is contained in:
Leon Mika 2026-03-04 22:33:39 +11:00
parent d0cebe6564
commit 199ff9feb9
21 changed files with 471 additions and 65 deletions

View file

@ -6,7 +6,6 @@ import (
"html/template"
"log"
"path/filepath"
"strings"
"time"
"github.com/gofiber/fiber/v3"
@ -17,11 +16,11 @@ import (
fiber_html "github.com/gofiber/template/html/v3"
"github.com/gofiber/utils/v2"
"github.com/spf13/cobra"
"github.com/yuin/goldmark"
"github.com/yuin/goldmark/extension"
"lmika.dev/lmika/weiro/config"
"lmika.dev/lmika/weiro/handlers"
"lmika.dev/lmika/weiro/handlers/middleware"
"lmika.dev/lmika/weiro/models"
"lmika.dev/lmika/weiro/providers/markdown"
"lmika.dev/lmika/weiro/services"
)
@ -49,16 +48,19 @@ Starting weiro without any arguments will start the server.
fiberTemplate := fiber_html.New("./views", ".html")
fiberTemplate.Funcmap["sub"] = func(x, y int) int { return x - y }
fiberTemplate.Funcmap["markdown"] = func() func(s string) template.HTML {
mdParser := goldmark.New(
goldmark.WithExtensions(extension.GFM),
)
return func(s string) template.HTML {
var sb strings.Builder
if err := mdParser.Convert([]byte(s), &sb); err != nil {
fiberTemplate.Funcmap["markdown"] = func() func(s string, site models.Site) template.HTML {
mdParser := markdown.NewRendererForUI()
return func(s string, site models.Site) template.HTML {
ctx := context.Background()
if site.ID != 0 {
ctx = models.WithSite(ctx, site)
}
s, err := mdParser.Render(ctx, s)
if err != nil {
return template.HTML("Markdown error: " + html.EscapeString(err.Error()))
}
return template.HTML(sb.String())
return template.HTML(s)
}
}()
@ -124,11 +126,13 @@ Starting weiro without any arguments will start the server.
siteGroup.Delete("/posts/:postID", ph.Delete)
siteGroup.Get("/uploads", uh.Index)
siteGroup.Get("/uploads/slug/+", uh.ShowFromSlug)
siteGroup.Get("/uploads/:uploadID", uh.Show)
siteGroup.Get("/uploads/:uploadID/raw", uh.ShowRaw)
siteGroup.Post("/uploads/pending", uh.New)
siteGroup.Post("/uploads/pending/:guid", uh.UploadPart)
siteGroup.Post("/uploads/pending/:guid/finalize", uh.UploadComplete)
siteGroup.Delete("/uploads/:uploadID", uh.Delete)
app.Get("/", middleware.OptionalUser(svcs.Auth), ih.Index)
app.Get("/first-run", ih.FirstRun)