forked from sheepzh/time-tracker-4-browser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcate-initializer.ts
More file actions
49 lines (44 loc) · 1.11 KB
/
Copy pathcate-initializer.ts
File metadata and controls
49 lines (44 loc) · 1.11 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import cateDatabase from '@db/cate-database'
import { batchChangeCate } from '@service/site-service'
import type { Migrator } from "./types"
type InitialCate = {
name: string
hosts: string[]
}
const DEMO_ITEMS: InitialCate[] = [
{
name: 'Video',
hosts: [
'www.youtube.com',
'www.bilibili.com',
],
}, {
name: 'Tech',
hosts: [
'github.com',
'stackoverflow.com',
],
}, {
name: 'Info',
hosts: [
'www.baidu.com',
'www.google.com',
],
}
]
async function initItem(item: InitialCate) {
const { name, hosts } = item
const cate = await cateDatabase.add(name)
const cateId = cate.id
const siteKeys = hosts.map(host => ({ host, type: 'normal' } satisfies tt4b.site.SiteKey))
await batchChangeCate(cateId, siteKeys)
}
export default class CateInitializer implements Migrator {
async onInstall(): Promise<void> {
for (const item of DEMO_ITEMS) {
await initItem(item)
}
}
onUpdate(_version: string): void {
}
}