-
Notifications
You must be signed in to change notification settings - Fork 0
/
kobo.js
62 lines (53 loc) · 1.65 KB
/
kobo.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
//kobo.js
const sqlite3 = require("sqlite3");
const path = require("path");
// Function to open the database and fetch bookmarks
async function fetchBookmarks(dbFilePath) {
return new Promise((resolve, reject) => {
const dbPath = path.isAbsolute(dbFilePath)
? dbFilePath
: path.resolve(dbFilePath);
// Open the SQLite database
const db = new sqlite3.Database(dbPath, (err) => {
if (err) {
return reject(`Error opening database: ${err.message}`);
}
});
// Query to fetch all entries from the Bookmark table
const query = "SELECT * FROM Bookmark ORDER BY BookmarkID";
db.all(query, [], (err, rows) => {
if (err) {
return reject(`Error querying Bookmark table: ${err.message}`);
}
if (rows.length === 0) {
return resolve([]);
}
resolve(rows);
});
});
}
// Function to process a single bookmark
async function processBookmark(row, volumePath, searchEpub) {
const { VolumeID: volumeId, Text: text, Annotation: annotation } = row;
const cleanedAnnotation = annotation || "";
try {
const cfi = await searchEpub(volumePath, text);
console.log(`Found CFI for: ${cfi}`);
// Return the annotation data in the specified JSON format
return {
value: cfi,
color: "yellow", // Default color, can be customized
text,
note: cleanedAnnotation,
created: new Date().toISOString(), // Current date-time in ISO format
modified: "", // Optional field
};
} catch (err) {
throw new Error(`Error while searching for CFI: ${err.message}`);
}
}
// Exported functions
module.exports = {
fetchBookmarks,
processBookmark,
};