Skip to content

Self-hosted personal gallery application with online photo management and albums, supporting Live/Motion Photos, EXIF parsing, geolocation recognition, and an explore map.

fix(s3): support ali-oss url generating

Timothy Yinf2565419ffa6
diff --git a/server/services/storage/providers/s3.ts b/server/services/storage/providers/s3.ts
index d6ae2e61..e371a1e1 100644
--- a/server/services/storage/providers/s3.ts
+++ b/server/services/storage/providers/s3.ts
@@ -148,17 +148,31 @@ export class S3StorageProvider implements StorageProvider {
getPublicUrl(key: string): string {
const { cdnUrl, bucket, region, endpoint } = this.config
+ // CDN URL
if (cdnUrl) {
- return `${cdnUrl}/${key}`
+ return `${cdnUrl.replace(/\/$/, '')}/${key}`
}
+ // Default AWS S3 endpoint
if (!endpoint) {
return `https://${bucket}.s3.${region}.amazonaws.com/${key}`
} else if (endpoint.includes('amazonaws.com')) {
return `https://${bucket}.s3.${region}.amazonaws.com/${key}`
}
- return `${endpoint.replace(/\/+$/, '')}/${key}`
+ // Alibaba Cloud OSS
+ if (endpoint.includes('aliyuncs.com')) {
+ const baseUrl = endpoint.replace(/\/$/, '')
+ if (baseUrl.indexOf('//') === -1) {
+ throw new Error('Invalid endpoint URL')
+ }
+ const protocol = baseUrl.split('//')[0]
+ const remainder = baseUrl.split('//')[1]
+ return `${protocol}//${bucket}.${remainder}/${key}`
+ }
+
+ // Custom endpoint
+ return `${endpoint.replace(/\/$/, '')}/${bucket}/${key}`
}
async getSignedUrl(