mirror of
https://github.com/kokonect-link/cherrypick
synced 2024-12-03 01:09:01 +09:00
[API] 良い感じに
This commit is contained in:
parent
3c7f23b685
commit
d7a16d7ab1
@ -38,5 +38,7 @@ module.exports = (params, user) =>
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Serialize
|
// Serialize
|
||||||
res(await serialize(file));
|
res(await serialize(file, {
|
||||||
|
detail: true
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
|
@ -36,6 +36,6 @@ module.exports = (params, user) =>
|
|||||||
|
|
||||||
// Serialize
|
// Serialize
|
||||||
res(await serialize(folder, {
|
res(await serialize(folder, {
|
||||||
includeParent: true
|
detail: true
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
import * as mongo from 'mongodb';
|
import * as mongo from 'mongodb';
|
||||||
import DriveFile from '../models/drive-file';
|
import DriveFile from '../models/drive-file';
|
||||||
|
import serializeDriveFolder from './drive-folder';
|
||||||
import serializeDriveTag from './drive-tag';
|
import serializeDriveTag from './drive-tag';
|
||||||
import deepcopy = require('deepcopy');
|
import deepcopy = require('deepcopy');
|
||||||
import config from '../../conf';
|
import config from '../../conf';
|
||||||
@ -19,12 +20,12 @@ import config from '../../conf';
|
|||||||
export default (
|
export default (
|
||||||
file: any,
|
file: any,
|
||||||
options?: {
|
options?: {
|
||||||
includeTags: boolean
|
detail: boolean
|
||||||
}
|
}
|
||||||
) => new Promise<Object>(async (resolve, reject) => {
|
) => new Promise<Object>(async (resolve, reject) => {
|
||||||
const opts = options || {
|
const opts = Object.assign({
|
||||||
includeTags: true
|
detail: false
|
||||||
};
|
}, options);
|
||||||
|
|
||||||
let _file: any;
|
let _file: any;
|
||||||
|
|
||||||
@ -57,7 +58,14 @@ export default (
|
|||||||
|
|
||||||
_file.url = `${config.drive_url}/${_file.id}/${encodeURIComponent(_file.name)}`;
|
_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
|
// Populate tags
|
||||||
_file.tags = await _file.tags.map(async (tag: any) =>
|
_file.tags = await _file.tags.map(async (tag: any) =>
|
||||||
await serializeDriveTag(tag)
|
await serializeDriveTag(tag)
|
||||||
|
@ -17,12 +17,12 @@ import deepcopy = require('deepcopy');
|
|||||||
const self = (
|
const self = (
|
||||||
folder: any,
|
folder: any,
|
||||||
options?: {
|
options?: {
|
||||||
includeParent: boolean
|
detail: boolean
|
||||||
}
|
}
|
||||||
) => new Promise<Object>(async (resolve, reject) => {
|
) => new Promise<Object>(async (resolve, reject) => {
|
||||||
const opts = options || {
|
const opts = Object.assign({
|
||||||
includeParent: false
|
detail: false
|
||||||
};
|
}, options);
|
||||||
|
|
||||||
let _folder: any;
|
let _folder: any;
|
||||||
|
|
||||||
@ -39,10 +39,10 @@ const self = (
|
|||||||
_folder.id = _folder._id;
|
_folder.id = _folder._id;
|
||||||
delete _folder._id;
|
delete _folder._id;
|
||||||
|
|
||||||
if (opts.includeParent && _folder.parent_id) {
|
if (opts.detail && _folder.parent_id) {
|
||||||
// Populate parent folder
|
// Populate parent folder
|
||||||
_folder.parent = await self(_folder.parent_id, {
|
_folder.parent = await self(_folder.parent_id, {
|
||||||
includeParent: true
|
detail: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user