Add .removeOrphans()

This commit is contained in:
Max Isom 2021-11-19 12:22:27 -05:00
parent f5149dfaba
commit 34e45d6273
No known key found for this signature in database
GPG key ID: 25C9B1A7F6798880

View file

@ -1,10 +1,10 @@
import {promises as fs, createWriteStream} from 'fs';
import path from 'path';
import {inject, injectable} from 'inversify'; import {inject, injectable} from 'inversify';
import sequelize from 'sequelize'; import sequelize from 'sequelize';
import {FileCache} from '../models/index.js'; import {FileCache} from '../models/index.js';
import {TYPES} from '../types.js'; import {TYPES} from '../types.js';
import Config from './config.js'; import Config from './config.js';
import {promises as fs, createWriteStream} from 'fs';
import path from 'path';
@injectable() @injectable()
export default class FileCacheProvider { export default class FileCacheProvider {
@ -104,6 +104,14 @@ export default class FileCacheProvider {
} }
private async removeOrphans() { private async removeOrphans() {
// TODO for await (const dirent of await fs.opendir(this.config.CACHE_DIR)) {
if (dirent.isFile()) {
const model = await FileCache.findByPk(dirent.name);
if (!model) {
await fs.unlink(path.join(this.config.CACHE_DIR, dirent.name));
}
}
}
} }
} }