Fix export controller to be upload-provider agnostic
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing

This commit is contained in:
Garrett Mills 2020-11-29 02:41:45 -06:00
parent 97b4bf662c
commit f935507612
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246
3 changed files with 15 additions and 4 deletions

View File

@ -5,6 +5,7 @@ const path = require('path')
const md = require('markdown').markdown const md = require('markdown').markdown
const rimraf = require('rimraf') const rimraf = require('rimraf')
const uuid = require('uuid/v4') const uuid = require('uuid/v4')
const tmp = require('tmp-promise')
class ExportController extends Controller { class ExportController extends Controller {
static get services() { static get services() {
@ -214,9 +215,11 @@ class ExportController extends Controller {
for ( const file_id of file_group.FileIds ) { for ( const file_id of file_group.FileIds ) {
const file = await File.findById(file_id) const file = await File.findById(file_id)
if ( file ) { 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] 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(` file_htmls.push(`
<div class="file"> <div class="file">

View File

@ -32,6 +32,7 @@
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
"tar": "^6.0.5", "tar": "^6.0.5",
"tempfile": "^3.0.0", "tempfile": "^3.0.0",
"tmp": "^0.2.1" "tmp": "^0.2.1",
"tmp-promise": "^3.0.2"
} }
} }

View File

@ -4253,7 +4253,14 @@ through@~2.3.8:
resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5" resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5"
integrity sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU= 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" version "0.2.1"
resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.2.1.tgz#8457fc3037dcf4719c251367a1af6500ee1ccf14" resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.2.1.tgz#8457fc3037dcf4719c251367a1af6500ee1ccf14"
integrity sha512-76SUhtfqR2Ijn+xllcI5P1oyannHNHByD80W1q447gU3mp9G9PSpGdWmjUOHRDPiHYacIk66W7ubDTuPF3BEtQ== integrity sha512-76SUhtfqR2Ijn+xllcI5P1oyannHNHByD80W1q447gU3mp9G9PSpGdWmjUOHRDPiHYacIk66W7ubDTuPF3BEtQ==