mirror of
https://iceshrimp.dev/crimekillz/trashposs
synced 2024-11-22 00:43:49 +01:00
server - multerがテンポラリディレクトリにファイルを展開するように
DiskStorageをオプション無しで呼ぶといい感じになる またチェーンを改行するようにし、デバッグ表示にパスが出るようにした
This commit is contained in:
parent
95d6832735
commit
1ba12b922d
@ -40,7 +40,7 @@ const addFile = async (
|
||||
folderId: mongodb.ObjectID = null,
|
||||
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
|
||||
const [hash, [mime, ext], size] = await Promise.all([
|
||||
@ -210,18 +210,19 @@ export default (user: any, file: string | stream.Readable, ...args) => new Promi
|
||||
.catch(rej);
|
||||
}
|
||||
rej(new Error('un-compatible file.'));
|
||||
}).then(([path, remove]): Promise<any> => new Promise((res, rej) => {
|
||||
addFile(user, path, ...args)
|
||||
.then(file => {
|
||||
res(file);
|
||||
if (remove) {
|
||||
fs.unlink(path, (e) => {
|
||||
if (e) log(e.stack);
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(rej);
|
||||
}))
|
||||
})
|
||||
.then(([path, remove]): Promise<any> => new Promise((res, rej) => {
|
||||
addFile(user, path, ...args)
|
||||
.then(file => {
|
||||
res(file);
|
||||
if (remove) {
|
||||
fs.unlink(path, (e) => {
|
||||
if (e) log(e.stack);
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(rej);
|
||||
}))
|
||||
.then(file => {
|
||||
log(`drive file has been created ${file._id}`);
|
||||
resolve(file);
|
||||
|
@ -40,7 +40,7 @@ app.get('/', (req, res) => {
|
||||
endpoints.forEach(endpoint =>
|
||||
endpoint.withFile ?
|
||||
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)) :
|
||||
app.post(`/${endpoint.name}`,
|
||||
require('./api-handler').default.bind(null, endpoint))
|
||||
|
Loading…
Reference in New Issue
Block a user