fix some for api download pic

This commit is contained in:
Montech
2026-09-19 15:44:00 +03:30
parent 7227e9c61b
commit 79226c9f13
247 changed files with 409 additions and 199 deletions
@@ -0,0 +1,28 @@
import { Controller, Get, Header, NotFoundException, Param, StreamableFile } from '@nestjs/common';
import { createReadStream } from 'node:fs';
import { Public } from '../auth/guards';
import { mimeForUpload, resolveStoredUpload } from './upload-path';
/**
* Public file serving at GET /api/uploads/:filename.
*
* ProductImage.url is stored as `/uploads/<file>`, which nginx proxies. Shoppers
* and operators also hit `/api/uploads/<file>` (user-app axios base is `/api`,
* and the API Dokploy domain sits behind the same prefix). useStaticAssets only
* mounts `/uploads/`, so those requests 404'd with Nest's "Cannot GET /api/uploads/...".
*/
@Public()
@Controller('uploads')
export class PublicUploadsController {
@Get(':filename')
@Header('Cache-Control', 'public, max-age=86400')
stream(@Param('filename') filename: string): StreamableFile {
const file = resolveStoredUpload(filename);
if (!file) throw new NotFoundException('فایل یافت نشد');
return new StreamableFile(createReadStream(file), {
type: mimeForUpload(file) ?? 'application/octet-stream',
disposition: 'inline',
});
}
}