mirror of
https://github.com/ONLYOFFICE/sdkjs.git
synced 2026-04-07 14:09:12 +08:00
[deserializer] Fix versionBuild detection in download-maps.js
This commit is contained in:
@ -33,6 +33,7 @@
|
||||
const fs = require('fs');
|
||||
const {writeFile, mkdir, stat} = require('fs/promises');
|
||||
const {S3Client, GetObjectCommand} = require("@aws-sdk/client-s3");
|
||||
const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
|
||||
|
||||
async function run(accessKeyId, secretAccessKey, inputFile = "unique.txt", mapsDir = "maps", region = "eu-west-1",
|
||||
endpoint = "https://s3.eu-west-1.amazonaws.com", bucketName = "repo-doc-onlyoffice-com",
|
||||
@ -51,16 +52,28 @@ async function run(accessKeyId, secretAccessKey, inputFile = "unique.txt", mapsD
|
||||
}
|
||||
};
|
||||
|
||||
let versionBuild = '';
|
||||
let versionsSet = new Set();
|
||||
console.log('Read: ', inputFile);
|
||||
let text = fs.readFileSync(inputFile, {encoding: 'utf-8'});
|
||||
let lines = text.split('\n');
|
||||
for (let line of lines) {
|
||||
let sdkMatchRes = line.match(/\/([a-zA-z0-9\-\.]*)\/sdkjs\//);
|
||||
if (!sdkMatchRes || 2 !== sdkMatchRes.length) {
|
||||
let sdkMatchRes = line.match(/(http.*?)\/([a-zA-z0-9\-\.]*)\/sdkjs\//);
|
||||
if (!sdkMatchRes || 3 !== sdkMatchRes.length) {
|
||||
continue;
|
||||
}
|
||||
versionsSet.add(sdkMatchRes[1]);
|
||||
versionsSet.add(sdkMatchRes[2]);
|
||||
if (!versionBuild) {
|
||||
const apiUrl = `${sdkMatchRes[1]}/web-apps/apps/api/documents/api.js`;
|
||||
console.log(`Request for build version: ${apiUrl}`);
|
||||
const response = await fetch(`${sdkMatchRes[1]}/web-apps/apps/api/documents/api.js`);
|
||||
const apiContent = await response.text();
|
||||
const match = apiContent.match(/\(build:(\d+)\)/);
|
||||
if (match) {
|
||||
versionBuild = match[1];
|
||||
console.log(`Found build version: ${versionBuild}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
let versions = Array.from(versionsSet);
|
||||
console.log('Found versions: ' + JSON.stringify(versions));
|
||||
@ -69,7 +82,6 @@ async function run(accessKeyId, secretAccessKey, inputFile = "unique.txt", mapsD
|
||||
|
||||
const client = new S3Client(configS3);
|
||||
for (let version of versions) {
|
||||
let versionS3 = version.replace(/-/g, '/');
|
||||
await mkdir(`${mapsDir}/${version}`, {recursive: true});
|
||||
for (let editor of editors) {
|
||||
for (let map of maps) {
|
||||
@ -78,14 +90,21 @@ async function run(accessKeyId, secretAccessKey, inputFile = "unique.txt", mapsD
|
||||
await stat(filePath);
|
||||
console.log('Skip file exists: ', filePath);
|
||||
} catch (err) {
|
||||
const key = keyPrefix.replace('{version}', versionS3) + `/${editor}${map}`;
|
||||
const command = new GetObjectCommand({
|
||||
Bucket: bucketName,
|
||||
Key: key
|
||||
});
|
||||
let versionS3 = version.replace(/-[a-zA-z0-9\-\.]*/g, '/');
|
||||
const key = keyPrefix.replace('{version}', versionS3 + versionBuild) + `/${editor}${map}`;
|
||||
console.log(`Download: ${mapsDir}/${version}/${editor}${map} from ${key}`);
|
||||
const output = await client.send(command);
|
||||
await writeFile(filePath, output.Body);
|
||||
let body = "";
|
||||
try {
|
||||
const command = new GetObjectCommand({
|
||||
Bucket: bucketName,
|
||||
Key: key
|
||||
});
|
||||
const output = await client.send(command);
|
||||
body = output.Body;
|
||||
} catch (err) {
|
||||
console.log('Skip file exists due download error(maybe wrong versionBuild detection): ', err);
|
||||
}
|
||||
await writeFile(filePath, body);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
87
build/deserializer/package-lock.json
generated
87
build/deserializer/package-lock.json
generated
@ -9,7 +9,8 @@
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-s3": "^3.405.0",
|
||||
"jszip": "^3.10.1"
|
||||
"jszip": "^3.10.1",
|
||||
"node-fetch": "^3.3.2"
|
||||
}
|
||||
},
|
||||
"node_modules/@aws-crypto/crc32": {
|
||||
@ -1383,6 +1384,14 @@
|
||||
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
|
||||
"integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ=="
|
||||
},
|
||||
"node_modules/data-uri-to-buffer": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz",
|
||||
"integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==",
|
||||
"engines": {
|
||||
"node": ">= 12"
|
||||
}
|
||||
},
|
||||
"node_modules/fast-xml-parser": {
|
||||
"version": "4.2.5",
|
||||
"resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-4.2.5.tgz",
|
||||
@ -1404,6 +1413,39 @@
|
||||
"fxparser": "src/cli/cli.js"
|
||||
}
|
||||
},
|
||||
"node_modules/fetch-blob": {
|
||||
"version": "3.2.0",
|
||||
"resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz",
|
||||
"integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/jimmywarting"
|
||||
},
|
||||
{
|
||||
"type": "paypal",
|
||||
"url": "https://paypal.me/jimmywarting"
|
||||
}
|
||||
],
|
||||
"dependencies": {
|
||||
"node-domexception": "^1.0.0",
|
||||
"web-streams-polyfill": "^3.0.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^12.20 || >= 14.13"
|
||||
}
|
||||
},
|
||||
"node_modules/formdata-polyfill": {
|
||||
"version": "4.0.10",
|
||||
"resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz",
|
||||
"integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==",
|
||||
"dependencies": {
|
||||
"fetch-blob": "^3.1.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12.20.0"
|
||||
}
|
||||
},
|
||||
"node_modules/immediate": {
|
||||
"version": "3.0.6",
|
||||
"resolved": "https://registry.npmjs.org/immediate/-/immediate-3.0.6.tgz",
|
||||
@ -1438,6 +1480,41 @@
|
||||
"immediate": "~3.0.5"
|
||||
}
|
||||
},
|
||||
"node_modules/node-domexception": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz",
|
||||
"integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/jimmywarting"
|
||||
},
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://paypal.me/jimmywarting"
|
||||
}
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=10.5.0"
|
||||
}
|
||||
},
|
||||
"node_modules/node-fetch": {
|
||||
"version": "3.3.2",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz",
|
||||
"integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==",
|
||||
"dependencies": {
|
||||
"data-uri-to-buffer": "^4.0.0",
|
||||
"fetch-blob": "^3.1.4",
|
||||
"formdata-polyfill": "^4.0.10"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/node-fetch"
|
||||
}
|
||||
},
|
||||
"node_modules/pako": {
|
||||
"version": "1.0.11",
|
||||
"resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz",
|
||||
@ -1502,6 +1579,14 @@
|
||||
"bin": {
|
||||
"uuid": "dist/bin/uuid"
|
||||
}
|
||||
},
|
||||
"node_modules/web-streams-polyfill": {
|
||||
"version": "3.3.3",
|
||||
"resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.3.3.tgz",
|
||||
"integrity": "sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw==",
|
||||
"engines": {
|
||||
"node": ">= 8"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-s3": "^3.405.0",
|
||||
"jszip": "^3.10.1"
|
||||
"jszip": "^3.10.1",
|
||||
"node-fetch": "^3.3.2"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user