Skip to content

Commit

Permalink
feat: disable author name to be a uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeuoly committed Dec 2, 2024
1 parent 49f0f46 commit 40ceab5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
12 changes: 11 additions & 1 deletion internal/service/plugin_decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions internal/types/entities/plugin_entities/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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(), ":")
Expand Down

0 comments on commit 40ceab5

Please sign in to comment.