refactor: simplify auth and subscription links
This commit is contained in:
@@ -79,40 +79,40 @@ func TestNormalizeTarget(t *testing.T) {
|
||||
func TestNormalizeTargetAlias(t *testing.T) {
|
||||
// All aliases should map correctly
|
||||
aliases := map[string]string{
|
||||
"clash": TargetMihomo,
|
||||
"clashmeta": TargetMihomo,
|
||||
"clash-meta": TargetMihomo,
|
||||
"meta": TargetMihomo,
|
||||
"mihomo": TargetMihomo,
|
||||
"stash": TargetStash,
|
||||
"surge": TargetSurge,
|
||||
"surgemac": TargetSurgeMac,
|
||||
"surge-mac": TargetSurgeMac,
|
||||
"surge_mac": TargetSurgeMac,
|
||||
"surfboard": TargetSurfboard,
|
||||
"loon": TargetLoon,
|
||||
"egern": TargetEgern,
|
||||
"shadowrocket": TargetShadowrocket,
|
||||
"sr": TargetShadowrocket,
|
||||
"qx": TargetQX,
|
||||
"quanx": TargetQX,
|
||||
"quantumult": TargetQX,
|
||||
"quantumultx": TargetQX,
|
||||
"quantumult-x": TargetQX,
|
||||
"singbox": TargetSingBox,
|
||||
"sing-box": TargetSingBox,
|
||||
"sfa": TargetSingBox,
|
||||
"karing": TargetSingBox,
|
||||
"v2ray": TargetV2ray,
|
||||
"v2rayn": TargetV2ray,
|
||||
"v2rayng": TargetV2ray,
|
||||
"base64": TargetV2ray,
|
||||
"uri": TargetURI,
|
||||
"uris": TargetURI,
|
||||
"plain": TargetURI,
|
||||
"text": TargetURI,
|
||||
"json": TargetJSON,
|
||||
"raw": TargetJSON,
|
||||
"clash": TargetMihomo,
|
||||
"clashmeta": TargetMihomo,
|
||||
"clash-meta": TargetMihomo,
|
||||
"meta": TargetMihomo,
|
||||
"mihomo": TargetMihomo,
|
||||
"stash": TargetStash,
|
||||
"surge": TargetSurge,
|
||||
"surgemac": TargetSurgeMac,
|
||||
"surge-mac": TargetSurgeMac,
|
||||
"surge_mac": TargetSurgeMac,
|
||||
"surfboard": TargetSurfboard,
|
||||
"loon": TargetLoon,
|
||||
"egern": TargetEgern,
|
||||
"shadowrocket": TargetShadowrocket,
|
||||
"sr": TargetShadowrocket,
|
||||
"qx": TargetQX,
|
||||
"quanx": TargetQX,
|
||||
"quantumult": TargetQX,
|
||||
"quantumultx": TargetQX,
|
||||
"quantumult-x": TargetQX,
|
||||
"singbox": TargetSingBox,
|
||||
"sing-box": TargetSingBox,
|
||||
"sfa": TargetSingBox,
|
||||
"karing": TargetSingBox,
|
||||
"v2ray": TargetV2ray,
|
||||
"v2rayn": TargetV2ray,
|
||||
"v2rayng": TargetV2ray,
|
||||
"base64": TargetV2ray,
|
||||
"uri": TargetURI,
|
||||
"uris": TargetURI,
|
||||
"plain": TargetURI,
|
||||
"text": TargetURI,
|
||||
"json": TargetJSON,
|
||||
"raw": TargetJSON,
|
||||
}
|
||||
for alias, want := range aliases {
|
||||
t.Run("alias_"+alias, func(t *testing.T) {
|
||||
@@ -471,7 +471,7 @@ func TestFilterRuleJSON(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRecordStructsJSON(t *testing.T) {
|
||||
// Verify SourceRecord, CollectionRecord, TemplateRecord, DownloadGrantRecord, RecycleBinRecord
|
||||
// Verify SourceRecord, CollectionRecord, TemplateRecord, RecycleBinRecord
|
||||
// can marshal/unmarshal without errors.
|
||||
t.Run("SourceRecord", func(t *testing.T) {
|
||||
r := SourceRecord{ID: "s1", Name: "test", Type: "remote", URL: "http://example.com"}
|
||||
@@ -518,21 +518,6 @@ func TestRecordStructsJSON(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("DownloadGrantRecord", func(t *testing.T) {
|
||||
r := DownloadGrantRecord{ID: "g1", ResourceType: "source", ResourceId: "s1"}
|
||||
data, err := json.Marshal(r)
|
||||
if err != nil {
|
||||
t.Fatalf("marshal: %v", err)
|
||||
}
|
||||
var parsed DownloadGrantRecord
|
||||
if err := json.Unmarshal(data, &parsed); err != nil {
|
||||
t.Fatalf("unmarshal: %v", err)
|
||||
}
|
||||
if parsed.ResourceType != "source" {
|
||||
t.Errorf("ResourceType = %q, want source", parsed.ResourceType)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("RecycleBinRecord", func(t *testing.T) {
|
||||
r := RecycleBinRecord{ID: "r1", ResourceType: "source", ResourceId: "s1", Snapshot: map[string]any{"k": "v"}}
|
||||
data, err := json.Marshal(r)
|
||||
|
||||
+18
-30
@@ -51,30 +51,30 @@ type CustomRule struct {
|
||||
|
||||
// SourceRecord is the full DB record for a subscription source.
|
||||
type SourceRecord struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
URL string `json:"url"`
|
||||
Content string `json:"content"`
|
||||
Enabled bool `json:"enabled"`
|
||||
Filters []FilterRule `json:"filters"`
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
URL string `json:"url"`
|
||||
Content string `json:"content"`
|
||||
Enabled bool `json:"enabled"`
|
||||
Filters []FilterRule `json:"filters"`
|
||||
Meta map[string]any `json:"meta"`
|
||||
CreatedAt int64 `json:"createdAt"`
|
||||
UpdatedAt int64 `json:"updatedAt"`
|
||||
CreatedAt int64 `json:"createdAt"`
|
||||
UpdatedAt int64 `json:"updatedAt"`
|
||||
}
|
||||
|
||||
// CollectionRecord is the full DB record for a subscription collection.
|
||||
type CollectionRecord struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
SourceIds []string `json:"sourceIds"`
|
||||
Filters []FilterRule `json:"filters"`
|
||||
TemplateId string `json:"templateId"`
|
||||
IgnoreFailed bool `json:"ignoreFailed"`
|
||||
Enabled bool `json:"enabled"`
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
SourceIds []string `json:"sourceIds"`
|
||||
Filters []FilterRule `json:"filters"`
|
||||
TemplateId string `json:"templateId"`
|
||||
IgnoreFailed bool `json:"ignoreFailed"`
|
||||
Enabled bool `json:"enabled"`
|
||||
Meta map[string]any `json:"meta"`
|
||||
CreatedAt int64 `json:"createdAt"`
|
||||
UpdatedAt int64 `json:"updatedAt"`
|
||||
CreatedAt int64 `json:"createdAt"`
|
||||
UpdatedAt int64 `json:"updatedAt"`
|
||||
}
|
||||
|
||||
// TemplateRecord is the full DB record for a routing template.
|
||||
@@ -87,18 +87,6 @@ type TemplateRecord struct {
|
||||
UpdatedAt int64 `json:"updatedAt"`
|
||||
}
|
||||
|
||||
// DownloadGrantRecord represents a scoped download share token.
|
||||
type DownloadGrantRecord struct {
|
||||
ID string `json:"id"`
|
||||
ResourceType string `json:"resourceType"`
|
||||
ResourceId string `json:"resourceId"`
|
||||
Target string `json:"target,omitempty"`
|
||||
ExpiresAt *int64 `json:"expiresAt,omitempty"`
|
||||
Enabled bool `json:"enabled"`
|
||||
CreatedAt int64 `json:"createdAt"`
|
||||
UpdatedAt int64 `json:"updatedAt"`
|
||||
}
|
||||
|
||||
// RecycleBinRecord represents a soft-deleted resource snapshot.
|
||||
type RecycleBinRecord struct {
|
||||
ID string `json:"id"`
|
||||
|
||||
Reference in New Issue
Block a user