Spaces:
Running
Running
Vyacheslav commited on
Commit ·
c67c596
1
Parent(s): 71d77cc
optimization
Browse files23 unmodified lines24252627282930313231 unmodified lines6465666768697071727374757643 unmodified lines12012112212312412512612712812913013113223 unmodified linesconst upload = multer({storage,limits: { fileSize: 30 * 1024 * 1024 }});const handleUploadSingle = (req, res, next) => {upload.single('file')(req, res, (err) => {if (err instanceof multer.MulterError) {31 unmodified linesconst ext = path.extname(cleanName).toLowerCase();finalPath = safePath;const allowedExts = ['.jpg', '.jpeg', '.png', '.webp', '.gif', '.mp3', '.wav', '.ogg', '.m4a', '.mp4', '.webm', '.mov'];if (!allowedExts.includes(ext)) {if (fs.existsSync(safePath)) await fsPromises.unlink(safePath);return res.status(400).json({ error: st('Недопустимый формат файла', detectLangReq(req)) });}if (['.jpg', '.jpeg', '.png', '.webp'].includes(ext)) {try {const tempPath = safePath + '_clean.webp';await sharp(safePath, { limitInputPixels: 50000000 }) // Увеличен лимит пикселей43 unmodified linesconst ext = path.extname(cleanName).toLowerCase();let finalPath = safePath;const allowedExts = ['.jpg', '.jpeg', '.png', '.webp', '.gif', '.mp3', '.wav', '.ogg', '.m4a', '.mp4', '.webm', '.mov'];if (!allowedExts.includes(ext)) {if (fs.existsSync(safePath)) await fsPromises.unlink(safePath);continue;}if (['.jpg', '.jpeg', '.png', '.webp'].includes(ext)) {try {const tempPath = safePath + '_clean.webp';await sharp(safePath, { limitInputPixels: 50000000 })23 unmodified lines24252627282930313233343536373839404142434445464748495031 unmodified lines82838485868788899091929343 unmodified lines13713813914014114214314414514614714823 unmodified linesconst upload = multer({storage,limits: { fileSize: 25 * 1024 * 1024 }});const extList = {img: ['.jpg', '.jpeg', '.png', '.webp', '.gif', '.svg', '.ico', '.bmp', '.tiff', '.tif', '.heic', '.heif'],audio: ['.mp3', '.wav', '.ogg', '.m4a', '.flac', '.opus'],video: ['.mp4', '.webm', '.mov', '.avi', '.mkv', '.wmv', '.flv', '.m4v'],doc: ['.pdf', '.doc', '.docx', '.xls', '.xlsx', '.ppt', '.pptx', '.txt', '.csv', '.rtf', '.odt', '.ods', '.odp'],archive: ['.zip', '.rar', '.7z', '.tar', '.gz', '.bz2', '.xz'],exe: ['.apk', '.exe', '.msi', '.dmg', '.iso', '.img'],data: ['.json', '.xml', '.yaml', '.yml', '.toml', '.ini', '.cfg', '.conf', '.log', '.sqlite', '.db'],font: ['.ttf', '.otf', '.woff', '.woff2', '.eot'],design: ['.psd', '.ai', '.eps'],model: ['.fbx', '.obj', '.stl', '.3ds', '.glb', '.gltf', '.blend'],ebook: ['.epub', '.mobi', '.fb2'],other: ['.dart', '.torrent', '.nfo', '.diz']};const allowedExts = Object.values(extList).flat();const imgExts = extList.img;const sharpExts = ['.jpg', '.jpeg', '.png', '.webp', '.tiff', '.tif', '.heic', '.heif'];const handleUploadSingle = (req, res, next) => {upload.single('file')(req, res, (err) => {if (err instanceof multer.MulterError) {31 unmodified linesconst ext = path.extname(cleanName).toLowerCase();finalPath = safePath;if (!allowedExts.includes(ext)) {if (fs.existsSync(safePath)) await fsPromises.unlink(safePath);return res.status(400).json({ error: st('Недопустимый формат файла', detectLangReq(req)) });}if (sharpExts.includes(ext)) {try {const tempPath = safePath + '_clean.webp';await sharp(safePath, { limitInputPixels: 50000000 }) // Увеличен лимит пикселей43 unmodified linesconst ext = path.extname(cleanName).toLowerCase();let finalPath = safePath;if (!allowedExts.includes(ext)) {if (fs.existsSync(safePath)) await fsPromises.unlink(safePath);continue;}if (sharpExts.includes(ext)) {try {const tempPath = safePath + '_clean.webp';await sharp(safePath, { limitInputPixels: 50000000 })
routes/upload.js+21-5