Files
TREK/server/src/nest/common/place-image-upload.ts
T
Maurice 8fd46c4c18 feat: quality of life sweep from the feature discussions
Small requests from the discussions, each built end to end: planner and
map (cycling mode, date first headings, clear a day, stay times per day,
off-route stops, map lock, compact unplanned markers, pending stays,
cable car, transit quick picks), places (location filter, category from
OSM, open in maps, geo: link, image from an attachment, enrichment on
file import, places near a pin, place name language, Amap first in
China), lists and costs (packed counter, inherited sharing, Markdown
to-dos, payment notes, bookings CSV, my plan PDF), sharing (unplanned
places, travel only, without photos), journey (photo zoom, drafts,
photo order, trip suggestion, day jump), atlas (region counter, region
bucket list, places per country), vacay half company holidays, studio
copy and paste plus the book's own layouts, and RESTORE_FROM_BACKUP for
a first start restore.
2026-09-30 23:00:12 +02:00

26 lines
1.2 KiB
TypeScript

import path from 'path';
import type { Options } from 'multer';
export const MAX_PLACE_IMAGE_SIZE = 20 * 1024 * 1024; // 20 MB — same cap as covers.
/** The picture types a place image may be, whether uploaded or taken from an attachment. */
export const PLACE_IMAGE_EXTENSIONS = ['.jpg', '.jpeg', '.png', '.gif', '.webp'];
/**
* fileFilter for the custom place-image upload (#1136), shared by the
* trip-place and collection-place upload endpoints (passed inline on each
* route; the storage engine — spool destination + UUID filename — comes from
* the owning module's storage-upload factory options).
*/
export const PLACE_IMAGE_FILE_FILTER: Options['fileFilter'] = (_req, file, cb) => {
const ext = path.extname(file.originalname).toLowerCase();
if (file.mimetype.startsWith('image/') && !file.mimetype.includes('svg') && PLACE_IMAGE_EXTENSIONS.includes(ext)) {
cb(null, true);
} else {
// Carry statusCode so TrekExceptionFilter maps the rejection to a 400 rather
// than a 500 (same contract as the avatar upload's fileFilter).
const err: Error & { statusCode?: number } = new Error('Only jpg, png, gif, webp images allowed');
err.statusCode = 400;
cb(err);
}
};