feat(s3): enhance logging and public URL generation
Add detailed logging for S3 uploads in user and content services. Improve public URL generation logic in `S3Service` by providing better handling for `API_URL`, `DOMAIN_NAME`, and `PORT`. Update relevant tests to cover all scenarios.
This commit is contained in:
@@ -158,17 +158,19 @@ export class S3Service implements OnModuleInit, IStorageService {
|
||||
|
||||
getPublicUrl(storageKey: string): string {
|
||||
const apiUrl = this.configService.get<string>("API_URL");
|
||||
if (apiUrl) {
|
||||
return `${apiUrl.replace(/\/$/, "")}/media/${storageKey}`;
|
||||
}
|
||||
|
||||
const domain = this.configService.get<string>("DOMAIN_NAME", "localhost");
|
||||
const port = this.configService.get<number>("PORT", 3000);
|
||||
|
||||
if (domain === "localhost" || domain === "127.0.0.1") {
|
||||
return `http://${domain}:${port}/media/${storageKey}`;
|
||||
let baseUrl: string;
|
||||
|
||||
if (apiUrl) {
|
||||
baseUrl = apiUrl.replace(/\/$/, "");
|
||||
} else if (domain === "localhost" || domain === "127.0.0.1") {
|
||||
baseUrl = `http://${domain}:${port}`;
|
||||
} else {
|
||||
baseUrl = `https://api.${domain}`;
|
||||
}
|
||||
|
||||
return `https://api.${domain}/media/${storageKey}`;
|
||||
return `${baseUrl}/media/${storageKey}`;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user