[API] 良い感じに
This commit is contained in:
parent
3c7f23b685
commit
d7a16d7ab1
4 changed files with 23 additions and 13 deletions
|
@ -38,5 +38,7 @@ module.exports = (params, user) =>
|
|||
}
|
||||
|
||||
// Serialize
|
||||
res(await serialize(file));
|
||||
res(await serialize(file, {
|
||||
detail: true
|
||||
}));
|
||||
});
|
||||
|
|
|
@ -36,6 +36,6 @@ module.exports = (params, user) =>
|
|||
|
||||
// Serialize
|
||||
res(await serialize(folder, {
|
||||
includeParent: true
|
||||
detail: true
|
||||
}));
|
||||
});
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
import * as mongo from 'mongodb';
|
||||
import DriveFile from '../models/drive-file';
|
||||
import serializeDriveFolder from './drive-folder';
|
||||
import serializeDriveTag from './drive-tag';
|
||||
import deepcopy = require('deepcopy');
|
||||
import config from '../../conf';
|
||||
|
@ -19,12 +20,12 @@ import config from '../../conf';
|
|||
export default (
|
||||
file: any,
|
||||
options?: {
|
||||
includeTags: boolean
|
||||
detail: boolean
|
||||
}
|
||||
) => new Promise<Object>(async (resolve, reject) => {
|
||||
const opts = options || {
|
||||
includeTags: true
|
||||
};
|
||||
const opts = Object.assign({
|
||||
detail: false
|
||||
}, options);
|
||||
|
||||
let _file: any;
|
||||
|
||||
|
@ -57,7 +58,14 @@ export default (
|
|||
|
||||
_file.url = `${config.drive_url}/${_file.id}/${encodeURIComponent(_file.name)}`;
|
||||
|
||||
if (opts.includeTags && _file.tags) {
|
||||
if (opts.detail && _file.folder_id) {
|
||||
// Populate folder
|
||||
_file.folder = await serializeDriveFolder(_file.folder_id, {
|
||||
detail: true
|
||||
});
|
||||
}
|
||||
|
||||
if (opts.detail && _file.tags) {
|
||||
// Populate tags
|
||||
_file.tags = await _file.tags.map(async (tag: any) =>
|
||||
await serializeDriveTag(tag)
|
||||
|
|
|
@ -17,12 +17,12 @@ import deepcopy = require('deepcopy');
|
|||
const self = (
|
||||
folder: any,
|
||||
options?: {
|
||||
includeParent: boolean
|
||||
detail: boolean
|
||||
}
|
||||
) => new Promise<Object>(async (resolve, reject) => {
|
||||
const opts = options || {
|
||||
includeParent: false
|
||||
};
|
||||
const opts = Object.assign({
|
||||
detail: false
|
||||
}, options);
|
||||
|
||||
let _folder: any;
|
||||
|
||||
|
@ -39,10 +39,10 @@ const self = (
|
|||
_folder.id = _folder._id;
|
||||
delete _folder._id;
|
||||
|
||||
if (opts.includeParent && _folder.parent_id) {
|
||||
if (opts.detail && _folder.parent_id) {
|
||||
// Populate parent folder
|
||||
_folder.parent = await self(_folder.parent_id, {
|
||||
includeParent: true
|
||||
detail: true
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue