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
50 lines (45 loc) · 1.15 KB
/
cate-initializer.ts
File metadata and controls
50 lines (45 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import cateService from "@service/cate-service"
import { batchSaveSiteCate } from "@service/site-service"
import { Migrator } from "./common"
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 cateService.add(name)
const cateId = cate.id
const siteKeys = hosts.map(host => ({ host, type: 'normal' } satisfies timer.site.SiteKey))
await batchSaveSiteCate(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 {
version === '3.0.1' && this.onInstall()
}
}