Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/deserializer #3721

Merged
merged 12 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.idea/
build/node_modules
build/deserializer/cache
build/$weak$.js
common/AllFonts.js
common/Images/fonts_thumbnail*
Expand Down
52 changes: 52 additions & 0 deletions build/deserializer/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Deserializer

## Overview

**deserializer** allow you to automatically get deserialized stacktrace in errors

## How to use

* Put files with errors in json format in any `logs-dir`

* Make `unique-file` with unique errors and new-lines

```bash
node parse-json-log-dir.js logs-dir unique-file
```
* Install dependencies for `download-maps.js`

```bash
npm ci
```

* Download Closure Compiler maps into `maps-dir` for version specified in `unique-file`

```bash
node download-maps.js accessKeyId, secretAccessKey unique-file maps-dir
```
* Download Closure Compiler maps into `maps-dir` for version specified in `unique-file`

```bash
node download-maps.js accessKeyId, secretAccessKey unique-file maps-dir
```

maps-dir structure will be

```
maps-dir/
7.4.1-36
word.props.js.map
cell.props.js.map
slide.props.js.map
<version>-<build>
<maps>
```

* Deserialize `unique-file` call stack into `deserialized-file`

```bash
node deserialize.js unique-file deserialized-file maps-dir
```

* The result will be in the `deserialized-file`

95 changes: 95 additions & 0 deletions build/deserializer/deserialize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* (c) Copyright Ascensio System SIA 2010-2023
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/

const fs = require('node:fs');
// Input and output file with errors
const INPUTFILE = process.argv[2] ? `${__dirname}/${process.argv[2]}` : `${__dirname}/input.txt`;
const OUTPUTFILE = `${__dirname}/output.txt`;
// Old serialized props map
const OLD_PROPS_MAP_NAME = 'sdk-all.props.js.map';
// New serialized props map
const NEW_PROPS_MAP_WORD_NAME = 'word.props.js.map';
const NEW_PROPS_MAP_CELL_NAME = 'cell.props.js.map';
const NEW_PROPS_MAP_SLIDE_NAME = 'slide.props.js.map';

function readProps(file) {
let props = fs.readFileSync(file, {encoding: 'utf-8'});
let propsLines = props.split('\n');
let propsMap = {};
propsLines.forEach(function (line) {
let lineElems = line.split(':');
propsMap[lineElems[1]] = lineElems[0]
});
return propsMap;
}

function run(inputFile = "unique.txt", outputFile = "deserialized.txt", mapsDir="maps")
{
let sdkMaps = {};
console.log('Read: ', inputFile);
let propsReplaced = 0;
let text = fs.readFileSync(inputFile, {encoding: 'utf-8'});
let lines = text.split('\n');
let replaced = lines.map((line) => {
let sdkMatchRes = line.match(/\/([a-zA-z0-9\-\.]*)\/sdkjs\/([a-zA-z0-9\-\.]*)\//);

if (!sdkMatchRes || 3 !== sdkMatchRes.length) {
return line;
}
let maps = sdkMaps[sdkMatchRes[0]];
if (!maps) {
let pathProps = `${mapsDir}/${sdkMatchRes[1]}/${sdkMatchRes[2]}.props.js.map`;
let pathVars = `${mapsDir}/${sdkMatchRes[1]}/${sdkMatchRes[2]}.vars.js.map`;
console.log(`Read maps: ${pathProps} and ${pathVars}`);
sdkMaps[sdkMatchRes[0]] = {props: readProps(pathProps), vars: readProps(pathVars)};
}
if (maps) {
line = line.replace(/(new )?([a-zA-z0-9$]*)(@http| \(http)/, (match, p1, p2, p3) => {
let props = p1 ? maps.vars[p2] : maps.props[p2];
if (props) {
propsReplaced++;
return `${p1 || ''}${p2}(${props})${p3}`
} else {
return match
}
});
}
return line;
});
console.log(`Number of replaced properties: ${propsReplaced}`);

let output = replaced.join('\n');
fs.writeFileSync(outputFile, output, {encoding: 'utf-8'});
console.log('Complete writeFileSync:' + outputFile);
}

run.apply(this, process.argv.slice(2));
90 changes: 90 additions & 0 deletions build/deserializer/download-maps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* (c) Copyright Ascensio System SIA 2010-2023
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/

const fs = require('fs');
const { writeFile, mkdir, stat } = require('fs/promises');
const { S3Client, GetObjectCommand} = require("@aws-sdk/client-s3");

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") {
const configS3 = {
region: region,
endpoint: endpoint,
credentials : {
accessKeyId: accessKeyId,
secretAccessKey: secretAccessKey
}
};

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) {
continue;
}
versionsSet.add(sdkMatchRes[1]);
}
let versions = Array.from(versionsSet);
console.log('Found versions: ' + JSON.stringify(versions));
const editors = ['word', 'cell', 'slide'];
const maps = ['.props.js.map', '.vars.js.map', '-all.js.map', '-all-min.js.map'];

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) {
let filePath = `${mapsDir}/${version}/${editor}${map}`;
try {
await stat(filePath);
console.log('Skip file exists: ', filePath);
}
catch (err) {
const key = `closure-maps/${versionS3}/commercial/${editor}${map}`;
const command = new GetObjectCommand({
Bucket: bucketName,
Key: key
});
console.log(`Download: ${mapsDir}/${version}/${editor}${map} from ${key}`);
const output = await client.send(command);
await writeFile(filePath, output.Body);
}
}
}
}
console.log('Download complete');
}

run.apply(this, process.argv.slice(2)).catch(console.error);
Loading