appCrashLogs.js 772 字节
Newer Older
study夏羽's avatar
study夏羽 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
/**
 * @class AppCrashLogs 原生应用崩溃日志模型
 * @function clean 原生应用崩溃日志清理函数
 */
const BaseMod = require('./base')
const {
	DateTime,
	UniCrypto
} = require('../lib')
module.exports = class AppCrashLogs extends BaseMod {
	constructor() {
		super()
		this.tableName = 'app-crash-logs'
	}

	/**
	 * 原生应用崩溃日志清理函数
	 * @param {Number} days 保留天数
	 */
	async clean(days = 7) {
		days = Math.max(parseInt(days), 1)
		console.log('clean app crash logs - day:', days)

		const dateTime = new DateTime()

		const res = await this.delete(this.tableName, {
			create_time: {
				$lt: dateTime.getTimeBySetDays(0 - days)
			}
		})

		if (!res.code) {
			console.log('clean app crash log:', res)
		}
		return res
	}
}