solo-export-fixer 0.0.0-stage → 0.1.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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +42 -2
  3. package/bin/fix.js +117 -0
  4. package/package.json +10 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 solo-export-fixer contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,43 @@
1
- # Temporary Holding Version
1
+ # solo-export-fixer
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Mozilla Solo shuts down on 2026-11-30. Its export ZIP contains your pages and text, but the images are only links. This tool downloads every linked image into the export and rewrites the links to point at the local copies.
4
+
5
+ ```
6
+ npx solo-export-fixer my-site-export.zip
7
+ ```
8
+
9
+ Run it while the image links still work.
10
+
11
+ ## What it does
12
+
13
+ 1. Opens the ZIP (or an already unzipped folder).
14
+ 2. Finds image URLs in HTML, CSS and CSV files: `src`, `srcset`, `poster`, `content`, `url(...)`.
15
+ 3. Downloads each image into `images/`.
16
+ 4. Rewrites the references to the local files and writes the result to `<name>-complete/`.
17
+ 5. Lists anything it could not download in `FAILED-DOWNLOADS.txt`.
18
+
19
+ The original export is never modified.
20
+
21
+ ## Options
22
+
23
+ ```
24
+ solo-export-fixer <export.zip | folder> [-o outDir] [--dry-run]
25
+ ```
26
+
27
+ - `-o outDir`: where to write the fixed copy.
28
+ - `--dry-run`: list the images it would download, change nothing.
29
+
30
+ Exit code is `0` when every image was saved and `2` when some failed.
31
+
32
+ ## Limits
33
+
34
+ - Tested on a synthetic export, not yet on a real Solo ZIP. If yours breaks it, please open an issue and attach the file list (not your content).
35
+ - Images hosted on Unsplash will likely keep working after the shutdown. A local copy still protects you if they move.
36
+ - It works on any export that links to remote images, not only Solo.
37
+ - Needs Node 18 or newer. No dependencies.
38
+
39
+ Not affiliated with Mozilla.
40
+
41
+ ## License
42
+
43
+ MIT
package/bin/fix.js ADDED
@@ -0,0 +1,117 @@
1
+ #!/usr/bin/env node
2
+ // solo-export-fixer: put the images back into a website export that only ships links to them.
3
+ // Zero dependencies. Usage: node bin/fix.js <export.zip | folder> [-o outDir] [--dry-run]
4
+ 'use strict';
5
+ const fs = require('fs'), path = require('path'), zlib = require('zlib'), crypto = require('crypto');
6
+
7
+ const IMG_EXT = /\.(png|jpe?g|gif|webp|avif|svg|ico|bmp)$/i;
8
+ const TEXT_EXT = /\.(html?|css|csv|json|txt|xml)$/i;
9
+
10
+ function readZip(buf) { // minimal ZIP reader (stored + deflate), reads the central directory
11
+ let e = buf.length - 22;
12
+ while (e >= 0 && buf.readUInt32LE(e) !== 0x06054b50) e--;
13
+ if (e < 0) throw new Error('Not a ZIP file');
14
+ const n = buf.readUInt16LE(e + 10); let p = buf.readUInt32LE(e + 16); const out = {};
15
+ for (let i = 0; i < n; i++) {
16
+ if (buf.readUInt32LE(p) !== 0x02014b50) throw new Error('Bad ZIP directory');
17
+ const method = buf.readUInt16LE(p + 10), csize = buf.readUInt32LE(p + 20);
18
+ const nl = buf.readUInt16LE(p + 28), el = buf.readUInt16LE(p + 30), cl = buf.readUInt16LE(p + 32);
19
+ const off = buf.readUInt32LE(p + 42), name = buf.slice(p + 46, p + 46 + nl).toString('utf8');
20
+ p += 46 + nl + el + cl;
21
+ if (name.endsWith('/')) continue;
22
+ const ds = off + 30 + buf.readUInt16LE(off + 26) + buf.readUInt16LE(off + 28);
23
+ const raw = buf.slice(ds, ds + csize);
24
+ if (method !== 0 && method !== 8) throw new Error('Unsupported ZIP compression in ' + name);
25
+ out[name] = method === 0 ? raw : zlib.inflateRawSync(raw);
26
+ }
27
+ return out;
28
+ }
29
+ function readDir(dir, base = dir, out = {}) {
30
+ for (const f of fs.readdirSync(dir, { withFileTypes: true })) {
31
+ const full = path.join(dir, f.name);
32
+ if (f.isDirectory()) readDir(full, base, out);
33
+ else out[path.relative(base, full).split(path.sep).join('/')] = fs.readFileSync(full);
34
+ }
35
+ return out;
36
+ }
37
+ const unescapeUrl = u => u.replace(/&amp;/g, '&');
38
+ function findUrls(name, text) { // returns the exact strings as they appear in the file
39
+ const found = new Set();
40
+ const all = text.match(/https?:\/\/[^\s"'<>)\\,]+/g) || [];
41
+ const isCsv = /\.csv$/i.test(name);
42
+ if (isCsv) { for (const u of all) found.add(u); return found; } // the image-link sheet: every URL counts
43
+ const attr = /(?:src|srcset|poster|data-src|content)\s*=\s*["']([^"']+)["']/gi; let m;
44
+ while ((m = attr.exec(text))) for (const part of m[1].split(/\s*,\s+/)) {
45
+ const u = part.trim().split(/\s+/)[0];
46
+ if (/^https?:\/\//.test(u) && (m[0].toLowerCase().startsWith('content') ? IMG_EXT.test(u.split('?')[0]) : true)) found.add(u);
47
+ }
48
+ const css = /url\(\s*["']?(https?:\/\/[^"')]+)["']?\s*\)/gi;
49
+ while ((m = css.exec(text))) found.add(m[1]);
50
+ for (const u of all) if (IMG_EXT.test(u.split(/[?#]/)[0])) found.add(u);
51
+ return found;
52
+ }
53
+ const EXT_BY_TYPE = { 'image/jpeg': '.jpg', 'image/png': '.png', 'image/gif': '.gif', 'image/webp': '.webp', 'image/avif': '.avif', 'image/svg+xml': '.svg', 'image/x-icon': '.ico', 'image/vnd.microsoft.icon': '.ico', 'image/bmp': '.bmp' };
54
+ async function download(url, tries = 3) {
55
+ for (let i = 1; ; i++) {
56
+ try {
57
+ const r = await fetch(url, { redirect: 'follow', signal: AbortSignal.timeout(30000), headers: { 'user-agent': 'solo-export-fixer' } });
58
+ if (!r.ok) throw new Error('HTTP ' + r.status);
59
+ const type = (r.headers.get('content-type') || '').split(';')[0].trim().toLowerCase();
60
+ return { type, body: Buffer.from(await r.arrayBuffer()) };
61
+ } catch (err) { if (i >= tries) throw err; await new Promise(s => setTimeout(s, 800 * i)); }
62
+ }
63
+ }
64
+ async function main() {
65
+ const args = process.argv.slice(2);
66
+ const dry = args.includes('--dry-run');
67
+ const oi = args.indexOf('-o');
68
+ const input = args.find((a, i) => !a.startsWith('-') && (oi < 0 || i !== oi + 1));
69
+ if (!input) { console.log('Usage: solo-export-fixer <export.zip | folder> [-o outDir] [--dry-run]'); process.exit(1); }
70
+ const outDir = oi >= 0 ? args[oi + 1] : input.replace(/\.zip$/i, '').replace(/[\\/]+$/, '') + '-complete';
71
+ const files = fs.statSync(input).isDirectory() ? readDir(input) : readZip(fs.readFileSync(input));
72
+ const names = Object.keys(files);
73
+ const texts = names.filter(n => TEXT_EXT.test(n));
74
+ const seen = new Map(); // clean url -> { raws:Set, local }
75
+ for (const n of texts) for (const raw of findUrls(n, files[n].toString('utf8'))) {
76
+ const clean = unescapeUrl(raw);
77
+ if (!seen.has(clean)) seen.set(clean, { raws: new Set(), local: null });
78
+ seen.get(clean).raws.add(raw);
79
+ }
80
+ console.log(`${names.length} files in the export, ${seen.size} linked files to fetch.`);
81
+ if (dry) { for (const u of seen.keys()) console.log(' ' + u); return; }
82
+ const failed = []; let ok = 0, skipped = 0; const queue = [...seen.entries()];
83
+ async function worker() {
84
+ for (let item; (item = queue.shift());) {
85
+ const [url, rec] = item;
86
+ try {
87
+ const { type, body } = await download(url);
88
+ const urlExt = (path.extname(new URL(url).pathname).match(IMG_EXT) || [''])[0].toLowerCase();
89
+ if (!type.startsWith('image/') && !urlExt) { skipped++; continue; } // a page link, not an image
90
+ const ext = EXT_BY_TYPE[type] || urlExt || '.bin';
91
+ const stem = path.basename(new URL(url).pathname, path.extname(new URL(url).pathname)).replace(/[^a-zA-Z0-9_-]+/g, '-').slice(0, 40) || 'image';
92
+ rec.local = `images/${stem}-${crypto.createHash('sha1').update(url).digest('hex').slice(0, 8)}${ext}`;
93
+ files[rec.local] = body; ok++;
94
+ } catch (err) { failed.push([url, err.message]); }
95
+ }
96
+ }
97
+ await Promise.all(Array.from({ length: 6 }, worker));
98
+ const pairs = [];
99
+ for (const rec of seen.values()) if (rec.local) for (const raw of rec.raws) pairs.push([raw, rec.local]);
100
+ pairs.sort((a, b) => b[0].length - a[0].length); // longest first so a URL never clobbers a longer one
101
+ for (const n of texts) {
102
+ if (/\.csv$/i.test(n)) continue; // keep the original sheet as a record
103
+ let t = files[n].toString('utf8'); const depth = n.split('/').length - 1;
104
+ for (const [raw, local] of pairs) t = t.split(raw).join('../'.repeat(depth) + local);
105
+ files[n] = Buffer.from(t);
106
+ }
107
+ for (const [n, b] of Object.entries(files)) {
108
+ const dest = path.join(outDir, n);
109
+ if (!path.resolve(dest).startsWith(path.resolve(outDir) + path.sep)) continue; // never write outside outDir
110
+ fs.mkdirSync(path.dirname(dest), { recursive: true }); fs.writeFileSync(dest, b);
111
+ }
112
+ if (failed.length) fs.writeFileSync(path.join(outDir, 'FAILED-DOWNLOADS.txt'), failed.map(f => f.join('\t')).join('\n') + '\n');
113
+ console.log(`Saved ${ok} images, ${failed.length} failed, ${skipped} non-image links left alone.`);
114
+ console.log(`Complete site written to: ${outDir}`);
115
+ if (failed.length) { console.log('See FAILED-DOWNLOADS.txt for the links that could not be fetched.'); process.exitCode = 2; }
116
+ }
117
+ main().then(() => process.exit(process.exitCode || 0), e => { console.error('Error: ' + e.message); process.exit(1); });
package/package.json CHANGED
@@ -1,6 +1,12 @@
1
1
  {
2
2
  "name": "solo-export-fixer",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Put the images back into a website export that only ships links to them (Mozilla Solo, shuts down 2026-11-30).",
5
+ "bin": { "solo-export-fixer": "bin/fix.js" },
6
+ "files": ["bin", "README.md", "LICENSE"],
7
+ "scripts": { "test": "node bin/fix.js test/sample.zip -o test/out; test $? -eq 2 && test -d test/out/images" },
8
+ "engines": { "node": ">=18" },
9
+ "keywords": ["mozilla-solo", "solo", "website-export", "export", "images", "backup", "migration"],
10
+ "repository": { "type": "git", "url": "git+https://github.com/fengyiqicoder/solo-export-fixer.git" },
11
+ "license": "MIT"
12
+ }