feat(media): add public URL generation for media files and improve S3 integration
Introduce `getPublicUrl` in `S3Service` for generating public URLs. Replace custom file URL generation logic across services with the new method. Add media controller for file streaming and update related tests. Adjust frontend to display user roles instead of email in the sidebar. Update environment schema to include optional `API_URL`. Fix help page contact email.
This commit is contained in:
@@ -155,4 +155,20 @@ export class S3Service implements OnModuleInit, IStorageService {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
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}`;
|
||||
}
|
||||
|
||||
return `https://api.${domain}/media/${storageKey}`;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user