diff --git a/src/api/endpoints/drive/files/show.js b/src/api/endpoints/drive/files/show.js index dffb6d6612..27062cb84e 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 4424361a87..04b924dc58 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 65fe7d6d26..02241c2261 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 102c8aeff6..a5339ce96c 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 }); }