diff --git a/pkg/filekit/models/destination.go b/pkg/filekit/models/destination.go index bea9887..fc83d67 100644 --- a/pkg/filekit/models/destination.go +++ b/pkg/filekit/models/destination.go @@ -35,6 +35,7 @@ type S3Destination struct { SecretID string `json:"secret_id"` SecretKey string `json:"secret_key"` AccessBaseURL string `json:"access_baseurl"` + ImageProxyURL string `json:"image_proxy_baseurl"` EnableSSL bool `json:"enable_ssl"` EnableSigned bool `json:"enable_signed"` BucketLookup int `json:"bucket_lookup"` diff --git a/pkg/internal/server/api/attachments_api.go b/pkg/internal/server/api/attachments_api.go index d2542ef..1386f26 100644 --- a/pkg/internal/server/api/attachments_api.go +++ b/pkg/internal/server/api/attachments_api.go @@ -2,9 +2,10 @@ package api import ( "fmt" - "github.com/spf13/viper" "strings" + "github.com/spf13/viper" + "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" @@ -40,9 +41,9 @@ func openAttachment(c *fiber.Ctx) error { var err error var url, mimetype string if len(region) > 0 { - url, mimetype, err = services.OpenAttachmentByRID(id, region) + url, mimetype, err = services.OpenAttachmentByRID(id, c.QueryBool("preview", true), region) } else { - url, mimetype, err = services.OpenAttachmentByRID(id) + url, mimetype, err = services.OpenAttachmentByRID(id, c.QueryBool("preview", true)) } if err != nil { diff --git a/pkg/internal/server/api/stickers_api.go b/pkg/internal/server/api/stickers_api.go index 1e44596..a43ad68 100644 --- a/pkg/internal/server/api/stickers_api.go +++ b/pkg/internal/server/api/stickers_api.go @@ -2,12 +2,13 @@ package api import ( "fmt" - "github.com/samber/lo" "strings" + "github.com/samber/lo" + "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" "git.solsynth.dev/hypernet/paperclip/pkg/internal/server/exts" "git.solsynth.dev/hypernet/paperclip/pkg/internal/services" "github.com/gofiber/fiber/v2" @@ -42,9 +43,9 @@ func openStickerByAlias(c *fiber.Ctx) error { var url, mimetype string if len(region) > 0 { - url, mimetype, err = services.OpenAttachmentByRID(sticker.Attachment.Rid, region) + url, mimetype, err = services.OpenAttachmentByRID(sticker.Attachment.Rid, true, region) } else { - url, mimetype, err = services.OpenAttachmentByRID(sticker.Attachment.Rid) + url, mimetype, err = services.OpenAttachmentByRID(sticker.Attachment.Rid, true) } if err != nil { diff --git a/pkg/internal/services/opener.go b/pkg/internal/services/opener.go index eb0b144..8ecec31 100644 --- a/pkg/internal/services/opener.go +++ b/pkg/internal/services/opener.go @@ -7,15 +7,17 @@ import ( "math/rand/v2" nurl "net/url" "path/filepath" + "strings" "time" "git.solsynth.dev/hypernet/nexus/pkg/nex/cachekit" + "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" jsoniter "github.com/json-iterator/go" "github.com/minio/minio-go/v7" "github.com/samber/lo" + "github.com/spf13/viper" ) type openAttachmentResult struct { @@ -27,7 +29,7 @@ func KgAttachmentOpenCache(rid string) string { return fmt.Sprintf("attachment-open#%s", rid) } -func OpenAttachmentByRID(rid string, region ...string) (url string, mimetype string, err error) { +func OpenAttachmentByRID(rid string, preview bool, region ...string) (url string, mimetype string, err error) { var result *openAttachmentResult if val, err := cachekit.Get[openAttachmentResult]( gap.Ca, @@ -139,6 +141,16 @@ func OpenAttachmentByRID(rid string, region ...string) (url string, mimetype str nurl.QueryEscape(filepath.Join(destConfigured.Path, result.Attachment.Uuid)), ) } + if len(destConfigured.ImageProxyURL) > 0 && preview { + size := viper.GetInt("imageproxy.size") + url = fmt.Sprintf( + "%s/%dx%d,fit/%s", + destConfigured.ImageProxyURL, + size, + size, + strings.Replace(url, destConfigured.AccessBaseURL, "", 1), + ) + } return default: err = fmt.Errorf("invalid destination: unsupported protocol %s", dest.Type) diff --git a/settings.toml b/settings.toml index a782f13..0912cec 100644 --- a/settings.toml +++ b/settings.toml @@ -25,6 +25,10 @@ path = "uploads" type = "local" path = "uploads/permanent" access_baseurl = "http://192.168.50.133:8004" +image_proxy_baseurl = "https://io.sn.solsynth.dev" + +[imageproxy] +size = 1024 [security] internal_public_key = "keys/internal_public_key.pem"