mirror of
				https://github.com/FloatTech/zbpdata.git
				synced 2025-11-04 04:15:04 +09:00 
			
		
		
		
	add auto-updater
This commit is contained in:
		
							parent
							
								
									2783f59b7e
								
							
						
					
					
						commit
						61349e6e05
					
				
							
								
								
									
										28
									
								
								.github/workflows/release.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								.github/workflows/release.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,28 @@
 | 
			
		||||
name: 更新 md5
 | 
			
		||||
on:
 | 
			
		||||
  push:
 | 
			
		||||
    tags:
 | 
			
		||||
      - 'v*'
 | 
			
		||||
 | 
			
		||||
jobs:
 | 
			
		||||
  update:
 | 
			
		||||
    runs-on: ubuntu-latest
 | 
			
		||||
    steps:
 | 
			
		||||
      - name: Checkout
 | 
			
		||||
        uses: actions/checkout@v2.3.4
 | 
			
		||||
        with:
 | 
			
		||||
          fetch-depth: 0
 | 
			
		||||
 | 
			
		||||
      - name: Set up Go
 | 
			
		||||
        uses: actions/setup-go@v2
 | 
			
		||||
        with:
 | 
			
		||||
          go-version: '1.17'
 | 
			
		||||
 | 
			
		||||
      - name: Run Updater
 | 
			
		||||
        env:
 | 
			
		||||
          REILIA_SPS: ${{ secrets.REILIA_SPS }}
 | 
			
		||||
        run: |
 | 
			
		||||
          ls
 | 
			
		||||
          go mod init updater
 | 
			
		||||
          go mod tidy
 | 
			
		||||
          go run main.go
 | 
			
		||||
							
								
								
									
										52
									
								
								main.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								main.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,52 @@
 | 
			
		||||
package main
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"crypto/md5"
 | 
			
		||||
	"encoding/hex"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"io/fs"
 | 
			
		||||
	"os"
 | 
			
		||||
	"strings"
 | 
			
		||||
	"unicode"
 | 
			
		||||
	"unsafe"
 | 
			
		||||
 | 
			
		||||
	"github.com/fumiama/go-registry"
 | 
			
		||||
	"github.com/wdvxdr1123/ZeroBot/utils/helper"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func main() {
 | 
			
		||||
	var files []string
 | 
			
		||||
	fs.WalkDir(os.DirFS("./"), ".", func(path string, d fs.DirEntry, err error) error {
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
		if !d.IsDir() && strings.Contains(path, "/") && unicode.IsUpper([]rune(path)[0]) {
 | 
			
		||||
			files = append(files, path)
 | 
			
		||||
		}
 | 
			
		||||
		return nil
 | 
			
		||||
	})
 | 
			
		||||
	fmt.Println(files)
 | 
			
		||||
	md5s := make([]string, len(files))
 | 
			
		||||
	for i, fn := range files {
 | 
			
		||||
		data, err := os.ReadFile(fn)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			panic(err)
 | 
			
		||||
		}
 | 
			
		||||
		buf := md5.Sum(data)
 | 
			
		||||
		*(*unsafe.Pointer)(unsafe.Pointer(&md5s[i])) = unsafe.Pointer(&buf)
 | 
			
		||||
		*(*uintptr)(unsafe.Add(unsafe.Pointer(&md5s[i]), unsafe.Sizeof(uintptr(0)))) = uintptr(16)
 | 
			
		||||
	}
 | 
			
		||||
	r := registry.NewRegedit("reilia.eastasia.azurecontainer.io:32664", "fumiama", os.Getenv("REILIA_SPS"))
 | 
			
		||||
	err := r.Connect()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		panic(err)
 | 
			
		||||
	}
 | 
			
		||||
	for i, fn := range files {
 | 
			
		||||
		fmt.Println("set", "data/"+fn, "=", hex.EncodeToString(helper.StringToBytes(md5s[i])))
 | 
			
		||||
		err = r.Set("data/"+fn, md5s[i])
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			panic(err)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	r.Close()
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user