@ponderdev/justfits 1.3.0 → 1.4.0

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/src/scan.cjs CHANGED
@@ -11,9 +11,12 @@
11
11
  * and the probe says whether it can be read.
12
12
  */
13
13
 
14
+ const fs = require('node:fs');
15
+ const path = require('node:path');
14
16
  const kit = require('./kit/scan.cjs');
15
17
 
16
- const EXTENSIONS = new Set(['.mp4', '.mov', '.m4v', '.mkv', '.webm', '.avi', '.jpg', '.jpeg', '.png', '.heic', '.webp', '.gif']);
18
+ const EXTENSIONS = new Set(['.mp4', '.mov', '.m4v', '.mkv', '.webm', '.avi', '.jpg', '.jpeg', '.png', '.heic', '.webp', '.gif',
19
+ '.mp3', '.m4a', '.aac', '.wav', '.flac', '.ogg', '.opus', '.aif', '.aiff']);
17
20
  const OURS = /-fits( \d+)?$/i;
18
21
 
19
22
  // What it did, for a folder's results folder: "Holiday (fitted)".
@@ -40,4 +43,38 @@ function places({ beside = false } = {}) {
40
43
  };
41
44
  }
42
45
 
43
- module.exports = { scan, places, EXTENSIONS, WORD };
46
+ /*
47
+ * Whether a folder named holds anything Just Fits passes over for not being a
48
+ * video or picture (a PDF, a document, an archive), so the window can point
49
+ * to Just Zip for sending them as one file. Hidden files, a Mac's
50
+ * "._name" files, Just Fits' own results and results folders are not counted,
51
+ * as the walk does not take them either. It stops at the first one, looks at
52
+ * no more than a few thousand entries, and never throws.
53
+ */
54
+ async function others(paths) {
55
+ const results = new RegExp(` \\(${WORD}\\)( \\d+)?$`, 'i');
56
+ let looked = 0;
57
+ async function walk(dir) {
58
+ let entries;
59
+ try { entries = await fs.promises.readdir(dir, { withFileTypes: true }); } catch { return false; }
60
+ for (const entry of entries) {
61
+ if (++looked > 5000) return false;
62
+ if (entry.name.startsWith('.')) continue;
63
+ const full = path.join(dir, entry.name);
64
+ if (entry.isDirectory()) {
65
+ if (!results.test(entry.name) && await walk(full)) return true;
66
+ } else if (entry.isFile() && !EXTENSIONS.has(path.extname(entry.name).toLowerCase()) && !OURS.test(path.parse(entry.name).name)) {
67
+ return true;
68
+ }
69
+ }
70
+ return false;
71
+ }
72
+ for (const p of paths) {
73
+ let stat;
74
+ try { stat = await fs.promises.stat(p); } catch { continue; }
75
+ if (stat.isDirectory() && await walk(p)) return true;
76
+ }
77
+ return false;
78
+ }
79
+
80
+ module.exports = { scan, places, others, EXTENSIONS, WORD };