Skip to main content

Working With Files Trash Bin

This guide describes methods for working with files in the trash bin.

Trash bin operations​

This chapter describes methods for receiving, deleting and restoring files from the trash bin.

Initialization​

import 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);
}

Get trash bin content​

The following code example demonstrates how to get items from trash.

const params: IGetFsNodesSchema = {
parent_id: '<parent_id>'
};
const opts: CustomRequestConfig = { signal: '<AbortSignal>' };
filesApp
.trashBin
.getItems(params, opts)
.then(({ data: IFsNodesSchema }) => {
const {
_embedded: { nodes },
} = data;
return items;
})
.catch((error) => {
});

The following code example demonstrates how to get a paged list of trash bin’s files.

const pageSize: number = 20;
const params: IGetFsNodesSchema = {};
const opts: CustomRequestConfig = { signal: '<AbortSignal>' };
const paginator = filesApp.trashBin.getTrashItemsPaginator(
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();
}
})
.catch((error) => {
});

The following code example demonstrates how to get a list of all trashed nodes.

const params: IGetFsNodesSchema = {}; // 
const defaultPageSize: number = 100;
const delay: number = 300;
const opts: CustomRequestConfig = { signal: '<AbortSignal>' };
filesApp
.trashBin
.getAllNodes(params, defaultPageSize, delay, opts)
.then((nodes: IFsNodeSchema[]) => {
console.log('nodes', nodes); // IFsNodeSchema[]
})
.catch((error) => {
});

The following code example demonstrates how to get a list of all explicitly trashed nodes.

const params: IGetFsNodesSchema = {};
const defaultPageSize: number = 100;
const delay: number = 300;
const opts: CustomRequestConfig = { signal: '<AbortSignal>' };
filesApp
.trashBin
.getAllExplicitlyTrashedNodes(params, defaultPageSize, delay, opts)
.then((nodes: IFsNodeSchema[]) => {
console.log('nodes', nodes);
})
.catch((error) => {
});

Delete trash bin content​

The following code example demonstrates removing selected items from the trash bin.

const nodeIds = ['<item_id>', '<item_id>'];
const opts: CustomRequestConfig = { signal: '<AbortSignal>' };
filesApp
.trashBin
.deleteItems(nodeIds, opts)
.then(() => {
})
.catch((error) => {
});

The following code example demonstrates removing selected items from the trash bin with batching api.

const nodeIds = ['<item_id>', '<item_id>'];
const pageSize: number = '<number>';
const delay: number = '<delay>';
const opts: CustomRequestConfig = { signal: '<AbortSignal>' };
filesApp.trashBin
.batchDeletingItems(nodeIds, pageSize, delay, opts)
.then(() => {
})
.catch((error) => {
});

Restore trash bin content​

The following code example demonstrates restoring selected items from the trash bin.

const nodeIds = ['<item_id>', '<item_id>'];
const opts: CustomRequestConfig = { signal: '<AbortSignal>' };
filesApp
.trashBin
.restoreItems(nodeIds, opts)
.then(() => {})
.catch((error) => {});

The following code example demonstrates restoring all items from the trash bin.

const checkStatusDelay: number = 300;
const opts: CustomRequestConfig = { signal: '<AbortSignal>' };
filesApp
.trashBin
.fullRestore(checkStatusDelay, opts)
.then(() => {
})
.catch((error) => {
});

Empty trash bin​

The following code example demonstrates removing all items from the trash bin.

const opts: CustomRequestConfig = { signal: '<AbortSignal>' };
filesApp
.trashBin
.emptyTrash(opts)
.then(() => {})
.catch((error) => {});