♻️ Usermeta, is indexable, thumbnail and more fields on attachments
This commit is contained in:
parent
5bbf13b01e
commit
3a77af23cb
@ -32,11 +32,17 @@ type Attachment struct {
|
|||||||
|
|
||||||
CleanedAt *time.Time `json:"cleaned_at"`
|
CleanedAt *time.Time `json:"cleaned_at"`
|
||||||
|
|
||||||
Metadata datatypes.JSONMap `json:"metadata"`
|
Metadata datatypes.JSONMap `json:"metadata"` // This field is analyzer auto generated metadata
|
||||||
IsMature bool `json:"is_mature"`
|
Usermeta datatypes.JSONMap `json:"usermeta"` // This field is user set metadata
|
||||||
IsAnalyzed bool `json:"is_analyzed"`
|
|
||||||
IsUploaded bool `json:"is_uploaded"`
|
Thumbnail string `json:"thumbnail"` // The cover image of audio / video attachment
|
||||||
IsSelfRef bool `json:"is_self_ref"`
|
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"`
|
Ref *Attachment `json:"ref"`
|
||||||
RefID *uint `json:"ref_id"`
|
RefID *uint `json:"ref_id"`
|
||||||
|
@ -2,11 +2,12 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/url"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
|
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
|
||||||
"git.solsynth.dev/hypernet/paperclip/pkg/internal/database"
|
"git.solsynth.dev/hypernet/paperclip/pkg/internal/database"
|
||||||
"git.solsynth.dev/hypernet/paperclip/pkg/internal/server/exts"
|
"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/models"
|
||||||
"git.solsynth.dev/hypernet/paperclip/pkg/internal/services"
|
"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)
|
user := c.Locals("nex_user").(*sec.UserInfo)
|
||||||
|
|
||||||
var data struct {
|
var data struct {
|
||||||
Alternative string `json:"alt"`
|
Alternative *string `json:"alt"`
|
||||||
Metadata map[string]any `json:"metadata"`
|
Metadata *map[string]any `json:"metadata"`
|
||||||
IsMature bool `json:"is_mature"`
|
IsIndexable *bool `json:"is_indexable"`
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := exts.BindAndValidate(c, &data); err != nil {
|
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())
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
attachment.Alternative = data.Alternative
|
if data.Alternative != nil {
|
||||||
attachment.Metadata = data.Metadata
|
attachment.Alternative = *data.Alternative
|
||||||
attachment.IsMature = data.IsMature
|
}
|
||||||
|
if data.Metadata != nil {
|
||||||
|
attachment.Usermeta = *data.Metadata
|
||||||
|
}
|
||||||
|
if data.IsIndexable != nil {
|
||||||
|
attachment.IsIndexable = *data.IsIndexable
|
||||||
|
}
|
||||||
|
|
||||||
if attachment, err := services.UpdateAttachment(attachment); err != nil {
|
if attachment, err := services.UpdateAttachment(attachment); err != nil {
|
||||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||||
|
@ -2,11 +2,12 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"git.solsynth.dev/hypernet/paperclip/pkg/internal/gap"
|
"git.solsynth.dev/hypernet/paperclip/pkg/internal/gap"
|
||||||
"git.solsynth.dev/hypernet/passport/pkg/authkit"
|
"git.solsynth.dev/hypernet/passport/pkg/authkit"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"gorm.io/datatypes"
|
"gorm.io/datatypes"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"git.solsynth.dev/hypernet/paperclip/pkg/internal/database"
|
"git.solsynth.dev/hypernet/paperclip/pkg/internal/database"
|
||||||
"git.solsynth.dev/hypernet/paperclip/pkg/internal/models"
|
"git.solsynth.dev/hypernet/paperclip/pkg/internal/models"
|
||||||
@ -26,7 +27,7 @@ func listAttachment(c *fiber.Ctx) error {
|
|||||||
|
|
||||||
needQuery := true
|
needQuery := true
|
||||||
|
|
||||||
var result = make([]models.Attachment, take)
|
result := make([]models.Attachment, take)
|
||||||
var idxList []string
|
var idxList []string
|
||||||
|
|
||||||
if len(c.Query("id")) > 0 {
|
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("ref_id IS NULL")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tx = tx.Where("is_indexable != ?", false)
|
||||||
|
|
||||||
var count int64
|
var count int64
|
||||||
countTx := tx
|
countTx := tx
|
||||||
if err := countTx.Model(&models.Attachment{}).Count(&count).Error; err != nil {
|
if err := countTx.Model(&models.Attachment{}).Count(&count).Error; err != nil {
|
||||||
|
@ -2,6 +2,7 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
|
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
|
||||||
"git.solsynth.dev/hypernet/paperclip/pkg/internal/database"
|
"git.solsynth.dev/hypernet/paperclip/pkg/internal/database"
|
||||||
"git.solsynth.dev/hypernet/paperclip/pkg/internal/models"
|
"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{
|
metadata, err := services.NewAttachmentMetadata(tx, user, file, models.Attachment{
|
||||||
Alternative: c.FormValue("alt"),
|
Alternative: c.FormValue("alt"),
|
||||||
MimeType: c.FormValue("mimetype"),
|
MimeType: c.FormValue("mimetype"),
|
||||||
Metadata: usermeta,
|
Usermeta: usermeta,
|
||||||
IsMature: len(c.FormValue("mature")) > 0,
|
|
||||||
IsAnalyzed: false,
|
IsAnalyzed: false,
|
||||||
IsUploaded: true,
|
IsUploaded: true,
|
||||||
Destination: models.AttachmentDstTemporary,
|
Destination: models.AttachmentDstTemporary,
|
||||||
|
@ -3,6 +3,7 @@ package api
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
|
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
|
||||||
"git.solsynth.dev/hypernet/paperclip/pkg/internal/database"
|
"git.solsynth.dev/hypernet/paperclip/pkg/internal/database"
|
||||||
"git.solsynth.dev/hypernet/paperclip/pkg/internal/models"
|
"git.solsynth.dev/hypernet/paperclip/pkg/internal/models"
|
||||||
@ -22,7 +23,6 @@ func createAttachmentMultipartPlaceholder(c *fiber.Ctx) error {
|
|||||||
Alternative string `json:"alt"`
|
Alternative string `json:"alt"`
|
||||||
MimeType string `json:"mimetype"`
|
MimeType string `json:"mimetype"`
|
||||||
Metadata map[string]any `json:"metadata"`
|
Metadata map[string]any `json:"metadata"`
|
||||||
IsMature bool `json:"is_mature"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := exts.BindAndValidate(c, &data); err != nil {
|
if err := exts.BindAndValidate(c, &data); err != nil {
|
||||||
@ -50,8 +50,7 @@ func createAttachmentMultipartPlaceholder(c *fiber.Ctx) error {
|
|||||||
Size: data.Size,
|
Size: data.Size,
|
||||||
Alternative: data.Alternative,
|
Alternative: data.Alternative,
|
||||||
MimeType: data.MimeType,
|
MimeType: data.MimeType,
|
||||||
Metadata: data.Metadata,
|
Usermeta: data.Metadata,
|
||||||
IsMature: data.IsMature,
|
|
||||||
IsAnalyzed: false,
|
IsAnalyzed: false,
|
||||||
Destination: models.AttachmentDstTemporary,
|
Destination: models.AttachmentDstTemporary,
|
||||||
Pool: &pool,
|
Pool: &pool,
|
||||||
|
Loading…
Reference in New Issue
Block a user