✨ Referenced external attachment
This commit is contained in:
@ -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 {
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
)
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
|
@ -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"
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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"
|
||||
)
|
||||
|
||||
|
@ -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"
|
||||
)
|
||||
|
||||
|
@ -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"
|
||||
|
Reference in New Issue
Block a user