From f9c67b6d50666c917457c7ecd340d45ad742e483 Mon Sep 17 00:00:00 2001 From: StarPro Date: Sun, 13 Oct 2024 11:55:28 +0800 Subject: [PATCH] upgrade to new gojs --- README.md | 1 + go.mod | 16 +++++----------- huoshan.go | 5 +++-- huoshan.ts | 14 ++++++++++++-- image.go | 8 +++++--- test.js | 7 +++---- textin_test.go | 3 +-- 7 files changed, 30 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index f6883f1..a3ca18b 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # huoshan +To know about js functions, go to [huoshan.ts](https://apigo.cc/ai/huoshan/huoshan.ts) diff --git a/go.mod b/go.mod index a8fd177..49fb21e 100644 --- a/go.mod +++ b/go.mod @@ -3,33 +3,27 @@ module apigo.cc/ai/huoshan go 1.18 require ( - apigo.cc/apigo/gojs v0.1.1 + apigo.cc/gojs v0.0.1 github.com/ssgo/config v1.7.7 github.com/ssgo/log v1.7.7 - github.com/ssgo/u v1.7.7 + github.com/ssgo/u v1.7.9 github.com/volcengine/volc-sdk-golang v1.0.178 ) require ( - golang.org/x/net v0.29.0 // indirect - golang.org/x/text v0.18.0 // indirect + golang.org/x/net v0.30.0 // indirect + golang.org/x/text v0.19.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) require ( - filippo.io/edwards25519 v1.1.0 // indirect github.com/cenkalti/backoff/v4 v4.1.2 // 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-20230207041349-798e818bf904 // indirect github.com/google/uuid v1.6.0 // 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/httpclient v1.7.7 // indirect github.com/ssgo/standard v1.7.7 // indirect github.com/ssgo/tool v0.4.27 // indirect - golang.org/x/sys v0.25.0 // indirect + golang.org/x/sys v0.26.0 // indirect ) diff --git a/huoshan.go b/huoshan.go index d180d5c..b7ae815 100644 --- a/huoshan.go +++ b/huoshan.go @@ -1,7 +1,7 @@ package huoshan import ( - "apigo.cc/apigo/gojs" + "apigo.cc/gojs" _ "embed" "github.com/ssgo/config" "github.com/ssgo/log" @@ -30,13 +30,14 @@ func SetSSKey(key, iv []byte) { func init() { obj := gojs.Map{ + "name": "huoshan", "image": RequireImage(), } config.LoadConfig("huoshan", &conf) conf.AKey = confAes.DecryptUrlBase64ToString(conf.AKey) conf.SKey = confAes.DecryptUrlBase64ToString(conf.SKey) log.DefaultLogger.Info("Conf", "", conf) - gojs.Register("huoshan", gojs.Module{ + gojs.Register("apigo.cc/ai/huoshan", gojs.Module{ Object: obj, TsCode: huoshanTS, Example: "", diff --git a/huoshan.ts b/huoshan.ts index 9a52c95..33073e8 100644 --- a/huoshan.ts +++ b/huoshan.ts @@ -2,9 +2,19 @@ export default { image: { text2image, image2image, - readImage + readImage, + base64 } } + +//about image function text2image(prompt:string, option?:Object):string {return ""} -function image2image(image:string[], prompt:string, option?:Object):string {return ""} +// image2image +// image able with base64, bin(byte[], what you get from "readImage"), url(url must be written in an array like ["your url"]) +function image2image(image, prompt:string, option?:Object):string {return ""} function readImage(path:string):string {return ""} +// base64 written-in base64 function,you can use what you want +// data give what you want to give +function base64(data):string {return ""} + + diff --git a/image.go b/image.go index 29adfdc..41dae7f 100644 --- a/image.go +++ b/image.go @@ -1,8 +1,8 @@ package huoshan import ( - "apigo.cc/apigo/gojs" - "apigo.cc/apigo/gojs/dop251/goja" + "apigo.cc/gojs" + "apigo.cc/gojs/goja" "errors" "github.com/ssgo/log" "github.com/ssgo/u" @@ -62,6 +62,9 @@ func RequireImage() gojs.Map { panic(vm.NewGoError(err)) } }, + "base64": func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value { + return vm.ToValue(u.Base64(u.Bytes(gojs.MakeArgs(&argsIn, vm).Check(1).Any(0)))) + }, } } @@ -90,7 +93,6 @@ func T2IXL(prompt string, option map[string]interface{}, vm *goja.Runtime) []str } // I2IXLbyUrl used t2i_xl_sft -// // option 会覆盖已有参数,可传空,return_url不可更改 func I2IXLbyUrl(imageUrls []string, prompt string, option map[string]interface{}, vm *goja.Runtime) []string { vis := visual.NewInstance() diff --git a/test.js b/test.js index cf90038..6dac327 100644 --- a/test.js +++ b/test.js @@ -1,8 +1,7 @@ -import {image} from "huoshan" -import u from "util" +import {image} from 'apigo.cc/ai/huoshan' function main() { - let a = image.image2image(u.base64(image.readImage("img_2.jpeg")), "在吃冰淇淋", { + let a = image.image2image(image.base64(image.readImage("img_2.jpeg")), "在吃冰淇淋", { style_reference_args: { id_weight: 1.0 } @@ -12,7 +11,7 @@ function main() { id_weight: 1.0 } }) - let c = image.image2image([""], "在吃冰淇淋", { + let c = image.image2image(["一个url"], "在吃冰淇淋", { style_reference_args: { id_weight: 1.0 } diff --git a/textin_test.go b/textin_test.go index 031f644..e9f8e38 100644 --- a/textin_test.go +++ b/textin_test.go @@ -1,8 +1,7 @@ package huoshan import ( - "apigo.cc/apigo/gojs" - _ "apigo.cc/apigo/gojs/modules" + "apigo.cc/gojs" "fmt" "github.com/ssgo/u" "testing"