mirror of
https://github.com/v2rayA/v2rayA.git
synced 2026-11-20 23:02:25 +03:00
Merge pull request #1984 from Zakkaus/subscription-status
fix(subscription): show the usage once; tidy the header and the sidebar handle
This commit is contained in:
9 files changed
+91
-19
No files matched your search
@@ -23,6 +23,7 @@ export default {
|
||||
darkTheme: "Dark Theme",
|
||||
lightTheme: "Light Theme",
|
||||
autoTheme: "Auto Theme",
|
||||
expand: "Show the connection status",
|
||||
},
|
||||
welcome: {
|
||||
title: "Welcome",
|
||||
|
||||
@@ -23,6 +23,7 @@ export default {
|
||||
darkTheme: "پوسته تاریک",
|
||||
lightTheme: "پوسته روشن",
|
||||
autoTheme: "پوسته خودکار",
|
||||
expand: "نمایش وضعیت اتصال",
|
||||
},
|
||||
welcome: {
|
||||
title: "خوش آمدید",
|
||||
|
||||
@@ -23,6 +23,7 @@ export default {
|
||||
darkTheme: "어두운 테마",
|
||||
lightTheme: "밝은 테마",
|
||||
autoTheme: "자동 테마",
|
||||
expand: "연결 상태 표시",
|
||||
},
|
||||
welcome: {
|
||||
title: "환영합니다",
|
||||
|
||||
@@ -23,6 +23,7 @@ export default {
|
||||
darkTheme: "Tema escuro",
|
||||
lightTheme: "Tema claro",
|
||||
autoTheme: "Tema automático",
|
||||
expand: "Mostrar o estado da conexão",
|
||||
},
|
||||
welcome: {
|
||||
title: "Boas-vindas",
|
||||
|
||||
@@ -23,6 +23,7 @@ export default {
|
||||
darkTheme: "Тёмная тема",
|
||||
lightTheme: "Светлая тема",
|
||||
autoTheme: "Автоматическая тема",
|
||||
expand: "Показать состояние подключения",
|
||||
},
|
||||
welcome: {
|
||||
title: "Добро пожаловать",
|
||||
|
||||
@@ -23,6 +23,7 @@ export default {
|
||||
darkTheme: "深色主题",
|
||||
lightTheme: "浅色主题",
|
||||
autoTheme: "自动主题",
|
||||
expand: "显示连接状态",
|
||||
},
|
||||
welcome: {
|
||||
title: "欢迎使用",
|
||||
|
||||
+13
-4
@@ -8,7 +8,7 @@
|
||||
@mouseenter.native="showSidebar = true"
|
||||
@click.native="showSidebar = true"
|
||||
>
|
||||
<i class="lucide icon-panel-left" style="font-size: 36px; line-height: 1" />
|
||||
<i class="lucide icon-panel-left sidebar-handle" :title="$t('common.expand')" />
|
||||
</b-sidebar>
|
||||
<b-sidebar
|
||||
:open="showSidebar"
|
||||
@@ -455,9 +455,7 @@
|
||||
>
|
||||
<b-field
|
||||
v-if="tab === subi + 2"
|
||||
:label="`${sub.host.toUpperCase()}(${sub.servers.length}${
|
||||
sub.info ? ') (' : ''
|
||||
}${sub.info})`"
|
||||
:label="`${sub.host.toUpperCase()} (${sub.servers.length})${sub.info ? ' · ' + sub.info : ''}`"
|
||||
>
|
||||
<b-table
|
||||
:current-page.sync="currentPage[sub.id]"
|
||||
@@ -2323,6 +2321,17 @@ $coverBackground: rgba(0, 0, 0, 0.6);
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
// The handle that brings the status sidebar back was a 36px glyph in a
|
||||
// shadowed box, larger than any control on the page; a phone showed it as the
|
||||
// biggest thing on screen. Keep it a small, evenly padded target.
|
||||
.sidebar-handle {
|
||||
display: block;
|
||||
font-size: 20px;
|
||||
line-height: 1;
|
||||
padding: 6px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.b-sidebar.node-status-sidebar > .sidebar-content.is-fixed {
|
||||
left: 1px;
|
||||
top: 4.25rem;
|
||||
|
||||
@@ -105,21 +105,32 @@ type SubscriptionUserInfo struct {
|
||||
Expire time.Time
|
||||
}
|
||||
|
||||
// Known reports whether the provider sent any usage field at all.
|
||||
func (sui *SubscriptionUserInfo) Known() bool {
|
||||
return sui.Download != -1 || sui.Upload != -1 || sui.Total != -1 || !sui.Expire.IsZero()
|
||||
}
|
||||
|
||||
// String renders the usage the way the node list shows it: what is used of
|
||||
// what is available, and the day it expires. It used to list every raw
|
||||
// field ("download: 0 GB; upload: 0 GB; total: 107 GB; expire: 2026-10-04
|
||||
// 18:59 UTC") in integer GB next to the provider's own text in GiB.
|
||||
func (sui *SubscriptionUserInfo) String() string {
|
||||
const gib = 1024 * 1024 * 1024
|
||||
var outputs []string
|
||||
if sui.Download != -1 {
|
||||
outputs = append(outputs, fmt.Sprintf("download: %v GB", sui.Download/1e9))
|
||||
}
|
||||
if sui.Upload != -1 {
|
||||
outputs = append(outputs, fmt.Sprintf("upload: %v GB", sui.Upload/1e9))
|
||||
}
|
||||
if sui.Total != -1 {
|
||||
outputs = append(outputs, fmt.Sprintf("total: %v GB", sui.Total/1e9))
|
||||
if sui.Download != -1 || sui.Upload != -1 {
|
||||
used := float64(max(sui.Download, 0)+max(sui.Upload, 0)) / gib
|
||||
if sui.Total > 0 {
|
||||
outputs = append(outputs, fmt.Sprintf("Used %.2f GiB / %.2f GiB", used, float64(sui.Total)/gib))
|
||||
} else {
|
||||
outputs = append(outputs, fmt.Sprintf("Used %.2f GiB", used))
|
||||
}
|
||||
} else if sui.Total > 0 {
|
||||
outputs = append(outputs, fmt.Sprintf("Total %.2f GiB", float64(sui.Total)/gib))
|
||||
}
|
||||
if !sui.Expire.IsZero() {
|
||||
outputs = append(outputs, fmt.Sprintf("expire: %v UTC", sui.Expire.Format("2006-01-02 15:04")))
|
||||
outputs = append(outputs, "Expires "+sui.Expire.Local().Format("2006-01-02"))
|
||||
}
|
||||
return strings.Join(outputs, "; ")
|
||||
return strings.Join(outputs, " · ")
|
||||
}
|
||||
|
||||
func parseSubscriptionUserInfo(str string) SubscriptionUserInfo {
|
||||
@@ -201,11 +212,11 @@ func ResolveSubscriptionWithClient(source string, client *http.Client) (infos []
|
||||
// node; treat an unparseable or empty body as a failed fetch
|
||||
return nil, "", common.Coded("SUBSCRIPTION_EMPTY", fmt.Errorf("no server found in the subscription response"), nil)
|
||||
}
|
||||
subscriptionUserInfo := res.Header.Get("Subscription-Userinfo")
|
||||
sui := parseSubscriptionUserInfo(subscriptionUserInfo)
|
||||
if len(status) > 0 {
|
||||
status = sui.String() + "|" + status
|
||||
} else {
|
||||
// The Subscription-Userinfo header is the standard form of the usage; a
|
||||
// STATUS= line in the body is the provider's own prose for the same
|
||||
// numbers. Showing both printed every figure twice in two formats.
|
||||
sui := parseSubscriptionUserInfo(res.Header.Get("Subscription-Userinfo"))
|
||||
if sui.Known() {
|
||||
status = sui.String()
|
||||
}
|
||||
return infos, status, nil
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestSubscriptionUserInfoString(t *testing.T) {
|
||||
const gib = 1024 * 1024 * 1024
|
||||
cases := []struct {
|
||||
name string
|
||||
sui SubscriptionUserInfo
|
||||
want string
|
||||
}{
|
||||
{"usage and expiry", SubscriptionUserInfo{Upload: 0, Download: 1041529159, Total: 100 * gib, Expire: time.Date(2026, 10, 4, 18, 59, 0, 0, time.UTC)},
|
||||
"Used 0.97 GiB / 100.00 GiB · Expires " + time.Date(2026, 10, 4, 18, 59, 0, 0, time.UTC).Local().Format("2006-01-02")},
|
||||
{"no total", SubscriptionUserInfo{Upload: gib, Download: gib, Total: -1}, "Used 2.00 GiB"},
|
||||
{"total only", SubscriptionUserInfo{Upload: -1, Download: -1, Total: 10 * gib}, "Total 10.00 GiB"},
|
||||
{"nothing", SubscriptionUserInfo{Upload: -1, Download: -1, Total: -1}, ""},
|
||||
}
|
||||
for _, c := range cases {
|
||||
if got := c.sui.String(); got != c.want {
|
||||
t.Errorf("%s: got %q, want %q", c.name, got, c.want)
|
||||
}
|
||||
if c.sui.Known() != (c.want != "") {
|
||||
t.Errorf("%s: Known() disagrees with the rendered text", c.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseSubscriptionUserInfoHeader(t *testing.T) {
|
||||
sui := parseSubscriptionUserInfo("upload=0; download=1041529159; total=107374182400; expire=1791140340")
|
||||
if sui.Upload != 0 || sui.Download != 1041529159 || sui.Total != 107374182400 {
|
||||
t.Fatalf("fields: %+v", sui)
|
||||
}
|
||||
if sui.Expire.UTC().Format("2006-01-02 15:04") != "2026-10-04 18:59" {
|
||||
t.Fatalf("expire: %v", sui.Expire)
|
||||
}
|
||||
if !sui.Known() {
|
||||
t.Fatal("a header with fields must count as known")
|
||||
}
|
||||
empty := parseSubscriptionUserInfo("")
|
||||
if empty.Known() {
|
||||
t.Fatal("an empty header must not count as known")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user