Skip to main content

Trashbin

The CloudikePhotos SDK provides features for building a trashbin from server.

Initialization

import CLPhotos from 'web_photos';


let photosApp;

const options = {
logLevel: 'error' // 'trace' | 'debug' | 'info' | 'warn' | 'error'
};

const config = {
authToken: '', // user auth token
baseUrl: '', // api base url required
userAgent: '' // user agent name required
}

try {
photosApp = CLPhotos.init(options, config);
} catch (e) {
// catch photo sdk InternalError
}

Read Items from trash

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

photosApp.trashBin.getItems().then(({ data }) => {
const {
embedded: { items },
} = data;
return items; // IItemSchema[]
});

The following code example demonstrates how to get a paged list of trash bin of timeline.

const pageSize = 20;
const params = {}; // IGetEmbeddedItemsSchema
const paginator = photosApp.trashBin.getTrashItemsPaginator(
pageSize,
params
);
const items = [];
// get first page
paginator.next().then(({ data }) => {
if (data !== null) {
items.push(data); // IItemSchema[]
// get second page
return paginator.next();
}
});

Restore items from the trash bin to the timeline.

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

const selecteditems = [item1, item2]; // IItemSchema[]
photosApp.trashBin.restoreItems(selecteditems).then(({ data }) => {
const operations = data; // IOperationResult[]
});

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

photosApp.trashBin.fullRestore()
.then(() => {})
.catch ((error) => {})

Remove items from the trash bin.

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

const selecteditems = [item1, item2]; // IItemSchema[]
photosApp.trashBin.deleteItems(selecteditems).then(() => {
const operations = data; // IOperationResult[]
});

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

photosApp.trashBin.emptyTrash()
.then(() => {})
.catch ((error) => {})

The following code example demonstrates removing almost all items from an album except for excluded items.

const excludeItems = [item1, item2]; // IItemSchema[]
photosApp.trashBin.batchRemoveAll(excludeItems).then(() => {
const operations = data; // IOperationResult[]
});