From 40ceab504e7fa86204873cc9ec5dc86231f64eb1 Mon Sep 17 00:00:00 2001 From: Yeuoly Date: Mon, 2 Dec 2024 21:35:40 +0800 Subject: [PATCH] feat: disable author name to be a uuid --- internal/service/plugin_decoder.go | 12 +++++++++++- internal/types/entities/plugin_entities/identity.go | 7 +++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/internal/service/plugin_decoder.go b/internal/service/plugin_decoder.go index f3991da..acde38b 100644 --- a/internal/service/plugin_decoder.go +++ b/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 { diff --git a/internal/types/entities/plugin_entities/identity.go b/internal/types/entities/plugin_entities/identity.go index bd2c9f4..ea5f9f6 100644 --- a/internal/types/entities/plugin_entities/identity.go +++ b/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(), ":")