Yeuoly 10 months ago
parent
commit
de7c82ec62
3 changed files with 41 additions and 1 deletions
  1. 1 0
      cmd/commandline/init/permission.go
  2. 38 1
      cmd/commandline/plugin.go
  3. 2 0
      internal/utils/log/log.go

+ 1 - 0
cmd/commandline/init/permission.go

@@ -178,6 +178,7 @@ func (p *permission) edit() {
 				Enabled: true,
 				Size:    1048576,
 			}
+			p.storageSizeEditor.SetValue(fmt.Sprintf("%d", p.permission.Storage.Size))
 		}
 	}
 

+ 38 - 1
cmd/commandline/plugin.go

@@ -1,7 +1,13 @@
 package main
 
 import (
+	"fmt"
+	"os"
+
 	init_pkg "github.com/langgenius/dify-plugin-daemon/cmd/commandline/init"
+	"github.com/langgenius/dify-plugin-daemon/internal/core/plugin_packager/decoder"
+	"github.com/langgenius/dify-plugin-daemon/internal/core/plugin_packager/packager"
+	"github.com/langgenius/dify-plugin-daemon/internal/utils/log"
 	"github.com/spf13/cobra"
 )
 
@@ -16,9 +22,40 @@ var (
 	}
 
 	pluginPackageCommand = &cobra.Command{
-		Use:   "package",
+		Use:   "package plugin_path [-o output_path]",
 		Short: "Package",
 		Long:  "Package plugins",
+		Run: func(cmd *cobra.Command, args []string) {
+			if len(args) < 1 {
+				fmt.Println("Error: plugin_path is required")
+				return
+			}
+			output_path := "./plugin.difypkg"
+			if cmd.Flag("output_path") != nil {
+				output_path = cmd.Flag("output_path").Value.String()
+			}
+			decoder, err := decoder.NewFSPluginDecoder(args[0])
+			if err != nil {
+				log.Error("failed to create plugin decoder , plugin path: %s, error: %v", args[0], err)
+				return
+			}
+
+			packager := packager.NewPackager(decoder)
+			zip_file, err := packager.Pack()
+
+			if err != nil {
+				log.Error("failed to package plugin %v", err)
+				return
+			}
+
+			err = os.WriteFile(output_path, zip_file, 0644)
+			if err != nil {
+				log.Error("failed to write package file %v", err)
+				return
+			}
+
+			log.Info("plugin packaged successfully, output path: %s", output_path)
+		},
 	}
 
 	pluginPermissionCommand = &cobra.Command{

+ 2 - 0
internal/utils/log/log.go

@@ -90,6 +90,8 @@ func (l *Log) writeLog(level string, format string, stdout bool, v ...interface{
 			logger.Output(4, LOG_LEVEL_WARN_COLOR+format+LOG_LEVEL_COLOR_END)
 		} else if level == "ERROR" {
 			logger.Output(4, LOG_LEVEL_ERROR_COLOR+format+LOG_LEVEL_COLOR_END)
+		} else if level == "PANIC" {
+			logger.Output(4, LOG_LEVEL_ERROR_COLOR+format+LOG_LEVEL_COLOR_END)
 		}
 	}