add image sizes to db

This commit is contained in:
Zutatensuppe 2021-06-20 14:07:35 +02:00
parent b8c193b5dc
commit 22933ad6b9
2 changed files with 27 additions and 0 deletions

View file

@ -0,0 +1,22 @@
-- Add width/height to images table
CREATE TABLE images_new (
id INTEGER PRIMARY KEY AUTOINCREMENT,
created TIMESTAMP NOT NULL,
filename TEXT NOT NULL UNIQUE,
filename_original TEXT NOT NULL,
title TEXT NOT NULL,
width INTEGER NOT NULL,
height INTEGER NOT NULL
);
INSERT INTO images_new
SELECT id, created, filename, filename_original, title, 0, 0
FROM images;
DROP TABLE images;
ALTER TABLE images_new RENAME TO images;

View file

@ -176,11 +176,16 @@ app.post('/api/upload', (req, res): void => {
res.status(400).send("Something went wrong!");
}
const dim = await Images.getDimensions(
`${UPLOAD_DIR}/${req.file.filename}`
)
const imageId = db.insert('images', {
filename: req.file.filename,
filename_original: req.file.originalname,
title: req.body.title || '',
created: Time.timestamp(),
width: dim.w,
height: dim.h,
})
if (req.body.tags) {