From d7a16d7ab1c38886a031c5eb40a0ee3973670394 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 16 Feb 2017 16:55:01 +0900 Subject: [PATCH] =?UTF-8?q?[API]=20=E8=89=AF=E3=81=84=E6=84=9F=E3=81=98?= =?UTF-8?q?=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/endpoints/drive/files/show.js | 4 +++- src/api/endpoints/drive/folders/show.js | 2 +- src/api/serializers/drive-file.ts | 18 +++++++++++++----- src/api/serializers/drive-folder.ts | 12 ++++++------ 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/api/endpoints/drive/files/show.js b/src/api/endpoints/drive/files/show.js index dffb6d661..27062cb84 100644 --- a/src/api/endpoints/drive/files/show.js +++ b/src/api/endpoints/drive/files/show.js @@ -38,5 +38,7 @@ module.exports = (params, user) => } // Serialize - res(await serialize(file)); + res(await serialize(file, { + detail: true + })); }); diff --git a/src/api/endpoints/drive/folders/show.js b/src/api/endpoints/drive/folders/show.js index 4424361a8..04b924dc5 100644 --- a/src/api/endpoints/drive/folders/show.js +++ b/src/api/endpoints/drive/folders/show.js @@ -36,6 +36,6 @@ module.exports = (params, user) => // Serialize res(await serialize(folder, { - includeParent: true + detail: true })); }); diff --git a/src/api/serializers/drive-file.ts b/src/api/serializers/drive-file.ts index 65fe7d6d2..02241c226 100644 --- a/src/api/serializers/drive-file.ts +++ b/src/api/serializers/drive-file.ts @@ -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(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) diff --git a/src/api/serializers/drive-folder.ts b/src/api/serializers/drive-folder.ts index 102c8aeff..a5339ce96 100644 --- a/src/api/serializers/drive-folder.ts +++ b/src/api/serializers/drive-folder.ts @@ -17,12 +17,12 @@ import deepcopy = require('deepcopy'); const self = ( folder: any, options?: { - includeParent: boolean + detail: boolean } ) => new Promise(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 }); }