Skip to content

Commit

Permalink
fix(api): delete orphaned db records when deleting training folder / …
Browse files Browse the repository at this point in the history
…files
  • Loading branch information
jakowenko committed Oct 7, 2021
1 parent 233b74e commit f031545
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions api/src/controllers/fs.controller.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const fs = require('fs');
const filesystem = require('../util/fs.util');
const database = require('../util/db.util');
const { resync } = require('../util/db.util');
const { STORAGE } = require('../constants')();

Expand All @@ -18,6 +19,9 @@ module.exports.folders = {
fs.rmdirSync(`${STORAGE.PATH}/train/${name}`, { recursive: true });
await resync.files();
}
const db = database.connect();
db.prepare('DELETE FROM file WHERE name = ?').run(name);
db.prepare('DELETE FROM train WHERE name = ?').run(name);
res.send({ success: true });
},
};
3 changes: 3 additions & 0 deletions api/src/controllers/storage.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ module.exports.delete = async (req, res) => {
db.prepare(
`DELETE FROM file WHERE id IN (${files.map((obj) => `'${obj.id}'`).join(',')})`
).run();
db.prepare(
`DELETE FROM train WHERE fileId IN (${files.map((obj) => `'${obj.id}'`).join(',')})`
).run();
files.forEach((obj) => {
filesystem.delete(`${PATH}/${obj.key}`);
});
Expand Down

0 comments on commit f031545

Please sign in to comment.