-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsearch.js
46 lines (39 loc) · 1.13 KB
/
search.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
import alfy from 'alfy';
import sqlite3 from 'sqlite3';
import fs from 'fs';
import os from 'os';
var dbPath = getDbPath();
var db = new sqlite3.Database(dbPath);
db.all(`
SELECT
Title,
ResourceId,
Authors
FROM
Records
WHERE
ResourceDriverName = 'logos' AND
Availability >= 1 AND
Title LIKE '%${alfy.input}%' OR
UserTitle LIKE '%${alfy.input}%' OR
UserAbbreviatedTitle LIKE '%${alfy.input}%' OR
AbbreviatedTitle LIKE '%${alfy.input}%' OR
ResourceId LIKE '%${alfy.input}%'
ORDER BY
LastAccessedUtc DESC
`, function (err, rows) {
alfy.output(rows.map(function (row) {
return {
title: row.UserTitle || row.Title,
subtitle: row.Authors,
arg: row.ResourceId,
}
}));
});
function getDbPath() {
const dataPath = `${os.homedir()}/Library/Application Support/Logos4/Data`;
var folder = fs.readdirSync(dataPath).find(f => {
return fs.existsSync(`${dataPath}/${f}/LibraryCatalog/catalog.db`);
});
return `${dataPath}/${folder}/LibraryCatalog/catalog.db`;
}