Refactor uploads
This commit is contained in:
parent
75a46212da
commit
f59b9a5d22
14 changed files with 297 additions and 269 deletions
|
@ -1,6 +1,6 @@
|
|||
import fs from 'fs';
|
||||
import createError from 'http-errors';
|
||||
import { get as getFile } from './s3';
|
||||
import { get as getFile } from './sftp';
|
||||
|
||||
import debugname from 'debug';
|
||||
const debug = debugname('hostr:file-stream');
|
||||
|
@ -10,22 +10,23 @@ export default function* hostrFileStream(localPath, remotePath) {
|
|||
return new Promise((resolve, reject) => {
|
||||
localRead.once('error', () => {
|
||||
debug('local error');
|
||||
const remoteRead = getFile(remotePath);
|
||||
const remoteFile = getFile(remotePath);
|
||||
|
||||
remoteRead.once('readable', () => {
|
||||
debug('remote readable');
|
||||
remoteFile.then((remoteRead) => {
|
||||
const localWrite = fs.createWriteStream(localPath);
|
||||
localWrite.once('finish', () => {
|
||||
debug('local write end');
|
||||
resolve(fs.createReadStream(localPath));
|
||||
});
|
||||
remoteRead.pipe(localWrite);
|
||||
|
||||
remoteRead.once('error', () => {
|
||||
debug('remote error');
|
||||
reject(createError(404));
|
||||
});
|
||||
});
|
||||
|
||||
remoteRead.once('error', () => {
|
||||
debug('remote error');
|
||||
reject(createError(404));
|
||||
});
|
||||
|
||||
});
|
||||
localRead.once('readable', () => {
|
||||
debug('local readable');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue