diff --git a/app/controllers/api/v1/Export.controller.js b/app/controllers/api/v1/Export.controller.js index 355e5ec..ece5f21 100644 --- a/app/controllers/api/v1/Export.controller.js +++ b/app/controllers/api/v1/Export.controller.js @@ -5,6 +5,7 @@ const path = require('path') const md = require('markdown').markdown const rimraf = require('rimraf') const uuid = require('uuid/v4') +const tmp = require('tmp-promise') class ExportController extends Controller { static get services() { @@ -214,9 +215,11 @@ class ExportController extends Controller { for ( const file_id of file_group.FileIds ) { const file = await File.findById(file_id) if ( file ) { - const store_path = file.provider().filepath(file.store_id) + const tmp_file = await tmp.file() + await file.provider().download_file(file, tmp_file.path) const ext = file.original_name.split('.').reverse()[0] - await this.copy_template(store_path, path.resolve(work_dir, `file-${file.upload_name}.${ext}`)) + await this.copy_template(tmp_file.path, path.resolve(work_dir, `file-${file.upload_name}.${ext}`)) + await fs.unlink(tmp_file.path) file_htmls.push(`
diff --git a/package.json b/package.json index 083f255..8b77478 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "rimraf": "^3.0.2", "tar": "^6.0.5", "tempfile": "^3.0.0", - "tmp": "^0.2.1" + "tmp": "^0.2.1", + "tmp-promise": "^3.0.2" } } diff --git a/yarn.lock b/yarn.lock index 2795e87..c05c669 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4253,7 +4253,14 @@ through@~2.3.8: resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5" integrity sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU= -tmp@^0.2.1: +tmp-promise@^3.0.2: + version "3.0.2" + resolved "https://registry.yarnpkg.com/tmp-promise/-/tmp-promise-3.0.2.tgz#6e933782abff8b00c3119d63589ca1fb9caaa62a" + integrity sha512-OyCLAKU1HzBjL6Ev3gxUeraJNlbNingmi8IrHHEsYH8LTmEuhvYfqvhn2F/je+mjf4N58UmZ96OMEy1JanSCpA== + dependencies: + tmp "^0.2.0" + +tmp@^0.2.0, tmp@^0.2.1: version "0.2.1" resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.2.1.tgz#8457fc3037dcf4719c251367a1af6500ee1ccf14" integrity sha512-76SUhtfqR2Ijn+xllcI5P1oyannHNHByD80W1q447gU3mp9G9PSpGdWmjUOHRDPiHYacIk66W7ubDTuPF3BEtQ==