2019-06-10 06:13:55 +12:00
|
|
|
const Service = require('../service.js');
|
|
|
|
|
|
|
|
class Storage extends Service {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List Files
|
|
|
|
*
|
2019-10-09 17:16:38 +13:00
|
|
|
* /docs/references/storage/list-files.md
|
2019-06-10 06:13:55 +12:00
|
|
|
*
|
|
|
|
* @param string search
|
|
|
|
* @param number limit
|
|
|
|
* @param number offset
|
|
|
|
* @param string orderType
|
|
|
|
* @throws Exception
|
|
|
|
* @return {}
|
|
|
|
*/
|
|
|
|
async listFiles(search = '', limit = 25, offset = 0, orderType = 'ASC') {
|
|
|
|
let path = '/storage/files';
|
|
|
|
|
|
|
|
return await this.client.call('get', path, {'content-type': 'application/json'},
|
|
|
|
{
|
|
|
|
'search': search,
|
|
|
|
'limit': limit,
|
|
|
|
'offset': offset,
|
|
|
|
'orderType': orderType
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create File
|
|
|
|
*
|
2019-10-09 17:16:38 +13:00
|
|
|
* /docs/references/storage/create-file.md
|
2019-06-10 06:13:55 +12:00
|
|
|
*
|
|
|
|
* @param File files
|
|
|
|
* @param array read
|
|
|
|
* @param array write
|
|
|
|
* @param string folderId
|
|
|
|
* @throws Exception
|
|
|
|
* @return {}
|
|
|
|
*/
|
|
|
|
async createFile(files, read = [], write = [], folderId = '') {
|
|
|
|
let path = '/storage/files';
|
|
|
|
|
|
|
|
return await this.client.call('post', path, {'content-type': 'application/json'},
|
|
|
|
{
|
|
|
|
'files': files,
|
|
|
|
'read': read,
|
|
|
|
'write': write,
|
|
|
|
'folderId': folderId
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get File
|
|
|
|
*
|
2019-10-09 17:16:38 +13:00
|
|
|
* /docs/references/storage/get-file.md
|
2019-06-10 06:13:55 +12:00
|
|
|
*
|
|
|
|
* @param string fileId
|
|
|
|
* @throws Exception
|
|
|
|
* @return {}
|
|
|
|
*/
|
|
|
|
async getFile(fileId) {
|
|
|
|
let path = '/storage/files/{fileId}'.replace(new RegExp('{fileId}', 'g'), fileId);
|
|
|
|
|
|
|
|
return await this.client.call('get', path, {'content-type': 'application/json'},
|
|
|
|
{
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-08-29 00:37:13 +12:00
|
|
|
/**
|
|
|
|
* Update File
|
|
|
|
*
|
2019-10-09 17:16:38 +13:00
|
|
|
* /docs/references/storage/update-file.md
|
2019-08-29 00:37:13 +12:00
|
|
|
*
|
|
|
|
* @param string fileId
|
|
|
|
* @param array read
|
|
|
|
* @param array write
|
|
|
|
* @param string folderId
|
|
|
|
* @throws Exception
|
|
|
|
* @return {}
|
|
|
|
*/
|
|
|
|
async updateFile(fileId, read = [], write = [], folderId = '') {
|
|
|
|
let path = '/storage/files/{fileId}'.replace(new RegExp('{fileId}', 'g'), fileId);
|
|
|
|
|
|
|
|
return await this.client.call('put', path, {'content-type': 'application/json'},
|
|
|
|
{
|
|
|
|
'read': read,
|
|
|
|
'write': write,
|
|
|
|
'folderId': folderId
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-06-10 06:13:55 +12:00
|
|
|
/**
|
|
|
|
* Delete File
|
|
|
|
*
|
2019-10-09 17:16:38 +13:00
|
|
|
* /docs/references/storage/delete-file.md
|
2019-06-10 06:13:55 +12:00
|
|
|
*
|
|
|
|
* @param string fileId
|
|
|
|
* @throws Exception
|
|
|
|
* @return {}
|
|
|
|
*/
|
|
|
|
async deleteFile(fileId) {
|
|
|
|
let path = '/storage/files/{fileId}'.replace(new RegExp('{fileId}', 'g'), fileId);
|
|
|
|
|
|
|
|
return await this.client.call('delete', path, {'content-type': 'application/json'},
|
|
|
|
{
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-08-27 21:12:40 +12:00
|
|
|
* Get File for Download
|
2019-06-10 06:13:55 +12:00
|
|
|
*
|
2019-10-09 17:16:38 +13:00
|
|
|
* /docs/references/storage/get-file-download.md
|
2019-06-10 06:13:55 +12:00
|
|
|
*
|
|
|
|
* @param string fileId
|
|
|
|
* @throws Exception
|
|
|
|
* @return {}
|
|
|
|
*/
|
|
|
|
async getFileDownload(fileId) {
|
|
|
|
let path = '/storage/files/{fileId}/download'.replace(new RegExp('{fileId}', 'g'), fileId);
|
|
|
|
|
|
|
|
return await this.client.call('get', path, {'content-type': 'application/json'},
|
|
|
|
{
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-08-27 21:12:40 +12:00
|
|
|
* Get File Preview
|
2019-06-10 06:13:55 +12:00
|
|
|
*
|
2019-10-09 17:16:38 +13:00
|
|
|
* /docs/references/storage/get-file-preview.md
|
2019-06-10 06:13:55 +12:00
|
|
|
*
|
|
|
|
* @param string fileId
|
|
|
|
* @param number width
|
|
|
|
* @param number height
|
|
|
|
* @param number quality
|
|
|
|
* @param string background
|
|
|
|
* @param string output
|
|
|
|
* @throws Exception
|
|
|
|
* @return {}
|
|
|
|
*/
|
|
|
|
async getFilePreview(fileId, width = 0, height = 0, quality = 100, background = '', output = '') {
|
|
|
|
let path = '/storage/files/{fileId}/preview'.replace(new RegExp('{fileId}', 'g'), fileId);
|
|
|
|
|
|
|
|
return await this.client.call('get', path, {'content-type': 'application/json'},
|
|
|
|
{
|
|
|
|
'width': width,
|
|
|
|
'height': height,
|
|
|
|
'quality': quality,
|
|
|
|
'background': background,
|
|
|
|
'output': output
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-08-27 21:12:40 +12:00
|
|
|
* Get File for View
|
2019-06-10 06:13:55 +12:00
|
|
|
*
|
2019-10-09 17:16:38 +13:00
|
|
|
* /docs/references/storage/get-file-view.md
|
2019-06-10 06:13:55 +12:00
|
|
|
*
|
|
|
|
* @param string fileId
|
|
|
|
* @param string as
|
|
|
|
* @throws Exception
|
|
|
|
* @return {}
|
|
|
|
*/
|
|
|
|
async getFileView(fileId, as = '') {
|
|
|
|
let path = '/storage/files/{fileId}/view'.replace(new RegExp('{fileId}', 'g'), fileId);
|
|
|
|
|
|
|
|
return await this.client.call('get', path, {'content-type': 'application/json'},
|
|
|
|
{
|
|
|
|
'as': as
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Storage;
|