events.js 1.3 KB

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