upgrade to new gojs
This commit is contained in:
		
							parent
							
								
									cffe6bd450
								
							
						
					
					
						commit
						6d990dfb14
					
				
							
								
								
									
										16
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								go.mod
									
									
									
									
									
								
							@ -3,27 +3,23 @@ module apigo.cc/ai/textin
 | 
				
			|||||||
go 1.18
 | 
					go 1.18
 | 
				
			||||||
 | 
					
 | 
				
			||||||
require (
 | 
					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/config v1.7.7
 | 
				
			||||||
	github.com/ssgo/httpclient 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 (
 | 
					require (
 | 
				
			||||||
	filippo.io/edwards25519 v1.1.0 // indirect
 | 
					 | 
				
			||||||
	github.com/dlclark/regexp2 v1.11.4 // indirect
 | 
						github.com/dlclark/regexp2 v1.11.4 // indirect
 | 
				
			||||||
	github.com/fsnotify/fsnotify v1.7.0 // indirect
 | 
						github.com/fsnotify/fsnotify v1.7.0 // indirect
 | 
				
			||||||
	github.com/go-sourcemap/sourcemap v2.1.4+incompatible // 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/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/log v1.7.7 // indirect
 | 
				
			||||||
	github.com/ssgo/standard v1.7.7 // indirect
 | 
						github.com/ssgo/standard v1.7.7 // indirect
 | 
				
			||||||
	github.com/ssgo/tool v0.4.27 // indirect
 | 
						github.com/ssgo/tool v0.4.27 // indirect
 | 
				
			||||||
	golang.org/x/net v0.29.0 // indirect
 | 
						golang.org/x/net v0.30.0 // indirect
 | 
				
			||||||
	golang.org/x/sys v0.25.0 // indirect
 | 
						golang.org/x/sys v0.26.0 // indirect
 | 
				
			||||||
	golang.org/x/text v0.18.0 // indirect
 | 
						golang.org/x/text v0.19.0 // indirect
 | 
				
			||||||
	gopkg.in/yaml.v3 v3.0.1 // indirect
 | 
						gopkg.in/yaml.v3 v3.0.1 // indirect
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										6
									
								
								test.js
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								test.js
									
									
									
									
									
								
							@ -1,6 +1,6 @@
 | 
				
			|||||||
import textin from "textin"
 | 
					import ti from "apigo.cc/ai/textin"
 | 
				
			||||||
import file from "file"
 | 
					import file from "apigo.cc/gojs/file"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function main(){
 | 
					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")}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										16
									
								
								textin.go
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								textin.go
									
									
									
									
									
								
							@ -1,8 +1,8 @@
 | 
				
			|||||||
package textin
 | 
					package textin
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"apigo.cc/apigo/gojs"
 | 
						"apigo.cc/gojs"
 | 
				
			||||||
	"apigo.cc/apigo/gojs/dop251/goja"
 | 
						"apigo.cc/gojs/goja"
 | 
				
			||||||
	_ "embed"
 | 
						_ "embed"
 | 
				
			||||||
	"errors"
 | 
						"errors"
 | 
				
			||||||
	"github.com/ssgo/config"
 | 
						"github.com/ssgo/config"
 | 
				
			||||||
@ -11,14 +11,14 @@ import (
 | 
				
			|||||||
	"time"
 | 
						"time"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//go:embed textin.ts
 | 
				
			||||||
 | 
					var textinTS string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Conf struct {
 | 
					type Conf struct {
 | 
				
			||||||
	AKey string
 | 
						AKey string
 | 
				
			||||||
	SKey string
 | 
						SKey string
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//go:embed textin.ts
 | 
					 | 
				
			||||||
var textinTS string
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
var conf = Conf{}
 | 
					var conf = Conf{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var confAes = u.NewAes([]byte("?GQ$0K0GgLdO=f+~L68PLm$uhKr4'=tV"), []byte("VFs7@sK61cj^f?HZ"))
 | 
					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() {
 | 
					func init() {
 | 
				
			||||||
	obj := map[string]interface{}{
 | 
						obj := map[string]interface{}{
 | 
				
			||||||
 | 
							"name": "textin",
 | 
				
			||||||
		"OCR": func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value {
 | 
							"OCR": func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value {
 | 
				
			||||||
			args := gojs.MakeArgs(&argsIn, vm).Check(1)
 | 
								args := gojs.MakeArgs(&argsIn, vm).Check(1)
 | 
				
			||||||
			return vm.ToValue(OCR(args.Bytes(0), vm))
 | 
								return vm.ToValue(OCR(args.Bytes(0), vm))
 | 
				
			||||||
@ -50,7 +51,7 @@ func init() {
 | 
				
			|||||||
	conf.AKey = confAes.DecryptUrlBase64ToString(conf.AKey)
 | 
						conf.AKey = confAes.DecryptUrlBase64ToString(conf.AKey)
 | 
				
			||||||
	conf.SKey = confAes.DecryptUrlBase64ToString(conf.SKey)
 | 
						conf.SKey = confAes.DecryptUrlBase64ToString(conf.SKey)
 | 
				
			||||||
	//log.DefaultLogger.Info("conf", "", conf)
 | 
						//log.DefaultLogger.Info("conf", "", conf)
 | 
				
			||||||
	gojs.Register("textin", gojs.Module{
 | 
						gojs.Register("apigo.cc/ai/textin", gojs.Module{
 | 
				
			||||||
		Object:  obj,
 | 
							Object:  obj,
 | 
				
			||||||
		TsCode:  textinTS,
 | 
							TsCode:  textinTS,
 | 
				
			||||||
		Example: "",
 | 
							Example: "",
 | 
				
			||||||
@ -69,6 +70,9 @@ func OCR(file []byte, vm *goja.Runtime) string {
 | 
				
			|||||||
		} `json:"result"`
 | 
							} `json:"result"`
 | 
				
			||||||
	}{}
 | 
						}{}
 | 
				
			||||||
	//log.DefaultLogger.Info("Result", "", resMap)
 | 
						//log.DefaultLogger.Info("Result", "", resMap)
 | 
				
			||||||
 | 
						if resMap["code"] != 200 {
 | 
				
			||||||
 | 
							panic(vm.NewGoError(errors.New(u.BRed(resMap["message"]))))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	str := ""
 | 
						str := ""
 | 
				
			||||||
	u.Convert(resMap, &res)
 | 
						u.Convert(resMap, &res)
 | 
				
			||||||
	if len(res.Result.Pages) < 1 {
 | 
						if len(res.Result.Pages) < 1 {
 | 
				
			||||||
 | 
				
			|||||||
@ -1,8 +1,8 @@
 | 
				
			|||||||
package textin
 | 
					package textin
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"apigo.cc/apigo/gojs"
 | 
						"apigo.cc/gojs"
 | 
				
			||||||
	_ "apigo.cc/apigo/gojs/modules"
 | 
						_ "apigo.cc/gojs/file"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"github.com/ssgo/u"
 | 
						"github.com/ssgo/u"
 | 
				
			||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user