events.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Derive filenames based on domain + file path
  2. const fileHash = require('../../util/backup_filehash')
  3. const apple_timestamp = require('../../util/apple_timestamp')
  4. const CAL_DB = fileHash('Library/Calendar/Calendar.sqlitedb')
  5. module.exports = {
  6. version: 4,
  7. name: 'calendar.events',
  8. description: `List all calendar entries`,
  9. requiresBackup: true,
  10. // Run on a v3 lib / backup object.
  11. run (lib, { backup }) {
  12. return calendarReport(backup)
  13. },
  14. // Fields for apps report
  15. output: {
  16. timestamp: el => (new Date((el.start_date + 978307200) * 1000).toDateString()) + ' ' + (new Date((el.start_date + 978307200) * 1000).toTimeString()),
  17. timestamp_string: el => el.start_date_string,
  18. title: el => el.summary,
  19. content: el => el.description,
  20. calendarId: el => el.calendar_id,
  21. calendarTitle: el => el.calendar_title
  22. }
  23. }
  24. function calendarReport (backup) {
  25. return new Promise((resolve, reject) => {
  26. backup.openDatabase(CAL_DB)
  27. .then(db => {
  28. const query = `
  29. SELECT
  30. CalendarItem.*,
  31. ${apple_timestamp.parse('CalendarItem.start_date')} AS start_date_string,
  32. Calendar.title as calendar_title
  33. FROM CalendarItem
  34. LEFT JOIN Calendar ON
  35. Calendar.ROWID = CalendarItem.calendar_id
  36. ORDER BY start_date
  37. `
  38. db.all(query, async function (err, rows) {
  39. if (err) reject(err)
  40. resolve(rows)
  41. })
  42. })
  43. .catch(reject)
  44. })
  45. }