diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 541b3fa..5b62484 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,8 +4,9 @@
-
+
+
@@ -135,7 +136,8 @@
-
+
+
true
diff --git a/pkg/internal/server/api/attachment_dir_api.go b/pkg/internal/server/api/attachment_dir_api.go
index 8a4d505..2e1d24b 100644
--- a/pkg/internal/server/api/attachment_dir_api.go
+++ b/pkg/internal/server/api/attachment_dir_api.go
@@ -1,7 +1,6 @@
package api
import (
- "strconv"
"strings"
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/database"
@@ -23,25 +22,20 @@ func listAttachment(c *fiber.Ctx) error {
needQuery := true
var result = make([]models.Attachment, take)
- var idxList []uint
+ var idxList []string
if len(c.Query("id")) > 0 {
- var pendingQueryId []uint
+ var pendingQueryId []string
idx := strings.Split(c.Query("id"), ",")
for p, raw := range idx {
- id, err := strconv.Atoi(raw)
- if err != nil {
- continue
- } else {
- idxList = append(idxList, uint(id))
- }
- if val, ok := services.GetAttachmentCache(uint(id)); ok {
+ idxList = append(idxList, raw)
+ if val, ok := services.GetAttachmentCache(raw); ok {
result[p] = val
} else {
- pendingQueryId = append(pendingQueryId, uint(id))
+ pendingQueryId = append(pendingQueryId, raw)
}
}
- tx = tx.Where("id IN ?", pendingQueryId)
+ tx = tx.Where("rid IN ?", pendingQueryId)
needQuery = len(pendingQueryId) > 0
} else {
// Do sort this when doesn't filter by the id
@@ -83,7 +77,7 @@ func listAttachment(c *fiber.Ctx) error {
} else {
for _, item := range out {
for p, id := range idxList {
- if item.ID == id {
+ if item.Rid == id {
result[p] = item
}
}
diff --git a/pkg/internal/server/api/attachments_api.go b/pkg/internal/server/api/attachments_api.go
index aa64f0f..04c2107 100644
--- a/pkg/internal/server/api/attachments_api.go
+++ b/pkg/internal/server/api/attachments_api.go
@@ -2,13 +2,11 @@ package api
import (
"fmt"
- "net/url"
- "path/filepath"
- "strconv"
-
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/database"
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/gap"
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/server/exts"
+ "net/url"
+ "path/filepath"
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/models"
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/services"
@@ -21,14 +19,7 @@ import (
func openAttachment(c *fiber.Ctx) error {
id := c.Params("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)
- }
+ metadata, err := services.GetAttachmentByRID(id)
if err != nil {
return fiber.NewError(fiber.StatusNotFound)
}
@@ -77,9 +68,9 @@ func openAttachment(c *fiber.Ctx) error {
}
func getAttachmentMeta(c *fiber.Ctx) error {
- id, _ := c.ParamsInt("id")
+ id := c.Params("id")
- metadata, err := services.GetAttachmentByID(uint(id))
+ metadata, err := services.GetAttachmentByRID(id)
if err != nil {
return fiber.NewError(fiber.StatusNotFound)
}
diff --git a/pkg/internal/services/attachments.go b/pkg/internal/services/attachments.go
index b802554..94ababc 100644
--- a/pkg/internal/services/attachments.go
+++ b/pkg/internal/services/attachments.go
@@ -22,11 +22,6 @@ const metadataCacheLimit = 512
var metadataCache sync.Map
func GetAttachmentByID(id uint) (models.Attachment, error) {
- strId := strconv.Itoa(int(id))
- if val, ok := metadataCache.Load(strId); ok && val.(models.Attachment).Account.ID > 0 {
- return val.(models.Attachment), nil
- }
-
var attachment models.Attachment
if err := database.C.Where(models.Attachment{
BaseModel: models.BaseModel{ID: id},
@@ -68,17 +63,14 @@ func GetAttachmentByHash(hash string) (models.Attachment, error) {
return attachment, nil
}
-func GetAttachmentCache(id uint) (models.Attachment, bool) {
- strId := strconv.Itoa(int(id))
- if val, ok := metadataCache.Load(strId); ok && val.(models.Attachment).Account.ID > 0 {
+func GetAttachmentCache(id any) (models.Attachment, bool) {
+ if val, ok := metadataCache.Load(id); ok && val.(models.Attachment).Account.ID > 0 {
return val.(models.Attachment), ok
}
return models.Attachment{}, false
}
func CacheAttachment(item models.Attachment) {
- strId := strconv.Itoa(int(item.ID))
- metadataCache.Store(strId, item)
metadataCache.Store(item.Rid, item)
}