fix: inputs limit to their respective file formats

This commit is contained in:
Chris Holland 2024-10-22 15:26:46 -07:00
parent 19cc3ea0d7
commit b678ac86e8
No known key found for this signature in database
GPG key ID: 68B0A864B1B0A0D2
9 changed files with 55 additions and 6 deletions

20
apps/web/lib/constants.ts Normal file
View file

@ -0,0 +1,20 @@
export const ACCEPTED_FILE_FORMATS = {
video: 'video/*',
mp4: 'video/mp4',
webm: 'video/webm',
image: 'image/*',
jpg: 'image/jpeg',
png: 'image/png',
webp: 'image/webp',
pdf: 'application/pdf',
pptx: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
zip: 'application/zip,application/x-zip-compressed'
} as const;
/**
* Constructs the 'accept' attribute value for an input element
*/
export function constructAcceptValue(types : (keyof typeof ACCEPTED_FILE_FORMATS)[]): string {
return types.map(type => ACCEPTED_FILE_FORMATS[type]).filter(Boolean).join(",")
}