Skip to content

Commit

Permalink
add geosite.dat support
Browse files Browse the repository at this point in the history
  • Loading branch information
mmmray committed Sep 8, 2024
1 parent 7e7008e commit 9e26f89
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.wasm
*.dat
wasm_exec.js
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
build:
geoip.dat:
wget https://github.com/v2fly/geoip/releases/latest/download/geoip.dat

geosite.dat:
wget https://github.com/v2fly/domain-list-community/releases/latest/download/dlc.dat -O geosite.dat

build: geoip.dat geosite.dat
cp "$$(go env GOROOT)/misc/wasm/wasm_exec.js" .
GOARCH=wasm GOOS=js go build -o main.wasm
GOARCH=wasm GOOS=js go build -o main.wasm main.go

serve:
python3 -mhttp.server
23 changes: 23 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,38 @@ package main

import (
"fmt"
"strings"
"syscall/js"
"encoding/json"
"bytes"
"io"
_ "embed"
"io/ioutil"

"github.com/xtls/xray-core/infra/conf"
"github.com/xtls/xray-core/common/platform/filesystem"
"github.com/xtls/xray-core/common/errors"
json_reader "github.com/xtls/xray-core/infra/conf/json"
)

//go:embed geoip.dat
var geoipRaw []byte
//go:embed geosite.dat
var geositeRaw []byte

func main() {
filesystem.NewFileReader = func(path string) (io.ReadCloser, error) {
if strings.HasSuffix(path, "geoip.dat") {
return ioutil.NopCloser(bytes.NewReader(geoipRaw)), nil
}

if strings.HasSuffix(path, "geosite.dat") {
return ioutil.NopCloser(bytes.NewReader(geositeRaw)), nil
}

return nil, errors.New(path + " cannot be opened in the browser")
}

js.Global().Set("XrayParseConfig", js.FuncOf(func(this js.Value, args []js.Value) any {
if len(args) < 1 {
fmt.Println("invalid number of args")
Expand Down

0 comments on commit 9e26f89

Please sign in to comment.