feat: upload module (#486)
* feat: wip upload module * feat: local storage and serve local images * feat: protect against injections * feat: server local and s3 files * fix: use storage location when serving local files * feat: cross field env validation
This commit is contained in:
21
server/src/utils/image.ts
Normal file
21
server/src/utils/image.ts
Normal file
@ -0,0 +1,21 @@
|
||||
const cropRegex = /([w|h])([0-9]+)/;
|
||||
|
||||
export type ShortCropSize = `${'w' | 'h'}${number}` | 'original';
|
||||
|
||||
export interface CropSize {
|
||||
type: 'width' | 'height';
|
||||
value: number;
|
||||
}
|
||||
|
||||
export const getCropSize = (value: ShortCropSize): CropSize | null => {
|
||||
const match = value.match(cropRegex);
|
||||
|
||||
if (value === 'original' || match === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
type: match[1] === 'w' ? 'width' : 'height',
|
||||
value: +match[2],
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user