Support use rid to get file

This commit is contained in:
2024-08-18 19:53:50 +08:00
parent 0fb8e27e7c
commit e92e5bad60
4 changed files with 75 additions and 40 deletions

View File

@ -92,7 +92,7 @@ func listAttachment(c *fiber.Ctx) error {
}
for _, item := range result {
services.CacheAttachment(item.ID, item)
services.CacheAttachment(item)
}
return c.JSON(fiber.Map{

View File

@ -4,6 +4,7 @@ import (
"fmt"
"net/url"
"path/filepath"
"strconv"
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/database"
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/gap"
@ -18,9 +19,16 @@ import (
)
func openAttachment(c *fiber.Ctx) error {
id, _ := c.ParamsInt("id", 0)
id := c.Params("id")
metadata, err := services.GetAttachmentByID(uint(id))
var err error
var metadata models.Attachment
if numericId, numericErr := strconv.Atoi(id); numericErr == nil {
metadata, err = services.GetAttachmentByID(uint(numericId))
} else {
metadata, err = services.GetAttachmentByRID(id)
}
if err != nil {
return fiber.NewError(fiber.StatusNotFound)
}