Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c03ad8c221
|
||
|
|
8483927823
|
||
|
|
e7b79013fd
|
||
|
|
b6b37ebc6b
|
||
|
|
d647a585c8
|
||
|
|
6a2abf115f
|
||
|
|
ded2d3220d
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@memegoat/backend",
|
"name": "@memegoat/backend",
|
||||||
"version": "1.0.4",
|
"version": "1.0.6",
|
||||||
"description": "",
|
"description": "",
|
||||||
"author": "",
|
"author": "",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ describe("ApiKeysRepository", () => {
|
|||||||
// biome-ignore lint/suspicious/noThenProperty: Necessary to mock Drizzle's awaitable query builder
|
// biome-ignore lint/suspicious/noThenProperty: Necessary to mock Drizzle's awaitable query builder
|
||||||
Object.defineProperty(obj, "then", {
|
Object.defineProperty(obj, "then", {
|
||||||
value: function (onFulfilled: (arg0: unknown) => void) {
|
value: function (onFulfilled: (arg0: unknown) => void) {
|
||||||
const result = (this as any).execute();
|
const result = (this as Record<string, unknown>).execute();
|
||||||
return Promise.resolve(result).then(onFulfilled);
|
return Promise.resolve(result).then(onFulfilled);
|
||||||
},
|
},
|
||||||
configurable: true,
|
configurable: true,
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ describe("CategoriesRepository", () => {
|
|||||||
// biome-ignore lint/suspicious/noThenProperty: Necessary to mock Drizzle's awaitable query builder
|
// biome-ignore lint/suspicious/noThenProperty: Necessary to mock Drizzle's awaitable query builder
|
||||||
Object.defineProperty(obj, "then", {
|
Object.defineProperty(obj, "then", {
|
||||||
value: function (onFulfilled: (arg0: unknown) => void) {
|
value: function (onFulfilled: (arg0: unknown) => void) {
|
||||||
const result = (this as any).execute();
|
const result = (this as Record<string, unknown>).execute();
|
||||||
return Promise.resolve(result).then(onFulfilled);
|
return Promise.resolve(result).then(onFulfilled);
|
||||||
},
|
},
|
||||||
configurable: true,
|
configurable: true,
|
||||||
|
|||||||
@@ -21,10 +21,9 @@ describe("FavoritesRepository", () => {
|
|||||||
|
|
||||||
const wrapWithThen = (obj: unknown) => {
|
const wrapWithThen = (obj: unknown) => {
|
||||||
// biome-ignore lint/suspicious/noThenProperty: Necessary to mock Drizzle's awaitable query builder
|
// biome-ignore lint/suspicious/noThenProperty: Necessary to mock Drizzle's awaitable query builder
|
||||||
// biome-ignore lint/suspicious/noExplicitAny: Necessary to mock Drizzle's awaitable query builder
|
|
||||||
Object.defineProperty(obj, "then", {
|
Object.defineProperty(obj, "then", {
|
||||||
value: function (onFulfilled: (arg0: unknown) => void) {
|
value: function (onFulfilled: (arg0: unknown) => void) {
|
||||||
const result = (this as any).execute();
|
const result = (this as Record<string, unknown>).execute();
|
||||||
return Promise.resolve(result).then(onFulfilled);
|
return Promise.resolve(result).then(onFulfilled);
|
||||||
},
|
},
|
||||||
configurable: true,
|
configurable: true,
|
||||||
|
|||||||
@@ -49,6 +49,11 @@ describe("MediaController", () => {
|
|||||||
expect(stream.pipe).toHaveBeenCalledWith(res);
|
expect(stream.pipe).toHaveBeenCalledWith(res);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should throw NotFoundException if path is missing", async () => {
|
||||||
|
const res = {} as unknown as Response;
|
||||||
|
await expect(controller.getFile("", res)).rejects.toThrow(NotFoundException);
|
||||||
|
});
|
||||||
|
|
||||||
it("should throw NotFoundException if file is not found", async () => {
|
it("should throw NotFoundException if file is not found", async () => {
|
||||||
mockS3Service.getFileInfo.mockRejectedValue(new Error("Not found"));
|
mockS3Service.getFileInfo.mockRejectedValue(new Error("Not found"));
|
||||||
const res = {} as unknown as Response;
|
const res = {} as unknown as Response;
|
||||||
|
|||||||
@@ -1,27 +1,47 @@
|
|||||||
import { Controller, Get, NotFoundException, Param, Res } from "@nestjs/common";
|
import {
|
||||||
|
Controller,
|
||||||
|
Get,
|
||||||
|
Logger,
|
||||||
|
NotFoundException,
|
||||||
|
Query,
|
||||||
|
Res,
|
||||||
|
} from "@nestjs/common";
|
||||||
import type { Response } from "express";
|
import type { Response } from "express";
|
||||||
import type { BucketItemStat } from "minio";
|
import type { BucketItemStat } from "minio";
|
||||||
import { S3Service } from "../s3/s3.service";
|
import { S3Service } from "../s3/s3.service";
|
||||||
|
|
||||||
@Controller("media")
|
@Controller("media")
|
||||||
export class MediaController {
|
export class MediaController {
|
||||||
|
private readonly logger = new Logger(MediaController.name);
|
||||||
|
|
||||||
constructor(private readonly s3Service: S3Service) {}
|
constructor(private readonly s3Service: S3Service) {}
|
||||||
|
|
||||||
@Get("*key")
|
@Get()
|
||||||
async getFile(@Param("key") key: string, @Res() res: Response) {
|
async getFile(@Query("path") path: string, @Res() res: Response) {
|
||||||
try {
|
if (!path) {
|
||||||
const stats = (await this.s3Service.getFileInfo(key)) as BucketItemStat;
|
this.logger.warn("Tentative d'accès à un média sans paramètre 'path'");
|
||||||
const stream = await this.s3Service.getFile(key);
|
throw new NotFoundException("Paramètre 'path' manquant");
|
||||||
|
}
|
||||||
|
|
||||||
const contentType =
|
try {
|
||||||
stats.metaData?.["content-type"] || "application/octet-stream";
|
this.logger.log(`Récupération du fichier : ${path}`);
|
||||||
|
const stats = (await this.s3Service.getFileInfo(path)) as BucketItemStat;
|
||||||
|
const stream = await this.s3Service.getFile(path);
|
||||||
|
|
||||||
|
const contentType: string =
|
||||||
|
stats.metaData?.["content-type"] ||
|
||||||
|
stats.metaData?.["Content-Type"] ||
|
||||||
|
"application/octet-stream";
|
||||||
|
|
||||||
res.setHeader("Content-Type", contentType);
|
res.setHeader("Content-Type", contentType);
|
||||||
res.setHeader("Content-Length", stats.size);
|
res.setHeader("Content-Length", stats.size);
|
||||||
res.setHeader("Cache-Control", "public, max-age=31536000, immutable");
|
res.setHeader("Cache-Control", "public, max-age=31536000, immutable");
|
||||||
|
|
||||||
stream.pipe(res);
|
stream.pipe(res);
|
||||||
} catch (_error) {
|
} catch (error) {
|
||||||
|
this.logger.error(
|
||||||
|
`Erreur lors de la récupération du fichier ${path} : ${error.message}`,
|
||||||
|
);
|
||||||
throw new NotFoundException("Fichier non trouvé");
|
throw new NotFoundException("Fichier non trouvé");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,10 +23,9 @@ describe("ReportsRepository", () => {
|
|||||||
|
|
||||||
const wrapWithThen = (obj: unknown) => {
|
const wrapWithThen = (obj: unknown) => {
|
||||||
// biome-ignore lint/suspicious/noThenProperty: Necessary to mock Drizzle's awaitable query builder
|
// biome-ignore lint/suspicious/noThenProperty: Necessary to mock Drizzle's awaitable query builder
|
||||||
// biome-ignore lint/suspicious/noExplicitAny: Necessary to mock Drizzle's awaitable query builder
|
|
||||||
Object.defineProperty(obj, "then", {
|
Object.defineProperty(obj, "then", {
|
||||||
value: function (onFulfilled: (arg0: unknown) => void) {
|
value: function (onFulfilled: (arg0: unknown) => void) {
|
||||||
const result = (this as any).execute();
|
const result = (this as Record<string, unknown>).execute();
|
||||||
return Promise.resolve(result).then(onFulfilled);
|
return Promise.resolve(result).then(onFulfilled);
|
||||||
},
|
},
|
||||||
configurable: true,
|
configurable: true,
|
||||||
|
|||||||
@@ -192,7 +192,7 @@ describe("S3Service", () => {
|
|||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
const url = service.getPublicUrl("test.webp");
|
const url = service.getPublicUrl("test.webp");
|
||||||
expect(url).toBe("https://api.test.com/media/test.webp");
|
expect(url).toBe("https://api.test.com/media?path=test.webp");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should use DOMAIN_NAME and PORT for localhost", () => {
|
it("should use DOMAIN_NAME and PORT for localhost", () => {
|
||||||
@@ -205,7 +205,7 @@ describe("S3Service", () => {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
const url = service.getPublicUrl("test.webp");
|
const url = service.getPublicUrl("test.webp");
|
||||||
expect(url).toBe("http://localhost:3000/media/test.webp");
|
expect(url).toBe("http://localhost:3000/media?path=test.webp");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should use api.DOMAIN_NAME for production", () => {
|
it("should use api.DOMAIN_NAME for production", () => {
|
||||||
@@ -217,7 +217,7 @@ describe("S3Service", () => {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
const url = service.getPublicUrl("test.webp");
|
const url = service.getPublicUrl("test.webp");
|
||||||
expect(url).toBe("https://api.memegoat.fr/media/test.webp");
|
expect(url).toBe("https://api.memegoat.fr/media?path=test.webp");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -173,6 +173,6 @@ export class S3Service implements OnModuleInit, IStorageService {
|
|||||||
baseUrl = `https://api.${domain}`;
|
baseUrl = `https://api.${domain}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return `${baseUrl}/media/${storageKey}`;
|
return `${baseUrl}/media?path=${storageKey}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -239,7 +239,7 @@ Cette page documente tous les points de terminaison disponibles sur l'API Memego
|
|||||||
</Accordion>
|
</Accordion>
|
||||||
|
|
||||||
<Accordion title="Médias (/media)">
|
<Accordion title="Médias (/media)">
|
||||||
- `GET /media/*key` : Accès direct aux fichiers stockés sur S3. Supporte la mise en cache agressive.
|
- `GET /media?path=key` : Accès direct aux fichiers stockés sur S3 via le paramètre `path`. Supporte la mise en cache agressive.
|
||||||
</Accordion>
|
</Accordion>
|
||||||
|
|
||||||
<Accordion title="Administration (/admin)">
|
<Accordion title="Administration (/admin)">
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ Le système utilise plusieurs méthodes d'authentification sécurisées pour ré
|
|||||||
|
|
||||||
Memegoat utilise une architecture de stockage d'objets compatible S3 (MinIO). Les interactions se font de deux manières :
|
Memegoat utilise une architecture de stockage d'objets compatible S3 (MinIO). Les interactions se font de deux manières :
|
||||||
|
|
||||||
1. **Proxification Backend** : Pour l'accès public via `/media/*`.
|
1. **Proxification Backend** : Pour l'accès public via `/media?path=...`.
|
||||||
2. **URLs Présignées** : Pour l'upload sécurisé direct depuis le client (via `/contents/upload-url`).
|
2. **URLs Présignées** : Pour l'upload sécurisé direct depuis le client (via `/contents/upload-url`).
|
||||||
|
|
||||||
### Notifications (Mail)
|
### Notifications (Mail)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@memegoat/frontend",
|
"name": "@memegoat/frontend",
|
||||||
"version": "1.0.4",
|
"version": "1.0.6",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev",
|
"dev": "next dev",
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ export function ContentCard({ content }: ContentCardProps) {
|
|||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="p-0 relative bg-zinc-100 dark:bg-zinc-900 aspect-square flex items-center justify-center">
|
<CardContent className="p-0 relative bg-zinc-100 dark:bg-zinc-900 aspect-square flex items-center justify-center">
|
||||||
<Link href={`/meme/${content.slug}`} className="w-full h-full relative">
|
<Link href={`/meme/${content.slug}`} className="w-full h-full relative">
|
||||||
{content.type === "image" ? (
|
{content.type === "meme" ? (
|
||||||
<Image
|
<Image
|
||||||
src={content.url}
|
src={content.url}
|
||||||
alt={content.title}
|
alt={content.title}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ export interface Content {
|
|||||||
description?: string;
|
description?: string;
|
||||||
url: string;
|
url: string;
|
||||||
thumbnailUrl?: string;
|
thumbnailUrl?: string;
|
||||||
type: "image" | "video";
|
type: "meme" | "gif";
|
||||||
mimeType: string;
|
mimeType: string;
|
||||||
size: number;
|
size: number;
|
||||||
width?: number;
|
width?: number;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@memegoat/source",
|
"name": "@memegoat/source",
|
||||||
"version": "1.0.4",
|
"version": "1.0.6",
|
||||||
"description": "",
|
"description": "",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"version:get": "cmake -P version.cmake GET",
|
"version:get": "cmake -P version.cmake GET",
|
||||||
|
|||||||
Reference in New Issue
Block a user