mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ACS-5845] remove Alfresco Compatibility usage (#8822)
* upgrade to latest js-api * upgrade to latest js-api * upgrade to latest js-api * upgrade to latest js-api * upgrade to latest js-api * upgrade to latest js-api * fix security concerns for execSync * security fix * fixes as per code reviews * code fixes for attach file widget dialog * code fixes * code fixes * disable ACS storage check * add the jira to the commented out block * remove useless logger call * code fixes * code fixes * code fixes * code and typing fixes * fix lint * disable the code * try other fixes, add missing headers * dump error to console * replace test file with in-memory stream * code fixes * simplify checks * disable upload * remove useless test and ng-mocks dependency
This commit is contained in:
@@ -15,39 +15,37 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const alfrescoApi = require('@alfresco/js-api');
|
||||
import { AlfrescoApi, SharedlinksApi, FavoritesApi, NodesApi, UploadApi, NodeEntry } from '@alfresco/js-api';
|
||||
import { exit, argv } from 'node:process';
|
||||
const program = require('commander');
|
||||
const fs = require ('fs');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
import { logger } from './logger';
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
const { SharedlinksApi, FavoritesApi, NodesApi } = require('@alfresco/js-api');
|
||||
const MAX_RETRY = 10;
|
||||
let counter = 0;
|
||||
const TIMEOUT = 6000;
|
||||
const ACS_DEFAULT = require('./resources').ACS_DEFAULT;
|
||||
|
||||
let alfrescoJsApi;
|
||||
let alfrescoJsApi: AlfrescoApi;
|
||||
|
||||
export default async function() {
|
||||
// eslint-disable-next-line space-before-function-paren
|
||||
export default async function () {
|
||||
await main();
|
||||
}
|
||||
|
||||
async function main() {
|
||||
|
||||
program
|
||||
.version('0.1.0')
|
||||
.option('--host [type]', 'Remote environment host')
|
||||
.option('--clientId [type]', 'sso client', 'alfresco')
|
||||
.option('-p, --password [type]', 'password ')
|
||||
.option('-u, --username [type]', 'username ')
|
||||
.parse(process.argv);
|
||||
.parse(argv);
|
||||
|
||||
await checkEnv();
|
||||
|
||||
logger.info(`***** Step initialize ACS *****`);
|
||||
await initializeDefaultFiles();
|
||||
|
||||
}
|
||||
|
||||
async function initializeDefaultFiles() {
|
||||
@@ -81,41 +79,35 @@ async function initializeDefaultFiles() {
|
||||
}
|
||||
|
||||
async function createFolder(folderName: string, parentId: string) {
|
||||
let createdFolder: any;
|
||||
const body = {
|
||||
name: folderName,
|
||||
nodeType: 'cm:folder'
|
||||
};
|
||||
try {
|
||||
createdFolder = await new NodesApi(alfrescoJsApi).createNode(parentId, body, {overwrite: true});
|
||||
let createdFolder: NodeEntry;
|
||||
const body = {
|
||||
name: folderName,
|
||||
nodeType: 'cm:folder'
|
||||
};
|
||||
try {
|
||||
createdFolder = await new NodesApi(alfrescoJsApi).createNode(parentId, body, { overwrite: true });
|
||||
|
||||
logger.info(`Folder ${folderName} was created`);
|
||||
} catch (err) {
|
||||
if (err.status === 409) {
|
||||
const relativePath = `/${folderName}`;
|
||||
createdFolder = await new NodesApi(alfrescoJsApi).getNode('-my-', { relativePath });
|
||||
}
|
||||
logger.info(`Folder ${folderName} was created`);
|
||||
} catch (err) {
|
||||
if (err.status === 409) {
|
||||
const relativePath = `/${folderName}`;
|
||||
createdFolder = await new NodesApi(alfrescoJsApi).getNode('-my-', { relativePath });
|
||||
}
|
||||
return createdFolder;
|
||||
}
|
||||
return createdFolder;
|
||||
}
|
||||
|
||||
async function uploadFile(fileName: string, fileDestination: string) {
|
||||
async function uploadFile(fileName: string, fileDestination: string): Promise<NodeEntry> {
|
||||
const filePath = `../resources/content/${fileName}`;
|
||||
const file = fs.createReadStream(path.join(__dirname, filePath));
|
||||
let uploadedFile: any;
|
||||
let uploadedFile: NodeEntry;
|
||||
try {
|
||||
uploadedFile = await alfrescoJsApi.upload.uploadFile(
|
||||
file,
|
||||
'',
|
||||
fileDestination,
|
||||
null,
|
||||
{
|
||||
name: fileName,
|
||||
nodeType: 'cm:content',
|
||||
renditions: 'doclib',
|
||||
overwrite: true
|
||||
}
|
||||
);
|
||||
uploadedFile = await new UploadApi(alfrescoJsApi).uploadFile(file, '', fileDestination, null, {
|
||||
name: fileName,
|
||||
nodeType: 'cm:content',
|
||||
renditions: 'doclib',
|
||||
overwrite: true
|
||||
});
|
||||
logger.info(`File ${fileName} was uploaded`);
|
||||
} catch (err) {
|
||||
logger.error(`Failed to upload file with error: `, err.stack);
|
||||
@@ -123,36 +115,37 @@ async function uploadFile(fileName: string, fileDestination: string) {
|
||||
return uploadedFile;
|
||||
}
|
||||
|
||||
async function lockFile(nodeId) {
|
||||
async function lockFile(nodeId: string): Promise<NodeEntry> {
|
||||
const data = {
|
||||
type: 'ALLOW_OWNER_CHANGES'
|
||||
};
|
||||
try {
|
||||
await alfrescoJsApi.nodes.lockNode(nodeId, data);
|
||||
const result = new NodesApi(alfrescoJsApi).lockNode(nodeId, data);
|
||||
logger.info('File was locked');
|
||||
} catch (error) {
|
||||
return result;
|
||||
} catch (error) {
|
||||
logger.error('Failed to lock file with error: ', error.stack);
|
||||
}
|
||||
}
|
||||
|
||||
async function shareFile(nodeId) {
|
||||
async function shareFile(nodeId: string) {
|
||||
const data = {
|
||||
nodeId
|
||||
};
|
||||
try {
|
||||
await new SharedlinksApi(alfrescoJsApi).createSharedLink(data);
|
||||
logger.info('File was shared');
|
||||
} catch (error) {
|
||||
} catch (error) {
|
||||
logger.error('Failed to share file with error: ', error.stack);
|
||||
}
|
||||
}
|
||||
|
||||
async function favoriteFile(nodeId) {
|
||||
async function favoriteFile(nodeId: string) {
|
||||
const data = {
|
||||
target: {
|
||||
['file']: {
|
||||
guid: nodeId
|
||||
}
|
||||
['file']: {
|
||||
guid: nodeId
|
||||
}
|
||||
}
|
||||
};
|
||||
try {
|
||||
@@ -165,8 +158,7 @@ async function favoriteFile(nodeId) {
|
||||
|
||||
async function checkEnv() {
|
||||
try {
|
||||
|
||||
alfrescoJsApi = new alfrescoApi.AlfrescoApiCompatibility({
|
||||
alfrescoJsApi = new AlfrescoApi({
|
||||
provider: 'ALL',
|
||||
hostBpm: program.host,
|
||||
hostEcm: program.host,
|
||||
@@ -174,31 +166,33 @@ async function checkEnv() {
|
||||
oauth2: {
|
||||
host: `${program.host}/auth/realms/alfresco`,
|
||||
clientId: `${program.clientId}`,
|
||||
scope: 'openid'
|
||||
}
|
||||
scope: 'openid',
|
||||
redirectUri: '/'
|
||||
},
|
||||
contextRoot: 'alfresco'
|
||||
});
|
||||
await alfrescoJsApi.login(program.username, program.password);
|
||||
} catch (e) {
|
||||
if (e.error.code === 'ETIMEDOUT') {
|
||||
logger.error('The env is not reachable. Terminating');
|
||||
process.exit(1);
|
||||
exit(1);
|
||||
}
|
||||
logger.error('Login error environment down or inaccessible');
|
||||
counter++;
|
||||
if (MAX_RETRY === counter) {
|
||||
logger.error('Give up');
|
||||
process.exit(1);
|
||||
exit(1);
|
||||
} else {
|
||||
logger.error(`Retry in 1 minute attempt N ${counter}`);
|
||||
sleep(TIMEOUT);
|
||||
checkEnv();
|
||||
await checkEnv();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* eslint-enable */
|
||||
|
||||
function sleep(delay) {
|
||||
function sleep(delay: number) {
|
||||
const start = new Date().getTime();
|
||||
while (new Date().getTime() < start + delay) { }
|
||||
while (new Date().getTime() < start + delay) {}
|
||||
}
|
||||
|
Reference in New Issue
Block a user