-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
83 lines (67 loc) · 1.68 KB
/
index.js
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
'use strict'
const { createWriteStream } = require('fs')
const { remote } = require('electron')
const { join } = require('path')
class AeonPlugin {
constructor(options, context) {
this.options = Object.assign({}, AeonPlugin.defaults, options)
this.context = context
}
encode(string) {
return this.options.quotes ?
`"${string == null ? '' : string.replace(/"+/, '""')}"` :
`${string == null ? '' : string.replace(/,/, '')}`
}
async export(data) {
let path = await this.dialog.save({
defaultPath: this.defaultPath
})
if (!path) return
this.logger.info('Exporting items to Aeon Timeline...')
let ws = createWriteStream(path, {
autoclose: true,
flags: 'w'
})
if (this.options.header) {
ws.write(`${this.header}\n`)
}
for (let items of data) {
for (let item of items['@graph']) {
try {
ws.write(`${[
this.encode(item.title),
this.encode(item.date),
this.encode(item.creator || item.author),
this.encode(item.photo.map(p => p.path).join('|'))
].join(',')}\n`)
} catch (e) {
this.logger.error(e.message)
}
}
}
ws.end()
}
get dialog() {
return this.context.require('../dialog')
}
get defaultPath() {
return join(
remote.app.getPath('home'),
this.options.file
)
}
get header() {
return this.options.quotes ?
'"Title","Start","Author","Links"' :
'Title,Start,Author,Links'
}
get logger() {
return this.context.logger
}
}
AeonPlugin.defaults = {
file: 'tropy-aeon.csv',
header: false,
quotes: true
}
module.exports = AeonPlugin