1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-01-06 09:15:37 -05:00

Add data URL Link support to subscription

This commit is contained in:
Shelikhoo
2023-11-25 16:53:05 +00:00
committed by Xiaokang Wang (Shelikhoo)
parent c61820c7cd
commit f112667190
10 changed files with 121 additions and 2 deletions

View File

@@ -2,6 +2,10 @@ package dataurlfetcher
import (
"context"
"strings"
"github.com/vincent-petithory/dataurl"
"github.com/v2fly/v2ray-core/v5/app/subscription"
"github.com/v2fly/v2ray-core/v5/app/subscription/documentfetcher"
"github.com/v2fly/v2ray-core/v5/common"
@@ -20,5 +24,15 @@ func init() {
type dataURLFetcher struct{}
func (d *dataURLFetcher) DownloadDocument(ctx context.Context, source *subscription.ImportSource, opts ...documentfetcher.FetcherOptions) ([]byte, error) {
panic("implement me")
dataURL, err := dataurl.DecodeString(source.Url)
if err != nil {
return nil, newError("unable to decode dataURL").Base(err)
}
if dataURL.MediaType.Type != "application" {
return nil, newError("unsupported media type: ", dataURL.MediaType.Type)
}
if !strings.HasPrefix(dataURL.MediaType.Subtype, "vnd.v2ray.subscription") {
return nil, newError("unsupported media subtype: ", dataURL.MediaType.Subtype)
}
return []byte(source.Url), nil
}