implemented SlopStore and tested
This commit is contained in:
@@ -56,12 +56,24 @@ export class SlopStore {
|
||||
this.slopdb = slopdb
|
||||
}
|
||||
|
||||
async store(domain: string, path: string) {
|
||||
|
||||
async store(domain: string, path: string): Promise<IDBValidKey> {
|
||||
const slop_store = this.slopdb.transaction(SlopStore.slop_objectstore_name, "readwrite").objectStore(SlopStore.slop_objectstore_name)
|
||||
const existing_domain = await slop_store.get(domain)
|
||||
if(existing_domain) {
|
||||
// append this path to the existing domain object
|
||||
existing_domain.paths.add(path)
|
||||
return slop_store.put(existing_domain)
|
||||
} else {
|
||||
// create a domain object containing this path
|
||||
const paths_set = new Set()
|
||||
paths_set.add(path)
|
||||
return slop_store.add({domain: domain, paths: paths_set})
|
||||
}
|
||||
}
|
||||
|
||||
async get(url: string) {
|
||||
|
||||
async get(url: URL) {
|
||||
const slop_store = this.slopdb.transaction(SlopStore.slop_objectstore_name, "readonly").objectStore(SlopStore.slop_objectstore_name)
|
||||
return await slop_store.get(url.hostname)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user