forked from WebMemex/webmemex-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
30 lines (24 loc) · 1.15 KB
/
Copy pathindex.js
File metadata and controls
30 lines (24 loc) · 1.15 KB
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
// Stuff that is to be accessible from other modules (folders)
import docuri from 'docuri'
import randomString from 'src/util/random-string'
export const visitKeyPrefix = 'visit/'
// Creates an _id string given the variables, or vice versa parses such strings
// We simply use the creation time for the id, for easy chronological sorting.
// We add a random string we call a 'nonce' to prevent accidental collisions.
export const convertVisitDocId = docuri.route(`${visitKeyPrefix}:timestamp/:nonce`)
const convertAnyTimestampedDocId = docuri.route(':type/:timestamp/:nonce')
export const getTimestamp = doc =>
Number.parseInt(convertAnyTimestampedDocId(doc._id).timestamp)
export function generateVisitDocId({timestamp, nonce} = {}) {
const date = timestamp ? new Date(timestamp) : new Date()
return convertVisitDocId({
timestamp: date.getTime(),
nonce: nonce || randomString(),
})
}
// Decide whether to remember or ignore a visited page.
export function isWorthRemembering({url}) {
// Just remember http(s) pages, ignoring data uris, newtab, ...
const loggableUrlPattern = /^https?:\/\//
return loggableUrlPattern.test(url)
}