mirror of
https://github.com/MetaCubeX/metacubexd.git
synced 2024-11-24 09:45:35 +08:00
fix: subscriptionInfo may not be valid
This commit is contained in:
parent
3e4078d99e
commit
e7ba6c7c34
@ -3,21 +3,20 @@ import dayjs from 'dayjs'
|
|||||||
import type { SubscriptionInfo as ISubscriptionInfo } from '~/types'
|
import type { SubscriptionInfo as ISubscriptionInfo } from '~/types'
|
||||||
|
|
||||||
const getSubscriptionsInfo = (subscriptionInfo: ISubscriptionInfo) => {
|
const getSubscriptionsInfo = (subscriptionInfo: ISubscriptionInfo) => {
|
||||||
const total = byteSize(subscriptionInfo.Total, { units: 'iec' })
|
const { Download = 0, Upload = 0, Total = 0, Expire = 0 } = subscriptionInfo
|
||||||
const used = byteSize(subscriptionInfo.Download + subscriptionInfo.Upload, {
|
|
||||||
|
const total = byteSize(Total, { units: 'iec' })
|
||||||
|
const used = byteSize(Download + Upload, {
|
||||||
units: 'iec',
|
units: 'iec',
|
||||||
})
|
})
|
||||||
const percentage = (
|
const percentage = (((Download + Upload) / Total) * 100).toFixed(2)
|
||||||
((subscriptionInfo.Download + subscriptionInfo.Upload) /
|
|
||||||
subscriptionInfo.Total) *
|
|
||||||
100
|
|
||||||
).toFixed(2)
|
|
||||||
const expireStr = () => {
|
const expireStr = () => {
|
||||||
if (subscriptionInfo.Expire === 0) {
|
if (subscriptionInfo.Expire === 0) {
|
||||||
return 'Null'
|
return 'Null'
|
||||||
}
|
}
|
||||||
|
|
||||||
return dayjs(subscriptionInfo.Expire * 1000).format('YYYY-MM-DD')
|
return dayjs(Expire * 1000).format('YYYY-MM-DD')
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -29,7 +28,7 @@ const getSubscriptionsInfo = (subscriptionInfo: ISubscriptionInfo) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const SubscriptionInfo = (props: {
|
export const SubscriptionInfo = (props: {
|
||||||
subscriptionInfo: ISubscriptionInfo
|
subscriptionInfo?: ISubscriptionInfo
|
||||||
}) => {
|
}) => {
|
||||||
if (!props.subscriptionInfo) {
|
if (!props.subscriptionInfo) {
|
||||||
return
|
return
|
||||||
|
11
src/types/index.d.ts
vendored
11
src/types/index.d.ts
vendored
@ -38,15 +38,16 @@ export type ProxyNode = {
|
|||||||
delay: number
|
delay: number
|
||||||
}[]
|
}[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export type SubscriptionInfo = {
|
export type SubscriptionInfo = {
|
||||||
Download: number
|
Download?: number
|
||||||
Upload: number
|
Upload?: number
|
||||||
Total: number
|
Total?: number
|
||||||
Expire: number
|
Expire?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ProxyProvider = {
|
export type ProxyProvider = {
|
||||||
subscriptionInfo: SubscriptionInfo
|
subscriptionInfo?: SubscriptionInfo
|
||||||
name: string
|
name: string
|
||||||
proxies: ProxyNode[]
|
proxies: ProxyNode[]
|
||||||
testUrl: string
|
testUrl: string
|
||||||
|
Loading…
Reference in New Issue
Block a user