-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add data URL Link support to subscription
- Loading branch information
1 parent
cafc2f3
commit 1bb7eb5
Showing
10 changed files
with
121 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package dataurlsingle | ||
|
||
import ( | ||
"bytes" | ||
"strings" | ||
|
||
"github.com/vincent-petithory/dataurl" | ||
|
||
"github.com/v2fly/v2ray-core/v5/app/subscription/containers" | ||
"github.com/v2fly/v2ray-core/v5/common" | ||
) | ||
|
||
//go:generate go run github.com/v2fly/v2ray-core/v5/common/errors/errorgen | ||
|
||
func newSingularDataURLParser() containers.SubscriptionContainerDocumentParser { | ||
return &parser{} | ||
} | ||
|
||
type parser struct{} | ||
|
||
func (p parser) ParseSubscriptionContainerDocument(rawConfig []byte) (*containers.Container, error) { | ||
dataURL, err := dataurl.Decode(bytes.NewReader(rawConfig)) | ||
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-singular") { | ||
return nil, newError("unsupported media subtype: ", dataURL.MediaType.Subtype) | ||
} | ||
result := &containers.Container{} | ||
result.Kind = "DataURLSingle" | ||
result.Metadata = make(map[string]string) | ||
result.ServerSpecs = append(result.ServerSpecs, containers.UnparsedServerConf{ | ||
KindHint: "", | ||
Content: dataURL.Data, | ||
}) | ||
return result, nil | ||
} | ||
|
||
func init() { | ||
common.Must(containers.RegisterParser("DataURLSingle", newSingularDataURLParser())) | ||
} |
9 changes: 9 additions & 0 deletions
9
app/subscription/containers/dataurlsingle/errors.generated.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package dataurlsingle | ||
|
||
import "github.com/v2fly/v2ray-core/v5/common/errors" | ||
|
||
type errPathObjHolder struct{} | ||
|
||
func newError(values ...interface{}) *errors.Error { | ||
return errors.New(values...).WithPathObj(errPathObjHolder{}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
app/subscription/documentfetcher/dataurlfetcher/errors.generated.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package dataurlfetcher | ||
|
||
import "github.com/v2fly/v2ray-core/v5/common/errors" | ||
|
||
type errPathObjHolder struct{} | ||
|
||
func newError(values ...interface{}) *errors.Error { | ||
return errors.New(values...).WithPathObj(errPathObjHolder{}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package engineering | ||
|
||
import ( | ||
"flag" | ||
"io" | ||
"os" | ||
|
||
"github.com/vincent-petithory/dataurl" | ||
|
||
"github.com/v2fly/v2ray-core/v5/main/commands/base" | ||
) | ||
|
||
var cmdEncodeDataURLContentType *string | ||
|
||
var cmdEncodeDataURL = &base.Command{ | ||
UsageLine: "{{.Exec}} engineering encodeDataURL", | ||
Flag: func() flag.FlagSet { | ||
fs := flag.NewFlagSet("", flag.ExitOnError) | ||
cmdEncodeDataURLContentType = fs.String("type", "application/vnd.v2ray.subscription-singular", "") | ||
return *fs | ||
}(), | ||
Run: func(cmd *base.Command, args []string) { | ||
cmd.Flag.Parse(args) | ||
|
||
content, err := io.ReadAll(os.Stdin) | ||
if err != nil { | ||
base.Fatalf("%s", err) | ||
} | ||
dataURL := dataurl.New(content, *cmdEncodeDataURLContentType) | ||
dataURL.WriteTo(os.Stdout) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters