Working With File Versions
This guide describes methods for working with file versions.
#
File versions operationsThis chapter describes methods for receiving, creating, deleting, and modifying file versions.
#
Initializationimport CLFiles from '@cloudike/web_files';
let filesApp;
const options = { logLevel: 'error' // 'trace' | 'debug' | 'info' | 'warn' | 'error'};
const config = { authToken: '', // user auth token optional baseUrl: '', // api base url required userAgent: '', // user agent name required wsConfig: { // sockjs: '', // sockjs url optional sockjs_for_shares: "", // sockjs for shares url optional websocket_event_groups: [ "fs", "photos", "family" ], // websocket event groups optional, there are three groups: fs, photos, family jwt_token: '', // jwt token optional share_id: '', // share id optional auth_by_first_message: true // auth by first message optional }}
try { filesApp = CLFiles.init(options, config);} catch (error) { console.log('error', error);}
#
Create file versionThe following code example demonstrates how to create a file version by ID.
const nodeId = '<nodeId>';const opts: CustomRequestConfig = { signal: '<AbortSignal>' };const params: ICreateVersionSchema = {};filesApp.fileVersionsService .createNewVersion(nodeId, versionId, opts) .then(({ data }) => { console.log(data); // IVersionSchema }) .catch((error) => { });
#
Get file versionThe following code example demonstrates how to obtain a file's version by using its ID.
const nodeId = '<nodeId>';const versionId: string = '<versionId>';const opts: CustomRequestConfig = { signal: '<AbortSignal>' };
filesApp.fileVersionsService .getVersionsById(nodeId, versionId, opts) .then(({ data }) => { console.log(data); // IVersionSchema }) .catch((error) => {});
#
Get file versionsThe following code example demonstrates how to get file versions by node ID.
filesApp.folderOperationsService .getFolderContent({}) .then(({ data }) => { const { _embedded: { nodes }, } = data; const nodeId = '<nodeId>'; return filesApp.fileVersionsService.getVersions(nodeId, {}); }) .then(({ data }) => { console.log(data); // IVersionsSchema }) .catch((error) => {});
The following code example demonstrates how to get a paged list of file versions by node ID.
filesApp.folderOperationsService .getFolderContent({}) .then(({ data }) => { const { _embedded: { nodes }, } = data; const nodeId = '<nodeId>'; const pageSize: number = 20; const params: IGetVersionsSchema = {}; const opts: CustomRequestConfig = { signal: '<AbortSignal>' }; const paginator = filesApp.fileVersionsService.getVersionsPaginator( nodeId, pageSize, params, opts ); const items = []; // get first page paginator.next().then(({ data }) => { if (data !== null) { items.push(data); // IItemSchema[] // get second page return paginator.next(); } }); });
#
Delete file versionThe following code example demonstrates how to delete a file version by ID.
const nodeId = '<nodeId>';const versionId: string = '<versionId>';const opts: CustomRequestConfig = { signal: '<AbortSignal>' };
filesApp.fileVersionsService .deleteVersion(nodeId, versionId, opts) .then(({ data }) => { console.log(data); // IVersionSchema }) .catch((error) => { });
#
Get file version file objectThe following code example demonstrates how to get the file version of a file object by its node ID.
const nodeId = '<nodeId>';const versionId: string = '<versionId>';const opts: CustomRequestConfig = { signal: '<AbortSignal>' };filesApp.fileVersionsService .getFileVersionFileObject(nodeId, versionId, opts) .then(({ data }) => { console.log(data); // IFileObjectSchema }) .catch((error) => {});