p5.js-web-editor/server/utils/fileUtils.js

30 lines
1.5 KiB
JavaScript
Raw Permalink Normal View History

export const fileExtensionsArray = ['gif', 'jpg', 'jpeg', 'png', 'bmp', 'wav', 'flac', 'ogg',
'oga', 'mp4', 'm4p', 'mp3', 'm4a', 'aiff', 'aif', 'm4v', 'aac', 'webm', 'mpg', 'mp2',
2019-12-05 20:13:45 +00:00
'mpeg', 'mpe', 'mpv', 'js', 'jsx', 'html', 'htm', 'css', 'json', 'csv', 'tsv', 'obj', 'svg',
2019-09-26 20:17:22 +00:00
'otf', 'ttf', 'txt', 'mov', 'vert', 'frag', 'bin'];
export const mimeTypes = `image/*,audio/*,text/javascript,text/html,text/css,
application/json,application/x-font-ttf,application/x-font-truetype,text/plain,
text/csv,.obj,video/webm,video/ogg,video/quicktime,video/mp4`;
export const fileExtensions = fileExtensionsArray.map(ext => `.${ext}`).join(',');
export const fileExtensionsAndMimeTypes = `${fileExtensions},${mimeTypes}`;
export const MEDIA_FILE_REGEX =
new RegExp(`^(?!(http:\\/\\/|https:\\/\\/)).*\\.(${fileExtensionsArray.join('|')})$`, 'i');
export const MEDIA_FILE_QUOTED_REGEX =
new RegExp(`^('|")(?!(http:\\/\\/|https:\\/\\/)).*\\.(${fileExtensionsArray.join('|')})('|")$`, 'i');
export const STRING_REGEX = /(['"])((\\\1|.)*?)\1/gm;
2018-05-30 22:23:32 +00:00
// these are files that have to be linked to with a blob url
2018-08-29 19:06:41 +00:00
export const PLAINTEXT_FILE_REGEX = /.+\.(json|txt|csv|vert|frag|tsv)$/i;
2018-05-30 22:23:32 +00:00
// these are files that users would want to edit as text (maybe svg should be here?)
2019-09-26 20:17:22 +00:00
export const TEXT_FILE_REGEX = /.+\.(json|txt|csv|tsv|vert|frag|js|css|html|htm|jsx)$/i;
export const NOT_EXTERNAL_LINK_REGEX = /^(?!(http:\/\/|https:\/\/))/;
export const EXTERNAL_LINK_REGEX = /^(http:\/\/|https:\/\/)/;
2019-09-26 20:17:22 +00:00
export const CREATE_FILE_REGEX = /.+\.(json|txt|csv|tsv|js|css|frag|vert)$/i;