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:
Mathis HERRIOT
2026-01-14 23:13:28 +01:00
parent 4ca15b578d
commit 38adbb6e77
12 changed files with 128 additions and 38 deletions

View File

@@ -30,6 +30,7 @@ describe("ContentsService", () => {
const mockS3Service = {
getUploadUrl: jest.fn(),
uploadFile: jest.fn(),
getPublicUrl: jest.fn(),
};
const mockMediaService = {

View File

@@ -128,11 +128,11 @@ export class ContentsService {
const processedData = data.map((content) => ({
...content,
url: this.getFileUrl(content.storageKey),
url: this.s3Service.getPublicUrl(content.storageKey),
author: {
...content.author,
avatarUrl: content.author?.avatarUrl
? this.getFileUrl(content.author.avatarUrl)
? this.s3Service.getPublicUrl(content.author.avatarUrl)
: null,
},
}));
@@ -189,18 +189,18 @@ export class ContentsService {
return {
...content,
url: this.getFileUrl(content.storageKey),
url: this.s3Service.getPublicUrl(content.storageKey),
author: {
...content.author,
avatarUrl: content.author?.avatarUrl
? this.getFileUrl(content.author.avatarUrl)
? this.s3Service.getPublicUrl(content.author.avatarUrl)
: null,
},
};
}
generateBotHtml(content: { title: string; storageKey: string }): string {
const imageUrl = this.getFileUrl(content.storageKey);
const imageUrl = this.s3Service.getPublicUrl(content.storageKey);
return `<!DOCTYPE html>
<html>
<head>
@@ -221,19 +221,6 @@ export class ContentsService {
</html>`;
}
getFileUrl(storageKey: string): string {
const endpoint = this.configService.get("S3_ENDPOINT");
const port = this.configService.get("S3_PORT");
const protocol =
this.configService.get("S3_USE_SSL") === true ? "https" : "http";
const bucket = this.configService.get("S3_BUCKET_NAME");
if (endpoint === "localhost" || endpoint === "127.0.0.1") {
return `${protocol}://${endpoint}:${port}/${bucket}/${storageKey}`;
}
return `${protocol}://${endpoint}/${bucket}/${storageKey}`;
}
private generateSlug(text: string): string {
return text
.toLowerCase()