@willwade/aac-processors 0.1.5 → 0.1.7
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 +14 -0
- package/dist/browser/index.browser.js +15 -1
- package/dist/browser/processors/gridset/password.js +11 -0
- package/dist/browser/processors/gridsetProcessor.js +42 -46
- package/dist/browser/processors/obfProcessor.js +47 -63
- package/dist/browser/processors/snapProcessor.js +1031 -0
- package/dist/browser/processors/touchchatProcessor.js +1004 -0
- package/dist/browser/utils/io.js +36 -2
- package/dist/browser/utils/sqlite.js +109 -0
- package/dist/browser/utils/zip.js +54 -0
- package/dist/browser/validation/gridsetValidator.js +7 -27
- package/dist/browser/validation/obfValidator.js +9 -4
- package/dist/browser/validation/snapValidator.js +197 -0
- package/dist/browser/validation/touchChatValidator.js +201 -0
- package/dist/index.browser.d.ts +7 -0
- package/dist/index.browser.js +19 -2
- package/dist/processors/gridset/helpers.js +3 -4
- package/dist/processors/gridset/index.d.ts +1 -1
- package/dist/processors/gridset/index.js +3 -2
- package/dist/processors/gridset/password.d.ts +3 -2
- package/dist/processors/gridset/password.js +12 -0
- package/dist/processors/gridset/wordlistHelpers.js +107 -51
- package/dist/processors/gridsetProcessor.js +40 -44
- package/dist/processors/obfProcessor.js +46 -62
- package/dist/processors/snapProcessor.js +60 -54
- package/dist/processors/touchchatProcessor.js +38 -36
- package/dist/utils/io.d.ts +4 -0
- package/dist/utils/io.js +40 -2
- package/dist/utils/sqlite.d.ts +21 -0
- package/dist/utils/sqlite.js +137 -0
- package/dist/utils/zip.d.ts +7 -0
- package/dist/utils/zip.js +80 -0
- package/dist/validation/applePanelsValidator.js +11 -28
- package/dist/validation/astericsValidator.js +11 -30
- package/dist/validation/dotValidator.js +11 -30
- package/dist/validation/excelValidator.js +5 -6
- package/dist/validation/gridsetValidator.js +29 -26
- package/dist/validation/index.d.ts +2 -1
- package/dist/validation/index.js +9 -32
- package/dist/validation/obfValidator.js +8 -3
- package/dist/validation/obfsetValidator.js +11 -30
- package/dist/validation/opmlValidator.js +11 -30
- package/dist/validation/snapValidator.js +6 -9
- package/dist/validation/touchChatValidator.js +6 -7
- package/docs/BROWSER_USAGE.md +2 -10
- package/examples/README.md +3 -75
- package/examples/vitedemo/README.md +13 -7
- package/examples/vitedemo/index.html +51 -2
- package/examples/vitedemo/package-lock.json +9 -0
- package/examples/vitedemo/package.json +1 -0
- package/examples/vitedemo/src/main.ts +132 -2
- package/examples/vitedemo/src/vite-env.d.ts +1 -0
- package/examples/vitedemo/vite.config.ts +26 -7
- package/package.json +3 -1
- package/examples/browser-test-server.js +0 -81
|
@@ -1,49 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.DotValidator = void 0;
|
|
27
4
|
/* eslint-disable @typescript-eslint/require-await */
|
|
28
|
-
const fs = __importStar(require("fs"));
|
|
29
|
-
const path = __importStar(require("path"));
|
|
30
5
|
const baseValidator_1 = require("./baseValidator");
|
|
6
|
+
const io_1 = require("../utils/io");
|
|
31
7
|
/**
|
|
32
8
|
* Validator for Graphviz DOT files
|
|
33
9
|
*/
|
|
34
10
|
class DotValidator extends baseValidator_1.BaseValidator {
|
|
35
11
|
static async validateFile(filePath) {
|
|
36
12
|
const validator = new DotValidator();
|
|
37
|
-
const content =
|
|
38
|
-
const stats =
|
|
39
|
-
return validator.validate(content,
|
|
13
|
+
const content = (0, io_1.readBinaryFromInput)(filePath);
|
|
14
|
+
const stats = (0, io_1.getFs)().statSync(filePath);
|
|
15
|
+
return validator.validate(content, (0, io_1.getBasename)(filePath), stats.size);
|
|
40
16
|
}
|
|
41
17
|
static async identifyFormat(content, filename) {
|
|
42
18
|
const name = filename.toLowerCase();
|
|
43
19
|
if (name.endsWith('.dot'))
|
|
44
20
|
return true;
|
|
45
21
|
try {
|
|
46
|
-
|
|
22
|
+
if (typeof content !== 'string' &&
|
|
23
|
+
!(content instanceof ArrayBuffer) &&
|
|
24
|
+
!(content instanceof Uint8Array)) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
const str = typeof content === 'string' ? content : (0, io_1.decodeText)((0, io_1.toUint8Array)(content));
|
|
47
28
|
return str.includes('digraph') || str.includes('->');
|
|
48
29
|
}
|
|
49
30
|
catch {
|
|
@@ -59,7 +40,7 @@ class DotValidator extends baseValidator_1.BaseValidator {
|
|
|
59
40
|
});
|
|
60
41
|
let text = '';
|
|
61
42
|
await this.add_check('text', 'text content', async () => {
|
|
62
|
-
text =
|
|
43
|
+
text = (0, io_1.decodeText)(content);
|
|
63
44
|
if (!text.trim()) {
|
|
64
45
|
this.err('DOT file is empty', true);
|
|
65
46
|
}
|
|
@@ -25,19 +25,18 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.ExcelValidator = void 0;
|
|
27
27
|
/* eslint-disable @typescript-eslint/require-await */
|
|
28
|
-
const fs = __importStar(require("fs"));
|
|
29
|
-
const path = __importStar(require("path"));
|
|
30
28
|
const ExcelJS = __importStar(require("exceljs"));
|
|
31
29
|
const baseValidator_1 = require("./baseValidator");
|
|
30
|
+
const io_1 = require("../utils/io");
|
|
32
31
|
/**
|
|
33
32
|
* Validator for Excel imports (.xlsx/.xls)
|
|
34
33
|
*/
|
|
35
34
|
class ExcelValidator extends baseValidator_1.BaseValidator {
|
|
36
35
|
static async validateFile(filePath) {
|
|
37
36
|
const validator = new ExcelValidator();
|
|
38
|
-
const content =
|
|
39
|
-
const stats =
|
|
40
|
-
return validator.validate(content,
|
|
37
|
+
const content = (0, io_1.readBinaryFromInput)(filePath);
|
|
38
|
+
const stats = (0, io_1.getFs)().statSync(filePath);
|
|
39
|
+
return validator.validate(content, (0, io_1.getBasename)(filePath), stats.size);
|
|
41
40
|
}
|
|
42
41
|
static async identifyFormat(_content, filename) {
|
|
43
42
|
const name = filename.toLowerCase();
|
|
@@ -58,7 +57,7 @@ class ExcelValidator extends baseValidator_1.BaseValidator {
|
|
|
58
57
|
});
|
|
59
58
|
return this.buildResult(filename, filesize, 'excel');
|
|
60
59
|
}
|
|
61
|
-
const buffer = Buffer.isBuffer(content) ? content :
|
|
60
|
+
const buffer = typeof Buffer !== 'undefined' && Buffer.isBuffer(content) ? content : (0, io_1.toArrayBuffer)(content);
|
|
62
61
|
const workbook = new ExcelJS.Workbook();
|
|
63
62
|
await this.add_check('open', 'open workbook', async () => {
|
|
64
63
|
try {
|
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
@@ -8,24 +31,9 @@ exports.GridsetValidator = void 0;
|
|
|
8
31
|
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
9
32
|
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
10
33
|
const jszip_1 = __importDefault(require("jszip"));
|
|
34
|
+
const xml2js = __importStar(require("xml2js"));
|
|
11
35
|
const baseValidator_1 = require("./baseValidator");
|
|
12
36
|
const io_1 = require("../utils/io");
|
|
13
|
-
let cachedXml2js = null;
|
|
14
|
-
function getXml2js() {
|
|
15
|
-
if (cachedXml2js)
|
|
16
|
-
return cachedXml2js;
|
|
17
|
-
try {
|
|
18
|
-
const nodeRequire = (0, io_1.getNodeRequire)();
|
|
19
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
20
|
-
const module = nodeRequire('xml2js');
|
|
21
|
-
const resolved = module.default || module;
|
|
22
|
-
cachedXml2js = resolved;
|
|
23
|
-
return resolved;
|
|
24
|
-
}
|
|
25
|
-
catch {
|
|
26
|
-
throw new Error('Validator requires Xml2js in this environment.');
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
37
|
/**
|
|
30
38
|
* Validator for Grid3/Smartbox Gridset files (.gridset, .gridsetx)
|
|
31
39
|
*/
|
|
@@ -39,10 +47,9 @@ class GridsetValidator extends baseValidator_1.BaseValidator {
|
|
|
39
47
|
static async validateFile(filePath) {
|
|
40
48
|
const validator = new GridsetValidator();
|
|
41
49
|
const fs = (0, io_1.getFs)();
|
|
42
|
-
const path = (0, io_1.getPath)();
|
|
43
50
|
const content = fs.readFileSync(filePath);
|
|
44
51
|
const stats = fs.statSync(filePath);
|
|
45
|
-
return validator.validate(content,
|
|
52
|
+
return validator.validate(content, (0, io_1.getBasename)(filePath), stats.size);
|
|
46
53
|
}
|
|
47
54
|
/**
|
|
48
55
|
* Check if content is Gridset format
|
|
@@ -54,8 +61,7 @@ class GridsetValidator extends baseValidator_1.BaseValidator {
|
|
|
54
61
|
}
|
|
55
62
|
// Try to parse as XML and check for gridset structure
|
|
56
63
|
try {
|
|
57
|
-
const contentStr =
|
|
58
|
-
const xml2js = getXml2js();
|
|
64
|
+
const contentStr = typeof content === 'string' ? content : (0, io_1.decodeText)((0, io_1.toUint8Array)(content));
|
|
59
65
|
const parser = new xml2js.Parser();
|
|
60
66
|
const result = await parser.parseStringPromise(contentStr);
|
|
61
67
|
return result && (result.gridset || result.Gridset);
|
|
@@ -108,9 +114,8 @@ class GridsetValidator extends baseValidator_1.BaseValidator {
|
|
|
108
114
|
let xmlObj = null;
|
|
109
115
|
await this.add_check('xml_parse', 'valid XML', async () => {
|
|
110
116
|
try {
|
|
111
|
-
const xml2js = getXml2js();
|
|
112
117
|
const parser = new xml2js.Parser();
|
|
113
|
-
const contentStr =
|
|
118
|
+
const contentStr = (0, io_1.decodeText)(content);
|
|
114
119
|
xmlObj = await parser.parseStringPromise(contentStr);
|
|
115
120
|
}
|
|
116
121
|
catch (e) {
|
|
@@ -135,7 +140,7 @@ class GridsetValidator extends baseValidator_1.BaseValidator {
|
|
|
135
140
|
async validateZipArchive(content, filename, _filesize) {
|
|
136
141
|
let zip;
|
|
137
142
|
try {
|
|
138
|
-
zip = await jszip_1.default.loadAsync(
|
|
143
|
+
zip = await jszip_1.default.loadAsync((0, io_1.toUint8Array)(content));
|
|
139
144
|
}
|
|
140
145
|
catch (e) {
|
|
141
146
|
this.err(`Failed to open ZIP archive: ${e.message}`, true);
|
|
@@ -151,7 +156,6 @@ class GridsetValidator extends baseValidator_1.BaseValidator {
|
|
|
151
156
|
else {
|
|
152
157
|
try {
|
|
153
158
|
const gridsetXml = await gridsetEntry.async('string');
|
|
154
|
-
const xml2js = getXml2js();
|
|
155
159
|
const parser = new xml2js.Parser();
|
|
156
160
|
const xmlObj = await parser.parseStringPromise(gridsetXml);
|
|
157
161
|
const gridset = xmlObj.gridset || xmlObj.Gridset;
|
|
@@ -159,7 +163,7 @@ class GridsetValidator extends baseValidator_1.BaseValidator {
|
|
|
159
163
|
this.err('Invalid gridset.xml structure', true);
|
|
160
164
|
}
|
|
161
165
|
else {
|
|
162
|
-
await this.validateGridsetStructure(gridset, filename,
|
|
166
|
+
await this.validateGridsetStructure(gridset, filename, new Uint8Array());
|
|
163
167
|
}
|
|
164
168
|
}
|
|
165
169
|
catch (e) {
|
|
@@ -176,7 +180,6 @@ class GridsetValidator extends baseValidator_1.BaseValidator {
|
|
|
176
180
|
else {
|
|
177
181
|
try {
|
|
178
182
|
const settingsXml = await settingsEntry.async('string');
|
|
179
|
-
const xml2js = getXml2js();
|
|
180
183
|
const parser = new xml2js.Parser();
|
|
181
184
|
const xmlObj = await parser.parseStringPromise(settingsXml);
|
|
182
185
|
const settings = xmlObj.GridSetSettings || xmlObj.gridSetSettings || xmlObj.GridsetSettings;
|
|
@@ -16,6 +16,7 @@ export { ApplePanelsValidator } from './applePanelsValidator';
|
|
|
16
16
|
export { ObfsetValidator } from './obfsetValidator';
|
|
17
17
|
import { BaseValidator } from './baseValidator';
|
|
18
18
|
import { ValidationResult } from './validationTypes';
|
|
19
|
+
import { type ProcessorInput } from '../utils/io';
|
|
19
20
|
export declare function getValidatorForFormat(format: string): BaseValidator | null;
|
|
20
21
|
export declare function getValidatorForFile(filename: string): BaseValidator | null;
|
|
21
22
|
/**
|
|
@@ -23,4 +24,4 @@ export declare function getValidatorForFile(filename: string): BaseValidator | n
|
|
|
23
24
|
* When a file path is provided, any validator-specific validateFile() helper
|
|
24
25
|
* will be used if available to access nested resources.
|
|
25
26
|
*/
|
|
26
|
-
export declare function validateFileOrBuffer(filePathOrBuffer:
|
|
27
|
+
export declare function validateFileOrBuffer(filePathOrBuffer: ProcessorInput, filenameHint?: string): Promise<ValidationResult>;
|
package/dist/validation/index.js
CHANGED
|
@@ -3,29 +3,6 @@
|
|
|
3
3
|
* Validation system for AAC processors
|
|
4
4
|
* Provides consistent validation across all supported formats
|
|
5
5
|
*/
|
|
6
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
-
if (k2 === undefined) k2 = k;
|
|
8
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
-
}
|
|
12
|
-
Object.defineProperty(o, k2, desc);
|
|
13
|
-
}) : (function(o, m, k, k2) {
|
|
14
|
-
if (k2 === undefined) k2 = k;
|
|
15
|
-
o[k2] = m[k];
|
|
16
|
-
}));
|
|
17
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
-
}) : function(o, v) {
|
|
20
|
-
o["default"] = v;
|
|
21
|
-
});
|
|
22
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
23
|
-
if (mod && mod.__esModule) return mod;
|
|
24
|
-
var result = {};
|
|
25
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
26
|
-
__setModuleDefault(result, mod);
|
|
27
|
-
return result;
|
|
28
|
-
};
|
|
29
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
7
|
exports.ObfsetValidator = exports.ApplePanelsValidator = exports.DotValidator = exports.OpmlValidator = exports.ExcelValidator = exports.AstericsGridValidator = exports.TouchChatValidator = exports.SnapValidator = exports.GridsetValidator = exports.ObfValidator = exports.BaseValidator = exports.buildValidationResultFromMessage = exports.ValidationFailureError = exports.ValidationError = void 0;
|
|
31
8
|
exports.getValidatorForFormat = getValidatorForFormat;
|
|
@@ -72,8 +49,7 @@ const opmlValidator_2 = require("./opmlValidator");
|
|
|
72
49
|
const dotValidator_2 = require("./dotValidator");
|
|
73
50
|
const applePanelsValidator_2 = require("./applePanelsValidator");
|
|
74
51
|
const obfsetValidator_2 = require("./obfsetValidator");
|
|
75
|
-
const
|
|
76
|
-
const path = __importStar(require("path"));
|
|
52
|
+
const io_1 = require("../utils/io");
|
|
77
53
|
function getValidatorForFormat(format) {
|
|
78
54
|
switch (format.toLowerCase()) {
|
|
79
55
|
case 'obf':
|
|
@@ -151,22 +127,23 @@ function getValidatorForFile(filename) {
|
|
|
151
127
|
*/
|
|
152
128
|
async function validateFileOrBuffer(filePathOrBuffer, filenameHint) {
|
|
153
129
|
const isPath = typeof filePathOrBuffer === 'string';
|
|
154
|
-
const name = filenameHint || (isPath ?
|
|
130
|
+
const name = filenameHint || (isPath ? (0, io_1.getBasename)(filePathOrBuffer) : 'upload');
|
|
155
131
|
const validator = getValidatorForFile(name) || getValidatorForFormat(name);
|
|
156
132
|
if (!validator) {
|
|
157
133
|
throw new Error(`No validator registered for ${name}`);
|
|
158
134
|
}
|
|
159
135
|
if (isPath) {
|
|
136
|
+
if (!(0, io_1.isNodeRuntime)()) {
|
|
137
|
+
throw new Error('File path validation is only supported in Node.js environments.');
|
|
138
|
+
}
|
|
160
139
|
const ctor = validator.constructor;
|
|
161
140
|
if (typeof ctor.validateFile === 'function') {
|
|
162
141
|
return ctor.validateFile(filePathOrBuffer);
|
|
163
142
|
}
|
|
164
|
-
const buf =
|
|
165
|
-
const stats =
|
|
166
|
-
return validator.validate(buf,
|
|
143
|
+
const buf = (0, io_1.readBinaryFromInput)(filePathOrBuffer);
|
|
144
|
+
const stats = (0, io_1.getFs)().statSync(filePathOrBuffer);
|
|
145
|
+
return validator.validate(buf, (0, io_1.getBasename)(filePathOrBuffer), stats.size);
|
|
167
146
|
}
|
|
168
|
-
const buffer =
|
|
169
|
-
? filePathOrBuffer
|
|
170
|
-
: Buffer.from(filePathOrBuffer);
|
|
147
|
+
const buffer = (0, io_1.toUint8Array)(filePathOrBuffer);
|
|
171
148
|
return validator.validate(buffer, name, buffer.byteLength);
|
|
172
149
|
}
|
|
@@ -28,7 +28,7 @@ class ObfValidator extends baseValidator_1.BaseValidator {
|
|
|
28
28
|
const validator = new ObfValidator();
|
|
29
29
|
const content = (0, io_1.readBinaryFromInput)(filePath);
|
|
30
30
|
const stats = (0, io_1.getFs)().statSync(filePath);
|
|
31
|
-
return validator.validate(content, (0, io_1.
|
|
31
|
+
return validator.validate(content, (0, io_1.getBasename)(filePath), stats.size);
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
34
|
* Check if content is OBF format
|
|
@@ -40,7 +40,12 @@ class ObfValidator extends baseValidator_1.BaseValidator {
|
|
|
40
40
|
}
|
|
41
41
|
// Try to parse as JSON and check format
|
|
42
42
|
try {
|
|
43
|
-
|
|
43
|
+
if (typeof content !== 'string' &&
|
|
44
|
+
!(content instanceof ArrayBuffer) &&
|
|
45
|
+
!(content instanceof Uint8Array)) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
const contentStr = typeof content === 'string' ? content : (0, io_1.decodeText)((0, io_1.toUint8Array)(content));
|
|
44
49
|
const json = JSON.parse(contentStr);
|
|
45
50
|
return json && json.format && json.format.startsWith('open-board-');
|
|
46
51
|
}
|
|
@@ -74,7 +79,7 @@ class ObfValidator extends baseValidator_1.BaseValidator {
|
|
|
74
79
|
let json = null;
|
|
75
80
|
await this.add_check('valid_json', 'JSON file', async () => {
|
|
76
81
|
try {
|
|
77
|
-
json = JSON.parse(
|
|
82
|
+
json = JSON.parse((0, io_1.decodeText)(content));
|
|
78
83
|
}
|
|
79
84
|
catch {
|
|
80
85
|
this.err("Couldn't parse as JSON", true);
|
|
@@ -1,49 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.ObfsetValidator = void 0;
|
|
27
4
|
/* eslint-disable @typescript-eslint/require-await */
|
|
28
|
-
const fs = __importStar(require("fs"));
|
|
29
|
-
const path = __importStar(require("path"));
|
|
30
5
|
const baseValidator_1 = require("./baseValidator");
|
|
6
|
+
const io_1 = require("../utils/io");
|
|
31
7
|
/**
|
|
32
8
|
* Validator for OBF set bundles (.obfset) - JSON arrays of boards
|
|
33
9
|
*/
|
|
34
10
|
class ObfsetValidator extends baseValidator_1.BaseValidator {
|
|
35
11
|
static async validateFile(filePath) {
|
|
36
12
|
const validator = new ObfsetValidator();
|
|
37
|
-
const content =
|
|
38
|
-
const stats =
|
|
39
|
-
return validator.validate(content,
|
|
13
|
+
const content = (0, io_1.readBinaryFromInput)(filePath);
|
|
14
|
+
const stats = (0, io_1.getFs)().statSync(filePath);
|
|
15
|
+
return validator.validate(content, (0, io_1.getBasename)(filePath), stats.size);
|
|
40
16
|
}
|
|
41
17
|
static async identifyFormat(content, filename) {
|
|
42
18
|
const name = filename.toLowerCase();
|
|
43
19
|
if (name.endsWith('.obfset'))
|
|
44
20
|
return true;
|
|
45
21
|
try {
|
|
46
|
-
|
|
22
|
+
if (typeof content !== 'string' &&
|
|
23
|
+
!(content instanceof ArrayBuffer) &&
|
|
24
|
+
!(content instanceof Uint8Array)) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
const str = typeof content === 'string' ? content : (0, io_1.decodeText)((0, io_1.toUint8Array)(content));
|
|
47
28
|
const parsed = JSON.parse(str);
|
|
48
29
|
return Array.isArray(parsed);
|
|
49
30
|
}
|
|
@@ -61,7 +42,7 @@ class ObfsetValidator extends baseValidator_1.BaseValidator {
|
|
|
61
42
|
let boards = null;
|
|
62
43
|
await this.add_check('json_parse', 'valid JSON array', async () => {
|
|
63
44
|
try {
|
|
64
|
-
const str =
|
|
45
|
+
const str = (0, io_1.decodeText)(content);
|
|
65
46
|
const parsed = JSON.parse(str);
|
|
66
47
|
if (!Array.isArray(parsed)) {
|
|
67
48
|
this.err('root must be a JSON array of boards', true);
|
|
@@ -1,43 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.OpmlValidator = void 0;
|
|
27
4
|
/* eslint-disable @typescript-eslint/require-await */
|
|
28
|
-
const fs = __importStar(require("fs"));
|
|
29
|
-
const path = __importStar(require("path"));
|
|
30
5
|
const fast_xml_parser_1 = require("fast-xml-parser");
|
|
31
6
|
const baseValidator_1 = require("./baseValidator");
|
|
7
|
+
const io_1 = require("../utils/io");
|
|
32
8
|
/**
|
|
33
9
|
* Validator for OPML files
|
|
34
10
|
*/
|
|
35
11
|
class OpmlValidator extends baseValidator_1.BaseValidator {
|
|
36
12
|
static async validateFile(filePath) {
|
|
37
13
|
const validator = new OpmlValidator();
|
|
38
|
-
const content =
|
|
39
|
-
const stats =
|
|
40
|
-
return validator.validate(content,
|
|
14
|
+
const content = (0, io_1.readBinaryFromInput)(filePath);
|
|
15
|
+
const stats = (0, io_1.getFs)().statSync(filePath);
|
|
16
|
+
return validator.validate(content, (0, io_1.getBasename)(filePath), stats.size);
|
|
41
17
|
}
|
|
42
18
|
static async identifyFormat(content, filename) {
|
|
43
19
|
const name = filename.toLowerCase();
|
|
@@ -45,7 +21,12 @@ class OpmlValidator extends baseValidator_1.BaseValidator {
|
|
|
45
21
|
return true;
|
|
46
22
|
}
|
|
47
23
|
try {
|
|
48
|
-
|
|
24
|
+
if (typeof content !== 'string' &&
|
|
25
|
+
!(content instanceof ArrayBuffer) &&
|
|
26
|
+
!(content instanceof Uint8Array)) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
const str = typeof content === 'string' ? content : (0, io_1.decodeText)((0, io_1.toUint8Array)(content));
|
|
49
30
|
const validation = fast_xml_parser_1.XMLValidator.validate(str);
|
|
50
31
|
if (validation !== true) {
|
|
51
32
|
return false;
|
|
@@ -68,7 +49,7 @@ class OpmlValidator extends baseValidator_1.BaseValidator {
|
|
|
68
49
|
});
|
|
69
50
|
let text = '';
|
|
70
51
|
await this.add_check('content', 'non-empty content', async () => {
|
|
71
|
-
text =
|
|
52
|
+
text = (0, io_1.decodeText)(content);
|
|
72
53
|
if (!text.trim()) {
|
|
73
54
|
this.err('OPML file is empty', true);
|
|
74
55
|
}
|
|
@@ -29,11 +29,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
29
|
exports.SnapValidator = void 0;
|
|
30
30
|
/* eslint-disable @typescript-eslint/require-await */
|
|
31
31
|
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
32
|
-
const fs = __importStar(require("fs"));
|
|
33
|
-
const path = __importStar(require("path"));
|
|
34
32
|
const xml2js = __importStar(require("xml2js"));
|
|
35
33
|
const jszip_1 = __importDefault(require("jszip"));
|
|
36
34
|
const baseValidator_1 = require("./baseValidator");
|
|
35
|
+
const io_1 = require("../utils/io");
|
|
37
36
|
/**
|
|
38
37
|
* Validator for Snap files (.spb, .sps)
|
|
39
38
|
* Snap files are zipped packages containing XML configuration
|
|
@@ -47,9 +46,9 @@ class SnapValidator extends baseValidator_1.BaseValidator {
|
|
|
47
46
|
*/
|
|
48
47
|
static async validateFile(filePath) {
|
|
49
48
|
const validator = new SnapValidator();
|
|
50
|
-
const content =
|
|
51
|
-
const stats =
|
|
52
|
-
return validator.validate(content,
|
|
49
|
+
const content = (0, io_1.readBinaryFromInput)(filePath);
|
|
50
|
+
const stats = (0, io_1.getFs)().statSync(filePath);
|
|
51
|
+
return validator.validate(content, (0, io_1.getBasename)(filePath), stats.size);
|
|
53
52
|
}
|
|
54
53
|
/**
|
|
55
54
|
* Check if content is Snap format
|
|
@@ -62,8 +61,7 @@ class SnapValidator extends baseValidator_1.BaseValidator {
|
|
|
62
61
|
}
|
|
63
62
|
// Try to parse as ZIP and check for Snap structure
|
|
64
63
|
try {
|
|
65
|
-
const
|
|
66
|
-
const zip = await jszip_1.default.loadAsync(buffer);
|
|
64
|
+
const zip = await jszip_1.default.loadAsync((0, io_1.toUint8Array)(content));
|
|
67
65
|
const entries = Object.values(zip.files).filter((entry) => !entry.dir);
|
|
68
66
|
return entries.some((entry) => entry.name.includes('settings') || entry.name.includes('.xml'));
|
|
69
67
|
}
|
|
@@ -85,8 +83,7 @@ class SnapValidator extends baseValidator_1.BaseValidator {
|
|
|
85
83
|
let validZip = false;
|
|
86
84
|
await this.add_check('zip', 'valid zip package', async () => {
|
|
87
85
|
try {
|
|
88
|
-
|
|
89
|
-
zip = await jszip_1.default.loadAsync(buffer);
|
|
86
|
+
zip = await jszip_1.default.loadAsync((0, io_1.toUint8Array)(content));
|
|
90
87
|
const entries = Object.values(zip.files);
|
|
91
88
|
validZip = entries.length > 0;
|
|
92
89
|
}
|
|
@@ -27,10 +27,9 @@ exports.TouchChatValidator = void 0;
|
|
|
27
27
|
/* eslint-disable @typescript-eslint/require-await */
|
|
28
28
|
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
29
29
|
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
30
|
-
const fs = __importStar(require("fs"));
|
|
31
|
-
const path = __importStar(require("path"));
|
|
32
30
|
const xml2js = __importStar(require("xml2js"));
|
|
33
31
|
const baseValidator_1 = require("./baseValidator");
|
|
32
|
+
const io_1 = require("../utils/io");
|
|
34
33
|
/**
|
|
35
34
|
* Validator for TouchChat files (.ce)
|
|
36
35
|
* TouchChat files are XML-based
|
|
@@ -44,9 +43,9 @@ class TouchChatValidator extends baseValidator_1.BaseValidator {
|
|
|
44
43
|
*/
|
|
45
44
|
static async validateFile(filePath) {
|
|
46
45
|
const validator = new TouchChatValidator();
|
|
47
|
-
const content =
|
|
48
|
-
const stats =
|
|
49
|
-
return validator.validate(content,
|
|
46
|
+
const content = (0, io_1.readBinaryFromInput)(filePath);
|
|
47
|
+
const stats = (0, io_1.getFs)().statSync(filePath);
|
|
48
|
+
return validator.validate(content, (0, io_1.getBasename)(filePath), stats.size);
|
|
50
49
|
}
|
|
51
50
|
/**
|
|
52
51
|
* Check if content is TouchChat format
|
|
@@ -58,7 +57,7 @@ class TouchChatValidator extends baseValidator_1.BaseValidator {
|
|
|
58
57
|
}
|
|
59
58
|
// Try to parse as XML and check for TouchChat structure
|
|
60
59
|
try {
|
|
61
|
-
const contentStr =
|
|
60
|
+
const contentStr = typeof content === 'string' ? content : (0, io_1.decodeText)((0, io_1.toUint8Array)(content));
|
|
62
61
|
const parser = new xml2js.Parser();
|
|
63
62
|
const result = await parser.parseStringPromise(contentStr);
|
|
64
63
|
// TouchChat files typically have specific structure
|
|
@@ -82,7 +81,7 @@ class TouchChatValidator extends baseValidator_1.BaseValidator {
|
|
|
82
81
|
await this.add_check('xml_parse', 'valid XML', async () => {
|
|
83
82
|
try {
|
|
84
83
|
const parser = new xml2js.Parser();
|
|
85
|
-
const contentStr =
|
|
84
|
+
const contentStr = (0, io_1.decodeText)(content);
|
|
86
85
|
xmlObj = await parser.parseStringPromise(contentStr);
|
|
87
86
|
}
|
|
88
87
|
catch (e) {
|
package/docs/BROWSER_USAGE.md
CHANGED
|
@@ -565,14 +565,7 @@ async function safeLoadFile(file) {
|
|
|
565
565
|
|
|
566
566
|
## Testing
|
|
567
567
|
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
To run the test server:
|
|
571
|
-
```bash
|
|
572
|
-
node examples/browser-test-server.js
|
|
573
|
-
```
|
|
574
|
-
|
|
575
|
-
Then open: http://localhost:8080/examples/browser-test.html
|
|
568
|
+
Use the Vite demo in `examples/vitedemo` for interactive browser testing.
|
|
576
569
|
|
|
577
570
|
## Troubleshooting
|
|
578
571
|
|
|
@@ -614,5 +607,4 @@ await processor.loadIntoTree(uint8Array);
|
|
|
614
607
|
|
|
615
608
|
- [API Documentation](./API.md)
|
|
616
609
|
- [Examples](../examples/)
|
|
617
|
-
- [Browser
|
|
618
|
-
- [Test Server](../examples/browser-test-server.js)
|
|
610
|
+
- [Vite Browser Demo](../examples/vitedemo)
|