@shipstatic/drop 2.16.1-beta.7 → 2.16.1-beta.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -204,7 +204,7 @@ ShipStatic's own apps send a project to be built. That isn't part of the public
204
204
 
205
205
  ## ZIP handling
206
206
 
207
- A **single** dropped ZIP is extracted and its contents deployed. ZIPs among several files are treated as ordinary files. Archive paths are sanitized against directory traversal (`../../config.json` → `config.json`).
207
+ A **single** dropped ZIP is extracted and its contents deployed. ZIPs among several files are treated as ordinary files. Archive paths are sanitized against directory traversal (`../../config.json` → `config.json`). A ZIP that can't be read or opened is an error that names it.
208
208
 
209
209
  ## Without React
210
210
 
package/dist/index.cjs CHANGED
@@ -121,7 +121,7 @@ function setRelativePath(file, path) {
121
121
  });
122
122
  }
123
123
  function filePath(file) {
124
- return file.webkitRelativePath?.trim() || file.name;
124
+ return file.webkitRelativePath || file.name;
125
125
  }
126
126
  function createProcessedFile(file, options) {
127
127
  const path = options?.path || filePath(file);
@@ -821,34 +821,34 @@ function unzip(data, opts, cb) {
821
821
 
822
822
  // src/zip.ts
823
823
  async function extractZipToFiles(zipFile) {
824
- try {
825
- const bytes = new Uint8Array(await zipFile.arrayBuffer());
826
- const entries = await new Promise((resolve, reject) => {
827
- unzip(bytes, (err2, data) => err2 ? reject(err2) : resolve(data));
828
- });
829
- const files = [];
830
- const errors = [];
831
- for (const [path, data] of Object.entries(entries)) {
832
- if (path.endsWith("/") && data.length === 0) continue;
833
- const sanitizedPath = normalizePath(path);
834
- if (!sanitizedPath) {
835
- errors.push(`Skipped invalid path: ${path}`);
836
- continue;
837
- }
838
- const filename = sanitizedPath.split("/").pop() || sanitizedPath;
839
- const file = new File([new Uint8Array(data)], filename);
840
- setRelativePath(file, sanitizedPath);
841
- files.push(file);
824
+ const bytes = new Uint8Array(
825
+ await zipFile.arrayBuffer().catch(() => {
826
+ throw new Error(ship.unreadable(zipFile.name));
827
+ })
828
+ );
829
+ const entries = await new Promise((resolve, reject) => {
830
+ unzip(
831
+ bytes,
832
+ (err2, data) => err2 ? reject(
833
+ new Error(`We couldn't open ${zipFile.name}. It may be damaged, or not a ZIP file.`)
834
+ ) : resolve(data)
835
+ );
836
+ });
837
+ const files = [];
838
+ const errors = [];
839
+ for (const [path, data] of Object.entries(entries)) {
840
+ if (path.endsWith("/") && data.length === 0) continue;
841
+ const sanitizedPath = normalizePath(path);
842
+ if (!sanitizedPath) {
843
+ errors.push(`Skipped invalid path: ${path}`);
844
+ continue;
842
845
  }
843
- return { files, errors };
844
- } catch (error) {
845
- return {
846
- files: [],
847
- errors: [
848
- `Failed to load ZIP file: ${error instanceof Error ? error.message : String(error)}`
849
- ]
850
- };
846
+ const filename = sanitizedPath.split("/").pop() || sanitizedPath;
847
+ const file = new File([new Uint8Array(data)], filename);
848
+ setRelativePath(file, sanitizedPath);
849
+ files.push(file);
851
850
  }
851
+ return { files, errors };
852
852
  }
853
853
  function normalizePath(path) {
854
854
  const normalized = [];
@@ -1107,7 +1107,7 @@ function useDrop({ ship }) {
1107
1107
  setState((prev) => prev.isDragging ? { ...prev, isDragging: false } : prev);
1108
1108
  const files = [];
1109
1109
  const directories = [];
1110
- let unreadable2 = false;
1110
+ let unreadable3 = false;
1111
1111
  for (const item of Array.from(e.dataTransfer.items)) {
1112
1112
  if (item.kind !== "file") continue;
1113
1113
  let entry;
@@ -1124,12 +1124,12 @@ function useDrop({ ship }) {
1124
1124
  setRelativePath(file, file.name);
1125
1125
  files.push(file);
1126
1126
  } else {
1127
- unreadable2 = true;
1127
+ unreadable3 = true;
1128
1128
  }
1129
1129
  }
1130
- if (directories.length === 0 && files.length === 0 && !unreadable2) return;
1130
+ if (directories.length === 0 && files.length === 0 && !unreadable3) return;
1131
1131
  await prepare(async () => {
1132
- if (unreadable2) throw new Error(UNREADABLE_DROP);
1132
+ if (unreadable3) throw new Error(UNREADABLE_DROP);
1133
1133
  await Promise.all(directories.map((d) => traverseFileTree(d.entry, files, d.path)));
1134
1134
  return files;
1135
1135
  });