Skip to content

Commit 720ce3e

Browse files
committed
refactor(subscribes): simplify userInfo handling and update subscription properties
1 parent 4c45018 commit 720ce3e

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

frontend/src/stores/subscribes.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,7 @@ export const useSubscribesStore = defineStore('subscribes', () => {
135135
}
136136

137137
const _doUpdateSub = async (s: Subscription) => {
138-
const pattern =
139-
/upload=(-?)([E+.\d]+);\s*download=(-?)([E+.\d]+);\s*total=([E+.\d]+);\s*expire=(\d*)/
140-
let userInfo = 'upload=0; download=0; total=0; expire=0'
138+
const userInfo: Recordable = {}
141139
let body = ''
142140
let proxies: Record<string, any>[] = []
143141

@@ -160,7 +158,12 @@ export const useSubscribesStore = defineStore('subscribes', () => {
160158
},
161159
})
162160
Object.assign(h, s.header.response)
163-
h['Subscription-Userinfo'] && (userInfo = h['Subscription-Userinfo'] as string)
161+
if (h['Subscription-Userinfo']) {
162+
;(h['Subscription-Userinfo'] as string).split(/\s*;\s*/).forEach((part) => {
163+
const [key, value] = part.split('=')
164+
userInfo[key] = parseInt(value) || 0
165+
})
166+
}
164167
body = b
165168
}
166169

@@ -233,13 +236,10 @@ export const useSubscribesStore = defineStore('subscribes', () => {
233236
}
234237
}
235238

236-
const match = userInfo.match(pattern) || [0, 0, 0, 0, 0]
237-
238-
const [, , upload = 0, , download = 0, total = 0, expire = 0] = match
239-
s.upload = Number(upload)
240-
s.download = Number(download)
241-
s.total = Number(total)
242-
s.expire = Number(expire) * 1000
239+
s.upload = userInfo.upload
240+
s.download = userInfo.download
241+
s.total = userInfo.total
242+
s.expire = userInfo.expire * 1000
243243
s.updateTime = Date.now()
244244
s.proxies = proxies.map(({ name, type, __id__ }) => ({ id: __id__, name, type }))
245245

0 commit comments

Comments
 (0)