Referenced external attachment

This commit is contained in:
2025-04-05 11:51:35 +08:00
parent 048535d1c0
commit 1de0a86074
18 changed files with 90 additions and 15 deletions

View File

@ -158,6 +158,25 @@ func NewAttachmentMetadata(tx *gorm.DB, user *sec.UserInfo, file *multipart.File
return attachment, nil
}
func NewRefURLAttachment(tx *gorm.DB, user *sec.UserInfo, attachment models.Attachment) (models.Attachment, error) {
if attachment.RefURL == nil {
return attachment, fmt.Errorf("attachment doesn't have a ref url")
}
attachment.Uuid = uuid.NewString()
attachment.Rid = RandString(16)
attachment.Size = 0
attachment.Destination = models.AttachmentDstExternal
attachment.Type = models.AttachmentTypeNormal
attachment.AccountID = user.ID
if err := tx.Save(&attachment).Error; err != nil {
return attachment, fmt.Errorf("failed to save attachment record: %v", err)
}
return attachment, nil
}
func TryLinkAttachment(tx *gorm.DB, og models.Attachment, hash string) (bool, error) {
prev, err := GetAttachmentByHash(hash)
if err != nil {

View File

@ -5,9 +5,9 @@ import (
"fmt"
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
"git.solsynth.dev/hypernet/paperclip/pkg/filekit/models"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/database"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/fs"
"git.solsynth.dev/hypernet/paperclip/pkg/filekit/models"
jsoniter "github.com/json-iterator/go"
"github.com/rs/zerolog/log"
"github.com/spf13/cast"

View File

@ -3,8 +3,8 @@ package services
import (
"time"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/database"
"git.solsynth.dev/hypernet/paperclip/pkg/filekit/models"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/database"
"github.com/rs/zerolog/log"
)

View File

@ -12,9 +12,9 @@ import (
"git.solsynth.dev/hypernet/nexus/pkg/nex/cachekit"
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
"git.solsynth.dev/hypernet/paperclip/pkg/filekit/models"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/database"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/gap"
"git.solsynth.dev/hypernet/paperclip/pkg/filekit/models"
"github.com/gofiber/fiber/v2"
"github.com/google/uuid"
jsoniter "github.com/json-iterator/go"

View File

@ -66,6 +66,12 @@ func OpenAttachmentByRID(rid string, preferredSize int, region ...string) (url s
mimetype = result.Attachment.MimeType
}
if result.Attachment.RefURL != nil {
url = *result.Attachment.RefURL
filesize = 0
return
}
filesize = result.Attachment.Size
var dest models.BaseDestination

View File

@ -5,8 +5,8 @@ import (
"fmt"
"time"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/database"
"git.solsynth.dev/hypernet/paperclip/pkg/filekit/models"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/database"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/gap"
wproto "git.solsynth.dev/hypernet/wallet/pkg/proto"

View File

@ -1,8 +1,8 @@
package services
import (
"git.solsynth.dev/hypernet/paperclip/pkg/internal/database"
"git.solsynth.dev/hypernet/paperclip/pkg/filekit/models"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/database"
)
func ListAttachmentPool() ([]models.AttachmentPool, error) {

View File

@ -4,8 +4,8 @@ import (
"fmt"
"strings"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/database"
"git.solsynth.dev/hypernet/paperclip/pkg/filekit/models"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/database"
)
func SetAttachmentAsThumbnail(item models.Attachment) (models.Attachment, error) {

View File

@ -2,8 +2,8 @@ package services
import (
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/database"
"git.solsynth.dev/hypernet/paperclip/pkg/filekit/models"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/database"
"gorm.io/gorm"
)

View File

@ -6,8 +6,8 @@ import (
"gorm.io/gorm"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/database"
"git.solsynth.dev/hypernet/paperclip/pkg/filekit/models"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/database"
"github.com/spf13/viper"
)

View File

@ -8,9 +8,9 @@ import (
"os"
"path/filepath"
"git.solsynth.dev/hypernet/paperclip/pkg/filekit/models"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/database"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/fs"
"git.solsynth.dev/hypernet/paperclip/pkg/filekit/models"
"github.com/gofiber/fiber/v2"
jsoniter "github.com/json-iterator/go"
"github.com/minio/minio-go/v7"