forked from FoundKeyGang/FoundKey
fix
This commit is contained in:
parent
b50813649a
commit
5279d062df
4 changed files with 20 additions and 17 deletions
|
@ -13,27 +13,27 @@ import serialize from '../../serializers/drive-file';
|
|||
* @param {any} app
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user, app) => new Promise(async (res, rej) => {
|
||||
module.exports = async (params, user, app) => {
|
||||
// Get 'limit' parameter
|
||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
if (limitErr) throw 'invalid limit param';
|
||||
|
||||
// Get 'since_id' parameter
|
||||
const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
|
||||
if (sinceIdErr) return rej('invalid since_id param');
|
||||
if (sinceIdErr) throw 'invalid since_id param';
|
||||
|
||||
// Get 'max_id' parameter
|
||||
const [maxId, maxIdErr] = $(params.max_id).optional.id().$;
|
||||
if (maxIdErr) return rej('invalid max_id param');
|
||||
if (maxIdErr) throw 'invalid max_id param';
|
||||
|
||||
// Check if both of since_id and max_id is specified
|
||||
if (sinceId && maxId) {
|
||||
return rej('cannot set since_id and max_id');
|
||||
throw 'cannot set since_id and max_id';
|
||||
}
|
||||
|
||||
// Get 'folder_id' parameter
|
||||
const [folderId = null, folderIdErr] = $(params.folder_id).optional.nullable.id().$;
|
||||
if (folderIdErr) return rej('invalid folder_id param');
|
||||
if (folderIdErr) throw 'invalid folder_id param';
|
||||
|
||||
// Construct query
|
||||
const sort = {
|
||||
|
@ -64,6 +64,6 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
|
|||
});
|
||||
|
||||
// Serialize
|
||||
res(await Promise.all(files.map(async file =>
|
||||
await serialize(file))));
|
||||
});
|
||||
const _files = await Promise.all(files.map(file => serialize(file)));
|
||||
return _files
|
||||
};
|
||||
|
|
|
@ -12,10 +12,10 @@ import serialize from '../../../serializers/drive-file';
|
|||
* @param {any} user
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
module.exports = async (params, user) => {
|
||||
// Get 'file_id' parameter
|
||||
const [fileId, fileIdErr] = $(params.file_id).id().$;
|
||||
if (fileIdErr) return rej('invalid file_id param');
|
||||
if (fileIdErr) throw 'invalid file_id param';
|
||||
|
||||
// Fetch file
|
||||
const file = await DriveFile
|
||||
|
@ -27,11 +27,13 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
});
|
||||
|
||||
if (file === null) {
|
||||
return rej('file-not-found');
|
||||
throw 'file-not-found';
|
||||
}
|
||||
|
||||
// Serialize
|
||||
res(await serialize(file, {
|
||||
const _file = await serialize(file, {
|
||||
detail: true
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
return _file
|
||||
};
|
||||
|
|
|
@ -30,6 +30,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
});
|
||||
|
||||
// Serialize
|
||||
res(await Promise.all(folders.map(async folder =>
|
||||
await serialize(folder))));
|
||||
res(await Promise.all(folders.map(folder => serialize(folder))));
|
||||
});
|
||||
|
|
|
@ -25,6 +25,8 @@ export default (
|
|||
detail: false
|
||||
}, options);
|
||||
|
||||
if (!file) return reject('invalid file arg.')
|
||||
|
||||
let _file: any;
|
||||
|
||||
// Populate the file if 'file' is ID
|
||||
|
|
Loading…
Reference in a new issue