feat: custom stickers apis

This commit is contained in:
Krispire Admin
2026-08-30 03:02:49 +05:30
parent fecb9bc045
commit 4427849647
6 changed files with 156 additions and 4 deletions
+23
View File
@@ -775,6 +775,29 @@ func (s *CollectionService) CoverPresign(ctx context.Context, userID, contentTyp
// presignImage builds an R2 presign for a user-scoped media key under the
// given prefix. The random suffix invalidates browser caches when the image
// is replaced.
// presignImageKey is presignImage's sibling for callers that store the storage
// KEY rather than a URL — so the CDN domain can change without rewriting rows.
// Handing those callers a public URL silently doubles it at read time.
func presignImageKey(ctx context.Context, r2 *repository.R2, prefix, name, contentType string) (uploadURL, key string, err error) {
if r2 == nil {
return "", "", errors.New("media uploads are not configured")
}
ext, ok := imageExtensionFor(contentType)
if !ok {
return "", "", fmt.Errorf("unsupported content type: %s", contentType)
}
suffix := make([]byte, 8)
if _, err := rand.Read(suffix); err != nil {
return "", "", err
}
key = path.Join(prefix, name, hex.EncodeToString(suffix)+ext)
uploadURL, _, err = r2.PresignPut(ctx, key, contentType, 5*time.Minute)
if err != nil {
return "", "", err
}
return uploadURL, key, nil
}
func presignImage(ctx context.Context, r2 *repository.R2, prefix, userID, contentType string) (uploadURL, publicURL string, err error) {
if r2 == nil {
return "", "", errors.New("media uploads are not configured")