From 6d990dfb1405a56c323e43e4d22f57145189690b Mon Sep 17 00:00:00 2001 From: StarPro Date: Sun, 13 Oct 2024 12:08:57 +0800 Subject: [PATCH] upgrade to new gojs --- go.mod | 16 ++++++---------- test.js | 6 +++--- textin.go | 16 ++++++++++------ textin_test.go | 4 ++-- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/go.mod b/go.mod index 0243e1a..6d252cd 100644 --- a/go.mod +++ b/go.mod @@ -3,27 +3,23 @@ module apigo.cc/ai/textin go 1.18 require ( - apigo.cc/apigo/gojs v0.1.1 + apigo.cc/gojs v0.0.1 + apigo.cc/gojs/file v0.0.1 github.com/ssgo/config v1.7.7 github.com/ssgo/httpclient v1.7.7 - github.com/ssgo/u v1.7.7 + github.com/ssgo/u v1.7.9 ) require ( - filippo.io/edwards25519 v1.1.0 // indirect github.com/dlclark/regexp2 v1.11.4 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/go-sourcemap/sourcemap v2.1.4+incompatible // indirect - github.com/go-sql-driver/mysql v1.8.1 // indirect github.com/google/pprof v0.0.0-20240409012703-83162a5b38cd // indirect - github.com/mitchellh/mapstructure v1.5.0 // indirect - github.com/ssgo/dao v0.1.5 // indirect - github.com/ssgo/db v1.7.9 // indirect github.com/ssgo/log v1.7.7 // indirect github.com/ssgo/standard v1.7.7 // indirect github.com/ssgo/tool v0.4.27 // indirect - golang.org/x/net v0.29.0 // indirect - golang.org/x/sys v0.25.0 // indirect - golang.org/x/text v0.18.0 // indirect + golang.org/x/net v0.30.0 // indirect + golang.org/x/sys v0.26.0 // indirect + golang.org/x/text v0.19.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/test.js b/test.js index 36599ab..002bbcd 100644 --- a/test.js +++ b/test.js @@ -1,6 +1,6 @@ -import textin from "textin" -import file from "file" +import ti from "apigo.cc/ai/textin" +import file from "apigo.cc/gojs/file" function main(){ - return {a : textin.OCR(file.read("img.png")), b : textin.OCRFromFile("img.png")} + return {a : ti.OCR(file.readBytes("img.png")), b : ti.OCRFromFile("img.png")} } diff --git a/textin.go b/textin.go index fabcc4d..d8dbb10 100644 --- a/textin.go +++ b/textin.go @@ -1,8 +1,8 @@ package textin import ( - "apigo.cc/apigo/gojs" - "apigo.cc/apigo/gojs/dop251/goja" + "apigo.cc/gojs" + "apigo.cc/gojs/goja" _ "embed" "errors" "github.com/ssgo/config" @@ -11,14 +11,14 @@ import ( "time" ) +//go:embed textin.ts +var textinTS string + type Conf struct { AKey string SKey string } -//go:embed textin.ts -var textinTS string - var conf = Conf{} var confAes = u.NewAes([]byte("?GQ$0K0GgLdO=f+~L68PLm$uhKr4'=tV"), []byte("VFs7@sK61cj^f?HZ")) @@ -33,6 +33,7 @@ func SetSSKey(key, iv []byte) { func init() { obj := map[string]interface{}{ + "name": "textin", "OCR": func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value { args := gojs.MakeArgs(&argsIn, vm).Check(1) return vm.ToValue(OCR(args.Bytes(0), vm)) @@ -50,7 +51,7 @@ func init() { conf.AKey = confAes.DecryptUrlBase64ToString(conf.AKey) conf.SKey = confAes.DecryptUrlBase64ToString(conf.SKey) //log.DefaultLogger.Info("conf", "", conf) - gojs.Register("textin", gojs.Module{ + gojs.Register("apigo.cc/ai/textin", gojs.Module{ Object: obj, TsCode: textinTS, Example: "", @@ -69,6 +70,9 @@ func OCR(file []byte, vm *goja.Runtime) string { } `json:"result"` }{} //log.DefaultLogger.Info("Result", "", resMap) + if resMap["code"] != 200 { + panic(vm.NewGoError(errors.New(u.BRed(resMap["message"])))) + } str := "" u.Convert(resMap, &res) if len(res.Result.Pages) < 1 { diff --git a/textin_test.go b/textin_test.go index 03e41fc..5856b22 100644 --- a/textin_test.go +++ b/textin_test.go @@ -1,8 +1,8 @@ package textin import ( - "apigo.cc/apigo/gojs" - _ "apigo.cc/apigo/gojs/modules" + "apigo.cc/gojs" + _ "apigo.cc/gojs/file" "fmt" "github.com/ssgo/u" "testing"