mirror of
https://github.com/BluemediaGER/muse.git
synced 2024-11-23 09:15:29 +01:00
Add .removeOrphans()
This commit is contained in:
parent
f5149dfaba
commit
34e45d6273
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue