/**
 * 运行方式：node clearupload.js -h 192.168.31.2 -u zxy -p zxy -d zxy -port 3306
 */
var zxy = require('zxy-comm');
var path = require('path');
var fs = require('fs');
var params = zxy.app.m_obtain.getStartArguments();
if (JSON.stringify(params) == "{}") {
    console.warn('请输入参数 -host -user -pwd -db');
    return;
}
zxy.runMysql({
    host: params.h || params.host || '',
    user: params.u || params.user || '',
    password: params.p || params.pwd || params.password || '',
    database: params.d || params.db || params.database || '',
    port: params.port || 3306,
    multipleStatements: true,
    insecureAuth: true
});
setTimeout(function () {
    zxy.app.m_mysql.run("truncate table zxy_upload_log;").then(function (r) {
        console.log("移除资源");
        var filepath = path.join(__dirname, '../../uploads');
        fs.readdir(filepath, function (err, files) {
            for (var i = 0; i < files.length; i++) {
                fs.unlinkSync(filepath + '/' + files[i]);
                console.log("删除文件" + files[i]);
            }
            process.exit(0);
        });
    }).catch(function (e) {
        console.error("资源删除失败");
        process.exit(0);
    });
}, 1000);