Image proxy preview

This commit is contained in:
2025-03-30 21:28:24 +08:00
parent 820d7a9f42
commit f306ee2e1e
5 changed files with 28 additions and 9 deletions

View File

@ -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)