Skip to content

Commit

Permalink
chore: inform uploader of zip uploads with no valid files
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Alemayhu <[email protected]>
  • Loading branch information
aalemayhu committed Dec 31, 2024
1 parent 7f8a14d commit 4181650
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 40 deletions.
27 changes: 17 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
"morgan": "^1.10.0",
"multer": "^1.4.4-lts.1",
"pg": "^8.11.3",
"react": "^18.2.0",
"react-dom": "^19.0.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"showdown": "^2.1.0",
"stripe": "^16.8.0",
"xlsx": "^0.18.5"
Expand Down
27 changes: 0 additions & 27 deletions src/lib/parser/ParserRules.test.ts

This file was deleted.

5 changes: 5 additions & 0 deletions src/lib/storage/checks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,8 @@ export const isImageFile = (name: string) =>
name.toLowerCase().endsWith('.svg'));

export const isXLSXFile = (fileName: string) => /.xlsx$/i.test(fileName);

export const isHiddenFileOrDirectory = (fileName: string) =>
fileName.startsWith('.') ||
fileName.endsWith('/') ||
fileName.startsWith('__MACOSX');
15 changes: 14 additions & 1 deletion src/lib/zip/zip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Body } from 'aws-sdk/clients/s3';
import { renderToStaticMarkup } from 'react-dom/server';
import { getUploadLimits } from '../misc/getUploadLimits';
import {
isHiddenFileOrDirectory,
isHTMLFile,
isImageFile,
isMarkdownFile,
Expand Down Expand Up @@ -62,14 +63,26 @@ class ZipHandler {

try {
const loadedZip = unzipSync(zipData, {
filter: (file) => !file.name.endsWith('/'),
filter: (file) => !isHiddenFileOrDirectory(file.name),
});

let noSuffixCount = 0;
const totalFiles = Object.keys(loadedZip).length;

for (const name in loadedZip) {
const file = loadedZip[name];
if (!name.includes('.')) {
noSuffixCount++;
}
await this.handleFile(name, file, paying, settings);
}

if (noSuffixCount === totalFiles) {
throw new Error(
'The zip file contains only files with no suffix. Supported file types are: .zip, .html, .csv, .md, .pdf, .ppt, and .pptx.'
);
}

this.addCombinedHTMLToFiles(paying, settings);
} catch (error: unknown) {
await this.handleZipError(error, zipData, paying);
Expand Down

0 comments on commit 4181650

Please sign in to comment.