Skip to content

Commit 83fed20

Browse files
author
sheepzh
committed
Fix bug with collecting aliases (#162)
1 parent c84708b commit 83fed20

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/database/host-alias-database.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ import { REMAIN_WORD_PREFIX } from "./common/constant"
1111
const DB_KEY_PREFIX = REMAIN_WORD_PREFIX + "ALIAS"
1212
const DB_KEY_PREFIX_M = REMAIN_WORD_PREFIX + "ALIASM"
1313

14-
const SOURCE_PREFIX_MAP: { [source in timer.site.AliasSource]: string } = {
14+
type _AliasSourceAbbr = 'u' | 'd'
15+
16+
const SOURCE_PREFIX_MAP: Record<timer.site.AliasSource, _AliasSourceAbbr> = {
1517
USER: 'u',
1618
DETECTED: 'd'
1719
}
18-
const ABBR_MAP = {
19-
'u': 'USER',
20-
'd': 'DETECTED'
20+
const ABBR_MAP: Record<_AliasSourceAbbr, timer.site.AliasSource> = {
21+
u: 'USER',
22+
d: 'DETECTED'
2123
}
2224

2325
function generateKey(aliasKey: timer.site.AliasKey): string {
@@ -39,7 +41,7 @@ function aliasKeyOf(key: string): timer.site.AliasKey {
3941
}
4042

4143
function valueOf(aliasKey: timer.site.AliasKey, value: string): timer.site.Alias {
42-
const abbr = value.substring(0, 1)
44+
const abbr = value.substring(0, 1) as _AliasSourceAbbr
4345

4446
return {
4547
...aliasKey,
@@ -70,13 +72,13 @@ class HostAliasDatabase extends BaseDatabase {
7072
// Force update
7173
return this.storage.put(key, value)
7274
}
73-
const existVal = this.storage.getOne(key)
75+
const existVal = await this.storage.getOne(key)
7476
if (!existVal || typeof existVal !== 'string') {
7577
// Force update
7678
return this.storage.put(key, value)
7779
}
78-
const abbr = (existVal as string).substring(0, 1)
79-
if (ABBR_MAP[abbr] === 'DETECTED') {
80+
const abbr = (existVal as string).substring(0, 1) as _AliasSourceAbbr
81+
if (abbr === 'd') {
8082
// Update
8183
return this.storage.put(key, value)
8284
}

0 commit comments

Comments
 (0)