calendar.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. const log = require('../util/log')
  2. const path = require('path')
  3. const sqlite3 = require('sqlite3')
  4. const bplist = require('bplist-parser')
  5. const fs = require('fs')
  6. const plist = require('plist')
  7. // Derive filenames based on domain + file path
  8. const fileHash = require('../util/backup_filehash')
  9. const database = fileHash('Library/Calendar/Calendar.sqlitedb')
  10. module.exports.name = 'calendar'
  11. module.exports.description = 'List calendar entries'
  12. // Specify this reporter requires a backup.
  13. // The second parameter to func() is now a backup instead of the path to one.
  14. module.exports.requiresBackup = true
  15. // Specify this reporter supports the promises API for allowing chaining of reports.
  16. module.exports.usesPromises = true
  17. module.exports.func = function (program, backup, resolve, reject) {
  18. calendarReport(backup)
  19. .then((items) => {
  20. var result = program.formatter.format(items, {
  21. program: program,
  22. columns: {
  23. 'Timestamp': el => (new Date((el.start_date + 978307200) * 1000).toDateString()) + ' ' + (new Date((el.start_date + 978307200) * 1000).toTimeString()) ,
  24. 'Title': el => el.summary,
  25. 'Content': el => el.description
  26. }
  27. })
  28. resolve(result)
  29. })
  30. .catch(reject)
  31. }
  32. const calendarReport = (backup) => {
  33. return new Promise((resolve, reject) => {
  34. var calendardb = backup.getDatabase(database)
  35. try {
  36. const query = `
  37. select * from CalendarItem
  38. order by start_date
  39. `
  40. calendardb.all(query, async function (err, rows) {
  41. if (err) reject(err)
  42. resolve(rows)
  43. })
  44. } catch (e) {
  45. reject(e)
  46. }
  47. })
  48. }