mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-07-31 17:38:28 +00:00
- remove some awaits
- add try catch - small refactoring
This commit is contained in:
@@ -28,63 +28,81 @@ import { Utils } from '../../../../utilities/utils';
|
||||
import { SharedlinksApi as AdfSharedlinksApi, SharedLinkEntry } from '@alfresco/js-api';
|
||||
|
||||
export class SharedLinksApi extends RepoApi {
|
||||
sharedlinksApi = new AdfSharedlinksApi(this.alfrescoJsApi);
|
||||
sharedlinksApi = new AdfSharedlinksApi(this.alfrescoJsApi);
|
||||
|
||||
constructor(username?, password?) {
|
||||
super(username, password);
|
||||
}
|
||||
constructor(username?, password?) {
|
||||
super(username, password);
|
||||
}
|
||||
|
||||
async shareFileById(id: string, expireDate?: Date): Promise<SharedLinkEntry|null> {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
const data = {
|
||||
nodeId: id,
|
||||
expiresAt: expireDate
|
||||
};
|
||||
async shareFileById(id: string, expireDate?: Date): Promise<SharedLinkEntry|null> {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
const data = {
|
||||
nodeId: id,
|
||||
expiresAt: expireDate
|
||||
};
|
||||
return await this.sharedlinksApi.createSharedLink(data);
|
||||
} catch (error) {
|
||||
console.log('---- shareFileById error: ', error);
|
||||
return null;
|
||||
}
|
||||
} catch (error) {
|
||||
console.log('---- shareFileById error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async shareFilesByIds(ids: string[]) {
|
||||
return await ids.reduce(async (previous: any, current: any) => {
|
||||
await previous;
|
||||
return await this.shareFileById(current);
|
||||
}, Promise.resolve());
|
||||
async shareFilesByIds(ids: string[]) {
|
||||
try {
|
||||
return await ids.reduce(async (previous: any, current: any) => {
|
||||
await previous;
|
||||
return await this.shareFileById(current);
|
||||
}, Promise.resolve());
|
||||
} catch (error) {
|
||||
console.log('--- shared links api shareFilesByIds catch error: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
async getSharedIdOfNode(name: string) {
|
||||
const sharedLinks = (await this.getSharedLinks()).list.entries;
|
||||
const found = sharedLinks.find(sharedLink => sharedLink.entry.name === name);
|
||||
return (found || { entry: { id: null } }).entry.id;
|
||||
async getSharedIdOfNode(name: string) {
|
||||
try {
|
||||
const sharedLinks = (await this.getSharedLinks()).list.entries;
|
||||
const found = sharedLinks.find(sharedLink => sharedLink.entry.name === name);
|
||||
return (found || { entry: { id: null } }).entry.id;
|
||||
} catch (error) {
|
||||
console.log('--- shared links api getSharedIdOfNode catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async unshareFile(name: string) {
|
||||
const id = await this.getSharedIdOfNode(name);
|
||||
return await this.sharedlinksApi.deleteSharedLink(id);
|
||||
async unshareFile(name: string) {
|
||||
try {
|
||||
const id = await this.getSharedIdOfNode(name);
|
||||
return await this.sharedlinksApi.deleteSharedLink(id);
|
||||
} catch (error) {
|
||||
console.log('--- shared links api unshareFile catch error: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
async getSharedLinks() {
|
||||
await this.apiAuth();
|
||||
return await this.sharedlinksApi.listSharedLinks();
|
||||
async getSharedLinks() {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return await this.sharedlinksApi.listSharedLinks();
|
||||
} catch (error) {
|
||||
console.log('--- shared links api getSharedLinks catch error: ', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async waitForApi(data) {
|
||||
try {
|
||||
const sharedFiles = async () => {
|
||||
const totalItems = (await this.getSharedLinks()).list.pagination.totalItems;
|
||||
if ( totalItems !== data.expect ) {
|
||||
return Promise.reject(totalItems);
|
||||
} else {
|
||||
return Promise.resolve(totalItems);
|
||||
}
|
||||
async waitForApi(data: { expect: number }) {
|
||||
try {
|
||||
const sharedFiles = async () => {
|
||||
const totalItems = (await this.getSharedLinks()).list.pagination.totalItems;
|
||||
if ( totalItems !== data.expect ) {
|
||||
return Promise.reject(totalItems);
|
||||
} else {
|
||||
return Promise.resolve(totalItems);
|
||||
}
|
||||
};
|
||||
|
||||
return await Utils.retryCall(sharedFiles);
|
||||
} catch (error) {
|
||||
console.log('-----> catch shared: ', error);
|
||||
}
|
||||
} catch (error) {
|
||||
console.log('--- shared links api waitForApi catch error: ', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user