feat: direct call download api by cgo dart

This commit is contained in:
liwei committed 2024-12-02 00:39:28 +08:00
1 parent 467ada5500
commit 91dfd78b77
71 files changed
+6936 -1883

No files matched your search

+6 -2
View File
@@ -51,7 +51,7 @@ func Invoke(index int, request *api.Request) string {
if !ok {
return BuildResult(errors.New("instance not found"))
}
return BuildResult(api.Invoke(instance, request))
return jsonEncode(api.Invoke(instance, request))
}
func BuildResult(data any) string {
@@ -59,6 +59,10 @@ func BuildResult(data any) string {
buf, _ := json.Marshal(model.NewErrorResult[any](err.Error()))
return string(buf)
}
buf, _ := json.Marshal(model.NewOkResult(data))
return jsonEncode(model.NewOkResult(data))
}
func jsonEncode(data any) string {
buf, _ := json.Marshal(data)
return string(buf)
}
-6
View File
@@ -1,15 +1,11 @@
package main
/*
#include <stdlib.h>
*/
import "C"
import (
"encoding/json"
"github.com/GopeedLab/gopeed/bind"
"github.com/GopeedLab/gopeed/pkg/api"
"github.com/GopeedLab/gopeed/pkg/api/model"
"unsafe"
)
func main() {}
@@ -20,7 +16,6 @@ func Create(cfg *C.char) *C.char {
if err := json.Unmarshal([]byte(C.GoString(cfg)), &config); err != nil {
return C.CString(bind.BuildResult(err))
}
defer C.free(unsafe.Pointer(cfg))
return C.CString(bind.Create(&config))
}
@@ -31,7 +26,6 @@ func Invoke(index int, req *C.char) *C.char {
if err := json.Unmarshal([]byte(C.GoString(req)), &request); err != nil {
return C.CString(bind.BuildResult(err))
}
defer C.free(unsafe.Pointer(req))
return C.CString(bind.Invoke(index, &request))
}
+2 -2
View File
@@ -8,8 +8,8 @@ import (
"github.com/GopeedLab/gopeed/pkg/api/model"
)
func Create(config *model.StartConfig) string {
return bind.Create(config)
func Create(cfg *model.StartConfig) string {
return bind.Create(cfg)
}
func Invoke(index int, request *api.Request) string {