add image sizes to db
This commit is contained in:
parent
b8c193b5dc
commit
22933ad6b9
2 changed files with 27 additions and 0 deletions
22
src/dbpatches/02_image_sizes.sqlite
Normal file
22
src/dbpatches/02_image_sizes.sqlite
Normal 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;
|
||||||
|
|
@ -176,11 +176,16 @@ app.post('/api/upload', (req, res): void => {
|
||||||
res.status(400).send("Something went wrong!");
|
res.status(400).send("Something went wrong!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const dim = await Images.getDimensions(
|
||||||
|
`${UPLOAD_DIR}/${req.file.filename}`
|
||||||
|
)
|
||||||
const imageId = db.insert('images', {
|
const imageId = db.insert('images', {
|
||||||
filename: req.file.filename,
|
filename: req.file.filename,
|
||||||
filename_original: req.file.originalname,
|
filename_original: req.file.originalname,
|
||||||
title: req.body.title || '',
|
title: req.body.title || '',
|
||||||
created: Time.timestamp(),
|
created: Time.timestamp(),
|
||||||
|
width: dim.w,
|
||||||
|
height: dim.h,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (req.body.tags) {
|
if (req.body.tags) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue