feat: publish v1.0.0-rc.36-custom.1
Publish Docker image (Multi-arch) / Build & push (amd64) (push) Failing after 9m20s
Release (Linux, macOS, Windows) / Linux Release (push) Failing after 55m7s
Publish Docker image (Multi-arch) / Build & push (arm64) (push) Canceled after 0s
Release (Linux, macOS, Windows) / macOS Release (push) Canceled after 0s
Release (Linux, macOS, Windows) / Windows Release (push) Canceled after 0s
Publish Docker image (Multi-arch) / Create multi-arch manifests (push) Canceled after 0s
Publish Docker image (Multi-arch) / Build & push (amd64) (push) Failing after 9m20s
Release (Linux, macOS, Windows) / Linux Release (push) Failing after 55m7s
Publish Docker image (Multi-arch) / Build & push (arm64) (push) Canceled after 0s
Release (Linux, macOS, Windows) / macOS Release (push) Canceled after 0s
Release (Linux, macOS, Windows) / Windows Release (push) Canceled after 0s
Publish Docker image (Multi-arch) / Create multi-arch manifests (push) Canceled after 0s
This commit is contained in:
commit
bb7968b612
2381 files changed
+551494
No files matched your search
@@ -0,0 +1,70 @@
|
||||
package plugins
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
|
||||
"github.com/QuantumNous/new-api/pkg/jsplugin"
|
||||
)
|
||||
|
||||
//go:embed tasks
|
||||
var taskPlugins embed.FS
|
||||
|
||||
func init() {
|
||||
entries, err := fs.ReadDir(taskPlugins, "tasks")
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("read embedded task plugins: %v", err))
|
||||
}
|
||||
for _, entry := range entries {
|
||||
if !entry.IsDir() {
|
||||
continue
|
||||
}
|
||||
key := entry.Name()
|
||||
source, sourceErr := Source(key)
|
||||
if sourceErr != nil {
|
||||
panic(fmt.Sprintf("read embedded task plugin %s: %v", key, sourceErr))
|
||||
}
|
||||
if _, registerErr := jsplugin.DefaultRegistry.RegisterFactory(source, jsplugin.Options{Key: key}); registerErr != nil {
|
||||
panic(fmt.Sprintf("register embedded task plugin %s: %v", key, registerErr))
|
||||
}
|
||||
if mediaType, data, ok := Icon(key); ok {
|
||||
if iconErr := jsplugin.ValidateIconImage(mediaType, data); iconErr != nil {
|
||||
panic(fmt.Sprintf("embedded task plugin %s icon: %v", key, iconErr))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Source returns the embedded factory source for a task plugin key.
|
||||
func Source(key string) (string, error) {
|
||||
source, err := taskPlugins.ReadFile("tasks/" + key + "/plugin.js")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(source), nil
|
||||
}
|
||||
|
||||
// Icon returns the embedded sidecar logo for a factory plugin, if the plugin
|
||||
// directory ships an icon.svg or icon.png next to plugin.js.
|
||||
func Icon(key string) (mediaType string, data []byte, ok bool) {
|
||||
if data, err := taskPlugins.ReadFile("tasks/" + key + "/icon.svg"); err == nil {
|
||||
return "image/svg+xml", data, true
|
||||
}
|
||||
if data, err := taskPlugins.ReadFile("tasks/" + key + "/icon.png"); err == nil {
|
||||
return "image/png", data, true
|
||||
}
|
||||
return "", nil, false
|
||||
}
|
||||
|
||||
// IconDataURI returns the embedded factory logo in the same data URI form the
|
||||
// task_plugins.icon column stores, so factory and override logos share one
|
||||
// read path.
|
||||
func IconDataURI(key string) string {
|
||||
mediaType, data, ok := Icon(key)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
return "data:" + mediaType + ";base64," + base64.StdEncoding.EncodeToString(data)
|
||||
}
|
||||
Reference in new issue
Block a user