Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.then((gltf) => {
const parsedGltf = JSON.parse(gltf);
gltfValidator
.validateBytes(new Uint8Array(Buffer.from(JSON.stringify(parsedGltf))))
.catch((error) => {
console.warn('Validation failed: ', error);
process.exit(1);
});
return converter(parsedGltf);
})
.then((data) => {
.then((gltf) => {
const parsedGltf = JSON.parse(gltf);
gltfValidator
.validateBytes(new Uint8Array(Buffer.from(JSON.stringify(parsedGltf))))
.catch((error) => {
console.warn('Validation failed: ', error);
});
const convertedFile = converter(parsedGltf);
convertedFile.then((data) => {
fs.writeFile(output, data, (error) => {
if (!error) {
console.log(`Written file to ${output}`);
} else {
console.error(error);
}
});
});
async function validateModel(glTFAsset) {
const asset = fs.readFileSync(glTFAsset.modelFilepath);
return validator.validateBytes(new Uint8Array(asset), {
uri: glTFAsset.modelName,
writeTimestamp: false,
externalResourceFunction: (uri) =>
new Promise((resolve, reject) => {
uri = path.resolve(path.dirname(glTFAsset.modelFilepath), decodeURIComponent(uri));
fs.readFile(uri, (error, data) => {
if (error) {
console.error(error.toString());
reject(error.toString());
return;
}
resolve(data);
});
})
}).then((report) => {
glTFAsset.report = report;
const validateURI = (uri) => {
const asset = fs.readFileSync(uri);
const dir = path.dirname(uri);
const promise = validator.validateBytes(new Uint8Array(asset), {
uri,
externalResourceFunction: (uri) =>
new Promise((resolve) => {
uri = path.resolve(dir, decodeURIComponent(uri));
const buffer = fs.readFileSync(uri)
resolve(new Uint8Array(buffer));
})
})
.then((report) => {
messages.numAssets++;
messages.numErrors += report.issues.numErrors;
messages.numWarnings += report.issues.numWarnings;
messages.numInfos += report.issues.numInfos;
messages.numHints += report.issues.numHints;
if (verbose) {
messages.reports.push(report);
export async function validate(sourceFilename: string) {
if (typeof sourceFilename === 'undefined') {
return;
}
if (!fs.existsSync(sourceFilename)) {
throw new Error('File not found.');
}
const currentSettings: ValidatorSettings = vscode.workspace.getConfiguration('glTF').get('Validation');
const gltfData = fs.readFileSync(sourceFilename);
const baseName = path.basename(sourceFilename);
const folderName = path.resolve(sourceFilename, '..');
const result = await gltfValidator.validateBytes(new Uint8Array(gltfData), {
uri: baseName,
maxIssues: currentSettings.maxIssues,
ignoredIssues: currentSettings.ignoredIssues,
severityOverrides: currentSettings.severityOverrides,
externalResourceFunction: (uri : string) =>
new Promise((resolve, reject) => {
uri = path.resolve(folderName, decodeURIComponent(uri));
fs.readFile(uri, (err, data) => {
if (err) {
reject(err.toString());
return;
}
resolve(data);
});
}),
});
.then((buffer) => validateBytes(new Uint8Array(buffer), {
externalResourceFunction: (uri) =>
this.resolveExternalResource(uri, rootFile, rootPath, assetMap)
}))
.then((report) => this.setReport(report, response))