appCrashLogs.js 772 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * @class AppCrashLogs 原生应用崩溃日志模型
  3. * @function clean 原生应用崩溃日志清理函数
  4. */
  5. const BaseMod = require('./base')
  6. const {
  7. DateTime,
  8. UniCrypto
  9. } = require('../lib')
  10. module.exports = class AppCrashLogs extends BaseMod {
  11. constructor() {
  12. super()
  13. this.tableName = 'app-crash-logs'
  14. }
  15. /**
  16. * 原生应用崩溃日志清理函数
  17. * @param {Number} days 保留天数
  18. */
  19. async clean(days = 7) {
  20. days = Math.max(parseInt(days), 1)
  21. console.log('clean app crash logs - day:', days)
  22. const dateTime = new DateTime()
  23. const res = await this.delete(this.tableName, {
  24. create_time: {
  25. $lt: dateTime.getTimeBySetDays(0 - days)
  26. }
  27. })
  28. if (!res.code) {
  29. console.log('clean app crash log:', res)
  30. }
  31. return res
  32. }
  33. }