add helper function for handling existing file in s3

This commit is contained in:
gitGnome
2026-04-15 14:01:39 +02:00
parent 90018bccdd
commit 3c31e82061
2 changed files with 36 additions and 19 deletions
+4 -7
View File
@@ -35,7 +35,7 @@ func extensionFromContentType(ct string) string {
return exts[0]
}
func getKey(hash string, contentType string) string {
func GetKey(hash string, contentType string) string {
return hash + extensionFromContentType(contentType)
}
@@ -78,15 +78,12 @@ func Upload(ctx context.Context, key string, body io.Reader, size int64, content
return err
}
func getDownloadUrl(ctx context.Context, key string) (*url.URL, error) {
func GetDownloadUrl(ctx context.Context, key string) (*url.URL, error) {
u, err := minClient.PresignedGetObject(ctx, globals.FileStorageBucketName, key, globals.FileDownloadLinkTtl, nil)
return u, err
}
func DoesExist(ctx context.Context, key string) bool {
_, err := minClient.GetObject(ctx, globals.FileStorageBucketName, key, minio.GetObjectOptions{})
if err != nil {
return false
}
return true
_, err := minClient.StatObject(ctx, globals.FileStorageBucketName, key, minio.StatObjectOptions{})
return err == nil
}