Remove gfwlist generation (#324)

This commit is contained in:
Loyalsoldier 2020-12-26 16:17:47 +08:00 committed by GitHub
parent 5cd2f4e60c
commit c8ac979dbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 1 additions and 90 deletions

View File

@ -47,17 +47,13 @@ jobs:
xz -z -9 -k dlc.dat
sha256sum dlc.dat.xz > dlc.dat.xz.sha256sum
- name: Generate gfwlist.txt sha256 hash
run: |
sha256sum gfwlist.txt > gfwlist.txt.sha256sum
- name: Git push assets to "release" branch
run: |
git init
git config --local user.name "actions"
git config --local user.email "action@github.com"
git checkout -b release
git add *.txt dlc.dat dlc.dat.sha256sum dlc.dat.zip dlc.dat.zip.sha256sum dlc.dat.xz dlc.dat.xz.sha256sum gfwlist.txt gfwlist.txt.sha256sum
git add *.txt dlc.dat dlc.dat.sha256sum dlc.dat.zip dlc.dat.zip.sha256sum dlc.dat.xz dlc.dat.xz.sha256sum
git commit -m "${{ env.RELEASE_NAME }}"
git remote add origin "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}"
git push -f -u origin release
@ -132,23 +128,3 @@ jobs:
asset_path: ./dlc.dat.xz.sha256sum
asset_name: dlc.dat.xz.sha256sum
asset_content_type: text/plain
- name: Upload gfwlist.txt
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./gfwlist.txt
asset_name: gfwlist.txt
asset_content_type: text/plain
- name: Upload gfwlist.txt sha256sum
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./gfwlist.txt.sha256sum
asset_name: gfwlist.txt.sha256sum
asset_content_type: text/plain

65
main.go
View File

@ -2,7 +2,6 @@ package main
import (
"bufio"
"encoding/base64"
"errors"
"flag"
"fmt"
@ -12,7 +11,6 @@ import (
"path/filepath"
"strconv"
"strings"
"time"
"google.golang.org/protobuf/proto"
"v2ray.com/core/app/router"
@ -109,61 +107,6 @@ func exportPlainTextList(list []string, refName string, pl *ParsedList) {
}
}
func exportGFWList(pl *ParsedList) error {
var entryBytes []byte
timeString := fmt.Sprintf("! Last Modified: %s\n", time.Now())
entryBytes = append(entryBytes, []byte("[AutoProxy 0.2.9]\n")...)
entryBytes = append(entryBytes, []byte(timeString)...)
entryBytes = append(entryBytes, []byte("! Expires: 24h\n")...)
entryBytes = append(entryBytes, []byte("! HomePage: https://github.com/v2fly/domain-list-community\n")...)
entryBytes = append(entryBytes, []byte("! GitHub URL: https://raw.githubusercontent.com/v2fly/domain-list-community/release/gfwlist.txt\n")...)
entryBytes = append(entryBytes, []byte("! jsdelivr URL: https://cdn.jsdelivr.net/gh/v2fly/domain-list-community@release/gfwlist.txt\n")...)
for _, entry := range pl.Entry {
exclude := false
if attrs := entry.Attrs; len(attrs) > 0 {
// exclude rules that have '@cn' attribute
for _, attr := range attrs {
if strings.EqualFold(attr.GetKey(), "cn") {
exclude = true
break
}
}
}
if exclude {
fmt.Printf("Exclude '%s' from gfwlist.txt because it has '@cn' attribute\n", entry.Value)
continue
}
switch entry.Type {
case "domain":
entryBytes = append(entryBytes, []byte("||"+entry.Value+"\n")...)
case "full":
entryBytes = append(entryBytes, []byte("|http://"+entry.Value+"\n")...)
entryBytes = append(entryBytes, []byte("|https://"+entry.Value+"\n")...)
case "keyword":
entryBytes = append(entryBytes, []byte(entry.Value+"\n")...)
case "regexp":
entryBytes = append(entryBytes, []byte("/"+entry.Value+"/\n")...)
default:
return errors.New("unknown domain type: " + entry.Type)
}
}
f, err := os.OpenFile("gfwlist.txt", os.O_RDWR|os.O_CREATE, 0644)
if err != nil {
return err
}
encoder := base64.NewEncoder(base64.StdEncoding, f)
if _, err = encoder.Write(entryBytes); err != nil {
return err
}
fmt.Println("gfwlist.txt has been generated successfully in current directory.")
if err = encoder.Close(); err != nil {
return err
}
return nil
}
func removeComment(line string) string {
idx := strings.Index(line, "#")
if idx == -1 {
@ -431,14 +374,6 @@ func main() {
}
}
}
// Export GfwList
if refName == "GEOLOCATION-!CN" {
if err := exportGFWList(pl); err != nil {
fmt.Println("Failed: ", err)
os.Exit(1)
}
}
}
protoBytes, err := proto.Marshal(protoList)