Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c03ad8c221
|
||
|
|
8483927823
|
||
|
|
e7b79013fd
|
||
|
|
b6b37ebc6b
|
||
|
|
d647a585c8
|
||
|
|
6a2abf115f
|
||
|
|
ded2d3220d
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@memegoat/backend",
|
||||
"version": "1.0.4",
|
||||
"version": "1.0.6",
|
||||
"description": "",
|
||||
"author": "",
|
||||
"private": true,
|
||||
|
||||
@@ -23,7 +23,7 @@ describe("ApiKeysRepository", () => {
|
||||
// biome-ignore lint/suspicious/noThenProperty: Necessary to mock Drizzle's awaitable query builder
|
||||
Object.defineProperty(obj, "then", {
|
||||
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);
|
||||
},
|
||||
configurable: true,
|
||||
|
||||
@@ -24,7 +24,7 @@ describe("CategoriesRepository", () => {
|
||||
// biome-ignore lint/suspicious/noThenProperty: Necessary to mock Drizzle's awaitable query builder
|
||||
Object.defineProperty(obj, "then", {
|
||||
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);
|
||||
},
|
||||
configurable: true,
|
||||
|
||||
@@ -21,10 +21,9 @@ describe("FavoritesRepository", () => {
|
||||
|
||||
const wrapWithThen = (obj: unknown) => {
|
||||
// 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", {
|
||||
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);
|
||||
},
|
||||
configurable: true,
|
||||
|
||||
@@ -49,6 +49,11 @@ describe("MediaController", () => {
|
||||
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 () => {
|
||||
mockS3Service.getFileInfo.mockRejectedValue(new Error("Not found"));
|
||||
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 { BucketItemStat } from "minio";
|
||||
import { S3Service } from "../s3/s3.service";
|
||||
|
||||
@Controller("media")
|
||||
export class MediaController {
|
||||
private readonly logger = new Logger(MediaController.name);
|
||||
|
||||
constructor(private readonly s3Service: S3Service) {}
|
||||
|
||||
@Get("*key")
|
||||
async getFile(@Param("key") key: string, @Res() res: Response) {
|
||||
try {
|
||||
const stats = (await this.s3Service.getFileInfo(key)) as BucketItemStat;
|
||||
const stream = await this.s3Service.getFile(key);
|
||||
@Get()
|
||||
async getFile(@Query("path") path: string, @Res() res: Response) {
|
||||
if (!path) {
|
||||
this.logger.warn("Tentative d'accès à un média sans paramètre 'path'");
|
||||
throw new NotFoundException("Paramètre 'path' manquant");
|
||||
}
|
||||
|
||||
const contentType =
|
||||
stats.metaData?.["content-type"] || "application/octet-stream";
|
||||
try {
|
||||
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-Length", stats.size);
|
||||
res.setHeader("Cache-Control", "public, max-age=31536000, immutable");
|
||||
|
||||
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é");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,10 +23,9 @@ describe("ReportsRepository", () => {
|
||||
|
||||
const wrapWithThen = (obj: unknown) => {
|
||||
// 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", {
|
||||
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);
|
||||
},
|
||||
configurable: true,
|
||||
|
||||
@@ -192,7 +192,7 @@ describe("S3Service", () => {
|
||||
return null;
|
||||
});
|
||||
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", () => {
|
||||
@@ -205,7 +205,7 @@ describe("S3Service", () => {
|
||||
},
|
||||
);
|
||||
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", () => {
|
||||
@@ -217,7 +217,7 @@ describe("S3Service", () => {
|
||||
},
|
||||
);
|
||||
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}`;
|
||||
}
|
||||
|
||||
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 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 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 :
|
||||
|
||||
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`).
|
||||
|
||||
### Notifications (Mail)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@memegoat/frontend",
|
||||
"version": "1.0.4",
|
||||
"version": "1.0.6",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
|
||||
@@ -95,7 +95,7 @@ export function ContentCard({ content }: ContentCardProps) {
|
||||
</CardHeader>
|
||||
<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">
|
||||
{content.type === "image" ? (
|
||||
{content.type === "meme" ? (
|
||||
<Image
|
||||
src={content.url}
|
||||
alt={content.title}
|
||||
|
||||
@@ -7,7 +7,7 @@ export interface Content {
|
||||
description?: string;
|
||||
url: string;
|
||||
thumbnailUrl?: string;
|
||||
type: "image" | "video";
|
||||
type: "meme" | "gif";
|
||||
mimeType: string;
|
||||
size: number;
|
||||
width?: number;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@memegoat/source",
|
||||
"version": "1.0.4",
|
||||
"version": "1.0.6",
|
||||
"description": "",
|
||||
"scripts": {
|
||||
"version:get": "cmake -P version.cmake GET",
|
||||
|
||||
Reference in New Issue
Block a user