♻️ Usermeta, is indexable, thumbnail and more fields on attachments

This commit is contained in:
LittleSheep 2024-12-26 21:53:09 +08:00
parent 5bbf13b01e
commit 3a77af23cb
5 changed files with 35 additions and 20 deletions

View File

@ -32,11 +32,17 @@ type Attachment struct {
CleanedAt *time.Time `json:"cleaned_at"`
Metadata datatypes.JSONMap `json:"metadata"`
IsMature bool `json:"is_mature"`
Metadata datatypes.JSONMap `json:"metadata"` // This field is analyzer auto generated metadata
Usermeta datatypes.JSONMap `json:"usermeta"` // This field is user set metadata
Thumbnail string `json:"thumbnail"` // The cover image of audio / video attachment
ContentRating int `json:"content_rating"` // This field use to filter mature content or not
QualityRating int `json:"quality_rating"` // This field use to filter good content or not
IsAnalyzed bool `json:"is_analyzed"`
IsUploaded bool `json:"is_uploaded"`
IsSelfRef bool `json:"is_self_ref"`
IsIndexable bool `json:"is_indexable"` // Show this attachment in the public directory api or not
Ref *Attachment `json:"ref"`
RefID *uint `json:"ref_id"`

View File

@ -2,11 +2,12 @@ package api
import (
"fmt"
"net/url"
"path/filepath"
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/database"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/server/exts"
"net/url"
"path/filepath"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/models"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/services"
@ -89,9 +90,9 @@ func updateAttachmentMeta(c *fiber.Ctx) error {
user := c.Locals("nex_user").(*sec.UserInfo)
var data struct {
Alternative string `json:"alt"`
Metadata map[string]any `json:"metadata"`
IsMature bool `json:"is_mature"`
Alternative *string `json:"alt"`
Metadata *map[string]any `json:"metadata"`
IsIndexable *bool `json:"is_indexable"`
}
if err := exts.BindAndValidate(c, &data); err != nil {
@ -103,9 +104,15 @@ func updateAttachmentMeta(c *fiber.Ctx) error {
return fiber.NewError(fiber.StatusBadRequest, err.Error())
}
attachment.Alternative = data.Alternative
attachment.Metadata = data.Metadata
attachment.IsMature = data.IsMature
if data.Alternative != nil {
attachment.Alternative = *data.Alternative
}
if data.Metadata != nil {
attachment.Usermeta = *data.Metadata
}
if data.IsIndexable != nil {
attachment.IsIndexable = *data.IsIndexable
}
if attachment, err := services.UpdateAttachment(attachment); err != nil {
return fiber.NewError(fiber.StatusBadRequest, err.Error())

View File

@ -2,11 +2,12 @@ package api
import (
"fmt"
"strings"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/gap"
"git.solsynth.dev/hypernet/passport/pkg/authkit"
"github.com/spf13/viper"
"gorm.io/datatypes"
"strings"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/database"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/models"
@ -26,7 +27,7 @@ func listAttachment(c *fiber.Ctx) error {
needQuery := true
var result = make([]models.Attachment, take)
result := make([]models.Attachment, take)
var idxList []string
if len(c.Query("id")) > 0 {
@ -73,6 +74,8 @@ func listAttachment(c *fiber.Ctx) error {
tx = tx.Where("ref_id IS NULL")
}
tx = tx.Where("is_indexable != ?", false)
var count int64
countTx := tx
if err := countTx.Model(&models.Attachment{}).Count(&count).Error; err != nil {

View File

@ -2,6 +2,7 @@ package api
import (
"fmt"
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/database"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/models"
@ -45,8 +46,7 @@ func createAttachmentDirectly(c *fiber.Ctx) error {
metadata, err := services.NewAttachmentMetadata(tx, user, file, models.Attachment{
Alternative: c.FormValue("alt"),
MimeType: c.FormValue("mimetype"),
Metadata: usermeta,
IsMature: len(c.FormValue("mature")) > 0,
Usermeta: usermeta,
IsAnalyzed: false,
IsUploaded: true,
Destination: models.AttachmentDstTemporary,

View File

@ -3,6 +3,7 @@ package api
import (
"encoding/json"
"fmt"
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/database"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/models"
@ -22,7 +23,6 @@ func createAttachmentMultipartPlaceholder(c *fiber.Ctx) error {
Alternative string `json:"alt"`
MimeType string `json:"mimetype"`
Metadata map[string]any `json:"metadata"`
IsMature bool `json:"is_mature"`
}
if err := exts.BindAndValidate(c, &data); err != nil {
@ -50,8 +50,7 @@ func createAttachmentMultipartPlaceholder(c *fiber.Ctx) error {
Size: data.Size,
Alternative: data.Alternative,
MimeType: data.MimeType,
Metadata: data.Metadata,
IsMature: data.IsMature,
Usermeta: data.Metadata,
IsAnalyzed: false,
Destination: models.AttachmentDstTemporary,
Pool: &pool,