瀏覽代碼

feat: disable author name to be a uuid

Yeuoly 7 月之前
父節點
當前提交
40ceab504e
共有 2 個文件被更改,包括 18 次插入1 次删除
  1. 11 1
      internal/service/plugin_decoder.go
  2. 7 0
      internal/types/entities/plugin_entities/identity.go

+ 11 - 1
internal/service/plugin_decoder.go

@@ -39,6 +39,11 @@ func UploadPluginPkg(
 		return exception.BadRequestError(err).ToResponse()
 	}
 
+	// avoid author to be a uuid
+	if pluginUniqueIdentifier.RemoteLike() {
+		return exception.BadRequestError(errors.New("author cannot be a uuid")).ToResponse()
+	}
+
 	manager := plugin_manager.Manager()
 	declaration, err := manager.SavePackage(pluginUniqueIdentifier, pluginFile)
 	if err != nil {
@@ -160,8 +165,13 @@ func FetchPluginManifest(
 	tenant_id string,
 	pluginUniqueIdentifier plugin_entities.PluginUniqueIdentifier,
 ) *entities.Response {
+	runtimeType := plugin_entities.PLUGIN_RUNTIME_TYPE_LOCAL
+	if pluginUniqueIdentifier.RemoteLike() {
+		runtimeType = plugin_entities.PLUGIN_RUNTIME_TYPE_REMOTE
+	}
+
 	pluginManifestCache, err := helper.CombinedGetPluginDeclaration(
-		pluginUniqueIdentifier, tenant_id, plugin_entities.PLUGIN_RUNTIME_TYPE_LOCAL,
+		pluginUniqueIdentifier, tenant_id, runtimeType,
 	)
 
 	if err != nil {

+ 7 - 0
internal/types/entities/plugin_entities/identity.go

@@ -6,6 +6,7 @@ import (
 	"strings"
 
 	"github.com/go-playground/validator/v10"
+	"github.com/google/uuid"
 	"github.com/langgenius/dify-plugin-daemon/internal/types/entities/manifest_entities"
 	"github.com/langgenius/dify-plugin-daemon/internal/types/validators"
 )
@@ -51,6 +52,12 @@ func (p PluginUniqueIdentifier) Version() manifest_entities.Version {
 	return ""
 }
 
+func (p PluginUniqueIdentifier) RemoteLike() bool {
+	// check if the author is a uuid
+	_, err := uuid.Parse(p.Author())
+	return err == nil
+}
+
 func (p PluginUniqueIdentifier) Author() string {
 	// extract author part from the string
 	split := strings.Split(p.String(), ":")