Getting Timeline
The CloudikePhotos SDK provides features for building a timeline from server.
#
Initializationimport 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 photos from the serverThe following code example demonstrates getting items of timeline.
const params = {}; // IGetEmbeddedItemsSchemaphotosApp.timeline.getTimelineItems(params) .then(({data}) => { const items = data; // IItemSchema[] })
The following code example demonstrates how to get a paged list of timeline items.
const pageSize = 20;const params = {}; // IGetEmbeddedItemsSchemaconst paginator = photosApp.timeline.getTimelineItemsPaginator(pageSize, params);const items = [];// get first pagepaginator.next() .then(({data}) => { if (data !== null) { items.push(data); // IItemSchema[] // get second page return paginator.next(); } })
The following code example demonstrates getting item data by 'id'.
const itemId = 'id'photosApp.timeline.getPhoto(itemId) .then(({data}) => { const itemData = data; // IItemSchema })
The following code example demonstrates getting items data by list of items 'id'
const itemIds = ['id1', 'id2'];photosApp.timeline.getPhotos(itemIds) .then((responses) => { const items = responses.map(({data}) => data); // IItemSchema[] })
#
Add photos to timelineThe following code example demonstrates adding items to timeline.
const items = [item1, item2]; // IItemSchema[]photosApp.timeline.addItemsToTimeline(items) .then(({data}) => { const operations = data; // IOperationResult[] })
#
Delete photos from timelineThe following code example demonstrates removing items from timeline.
const items = [item1, item2]; // IItemSchema[]photosApp.timeline.removeItems(removeItems) .then(({data}) => { const operations = data; // IOperationResult[] })
The following code example demonstrates removing almost all items from timeline except for excluded items.
const albumId = 'id'; // insert id of certain albumconst excludeItems = [item1, item2]; // IItemSchema[]photosApp.timeline.batchRemoveAll(excludeItems) .then(() => { const operations = data; // IOperationResult[] });
#
Download photos from timelineThe following code example demonstrates getting a link to download timeline item'
const items = [item1, item2]; // IItemSchema[]photosApp.timeline.createItemsZipStream(items) .then((downloadLink) => { // download items as .zip archive window.location.assign(downloadLink) })
#
Upload photos to timelineThe following code example demonstrates operations with uploading a list of photos.
let itemsList: Array<File | UploaderBase> = null; // (File | UploaderBase)[]const options = {multipartUpload: true};photosApp.timeline.addToUploadList(files, options) .then((uploaderList) => { let itemsList; // (File | UploaderBase)[] let uploaderListState; // IUploaderListState // subscribe on 'update' to watch for uploading proceess results uploaderList.on('update', ({list, state}) => { // update state of uploding items list itemsList = list; // (File | UploaderBase)[] uploaderListState = state; // IUploaderListState })
// subscribe on 'error' to watch for uploading proceess error uploaderList.on('error', (error) => { throw new Error('UploaderListError') })
// start uploading uploaderList.start(); return uploaderList; }) .then((uploaderList) => { const {list, state} = uploaderList.getList(); if (!!list && list.length > 0) { const item = list[0]; // File | UploaderBase
// remove item form uploading list uploaderList.remove(item);
// restart uploading if (item instanceof UploaderBase) { uploaderList.restart(item) }
// resume uploading uploaderList.resume()
// clear uploader list uploaderList.clear() } }) .catch((error) => { // UploaderListError });