server - multerがテンポラリディレクトリにファイルを展開するように
DiskStorageをオプション無しで呼ぶといい感じになる またチェーンを改行するようにし、デバッグ表示にパスが出るようにした
This commit is contained in:
parent
aabfe3c873
commit
28d2d38fce
2 changed files with 15 additions and 14 deletions
|
@ -40,7 +40,7 @@ const addFile = async (
|
||||||
folderId: mongodb.ObjectID = null,
|
folderId: mongodb.ObjectID = null,
|
||||||
force: boolean = false
|
force: boolean = false
|
||||||
) => {
|
) => {
|
||||||
log(`registering ${name} (user: ${user.username})`);
|
log(`registering ${name} (user: ${user.username}, path: ${path})`);
|
||||||
|
|
||||||
// Calculate hash, get content type and get file size
|
// Calculate hash, get content type and get file size
|
||||||
const [hash, [mime, ext], size] = await Promise.all([
|
const [hash, [mime, ext], size] = await Promise.all([
|
||||||
|
@ -210,7 +210,8 @@ export default (user: any, file: string | stream.Readable, ...args) => new Promi
|
||||||
.catch(rej);
|
.catch(rej);
|
||||||
}
|
}
|
||||||
rej(new Error('un-compatible file.'));
|
rej(new Error('un-compatible file.'));
|
||||||
}).then(([path, remove]): Promise<any> => new Promise((res, rej) => {
|
})
|
||||||
|
.then(([path, remove]): Promise<any> => new Promise((res, rej) => {
|
||||||
addFile(user, path, ...args)
|
addFile(user, path, ...args)
|
||||||
.then(file => {
|
.then(file => {
|
||||||
res(file);
|
res(file);
|
||||||
|
|
|
@ -40,7 +40,7 @@ app.get('/', (req, res) => {
|
||||||
endpoints.forEach(endpoint =>
|
endpoints.forEach(endpoint =>
|
||||||
endpoint.withFile ?
|
endpoint.withFile ?
|
||||||
app.post(`/${endpoint.name}`,
|
app.post(`/${endpoint.name}`,
|
||||||
endpoint.withFile ? multer({ dest: 'uploads/' }).single('file') : null,
|
endpoint.withFile ? multer({ storage: multer.diskStorage({}) }).single('file') : null,
|
||||||
require('./api-handler').default.bind(null, endpoint)) :
|
require('./api-handler').default.bind(null, endpoint)) :
|
||||||
app.post(`/${endpoint.name}`,
|
app.post(`/${endpoint.name}`,
|
||||||
require('./api-handler').default.bind(null, endpoint))
|
require('./api-handler').default.bind(null, endpoint))
|
||||||
|
|
Loading…
Reference in a new issue