diff options
| author | Pitu <[email protected]> | 2019-02-23 00:45:45 +0900 |
|---|---|---|
| committer | Pitu <[email protected]> | 2019-02-23 00:45:45 +0900 |
| commit | fc95cb7b0f047806937c25f0fc1104c72b0a32cb (patch) | |
| tree | fcf55a9e1f280dc34912a914e0cc47f69ce0b8c4 /src/api/routes/files | |
| parent | Update Util.js (diff) | |
| download | host.fuwn.me-fc95cb7b0f047806937c25f0fc1104c72b0a32cb.tar.xz host.fuwn.me-fc95cb7b0f047806937c25f0fc1104c72b0a32cb.zip | |
Better DB handling and stuff
Diffstat (limited to 'src/api/routes/files')
| -rw-r--r-- | src/api/routes/files/uploadPOST.js | 44 |
1 files changed, 31 insertions, 13 deletions
diff --git a/src/api/routes/files/uploadPOST.js b/src/api/routes/files/uploadPOST.js index d6cb8b7..fdab035 100644 --- a/src/api/routes/files/uploadPOST.js +++ b/src/api/routes/files/uploadPOST.js @@ -118,19 +118,37 @@ class uploadPOST extends Route { store the details on the database. */ const now = moment.utc().toDate(); - let inserted = null; + let insertedId = null; try { - inserted = await db.table('files').insert({ - userId: user ? user.id : null, - name: upload.filename, - original: upload.originalname, - type: upload.mimetype || '', - size: upload.size, - hash, - ip: req.ip, - createdAt: now, - editedAt: now - }, 'id'); + /* + This is so fucking dumb + */ + if (process.env.DB_CLIENT === 'sqlite3') { + insertedId = await db.table('files').insert({ + userId: user ? user.id : null, + name: upload.filename, + original: upload.originalname, + type: upload.mimetype || '', + size: upload.size, + hash, + ip: req.ip, + createdAt: now, + editedAt: now + }); + } else { + insertedId = await db.table('files').insert({ + userId: user ? user.id : null, + name: upload.filename, + original: upload.originalname, + type: upload.mimetype || '', + size: upload.size, + hash, + ip: req.ip, + createdAt: now, + editedAt: now + }, 'id'); + } + /* TODO: Something funny here, I'm not sure since I don't use MySQL but I think the argument id on the insert function on top behaves differently on psql/mysql/sqlite. Needs testing. @@ -155,7 +173,7 @@ class uploadPOST extends Route { */ if (albumId) { try { - await db.table('albumsFiles').insert({ albumId, fileId: inserted[0] }); + await db.table('albumsFiles').insert({ albumId, fileId: insertedId[0] }); await db.table('albums').where('id', albumId).update('editedAt', now); } catch (error) { log.error('There was an error updating editedAt on an album'); |