mirror of
https://github.com/Teamlinker/Teamlinker.git
synced 2025-06-03 03:00:17 +00:00
27 lines
1.0 KiB
TypeScript
27 lines
1.0 KiB
TypeScript
import * as fs from "fs-extra";
|
|
import Application from "../../common/app/app";
|
|
import {getMysqlInstance} from '../../common/db/mysql';
|
|
import getJobInstance from "../../common/job/job";
|
|
import {generateDeleteSql} from "../../common/util/sql";
|
|
import "../event/file";
|
|
import "../http/file";
|
|
import {ECommon_Model_File_Type, fileModel, ICommon_Model_File, Table_File} from './../../../common/model/file';
|
|
import path = require("path");
|
|
|
|
export async function config()
|
|
{
|
|
let job = getJobInstance();
|
|
job.create("remove-files", {
|
|
minute: 30
|
|
}, async (fireDate: Date) => {
|
|
let mysql = getMysqlInstance()
|
|
let ret = await mysql.execute<ICommon_Model_File>(`select * from ${Table_File} where type=${ECommon_Model_File_Type.LOCAL} and ref<=0 and created_time<(date_sub(current_timestamp(),INTERVAL 30 MINUTE))`)
|
|
for (let obj of ret) {
|
|
await fs.remove(path.join(Application.teamlinkerPath, obj.path))
|
|
await mysql.execute(generateDeleteSql(fileModel, {
|
|
id: obj.id
|
|
}))
|
|
}
|
|
})
|
|
}
|