package.go 951 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package plugin
  2. import (
  3. "os"
  4. "github.com/langgenius/dify-plugin-daemon/internal/utils/log"
  5. "github.com/langgenius/dify-plugin-daemon/pkg/plugin_packager/decoder"
  6. "github.com/langgenius/dify-plugin-daemon/pkg/plugin_packager/packager"
  7. )
  8. var (
  9. MaxPluginPackageSize = int64(52428800) // 50MB
  10. )
  11. func PackagePlugin(inputPath string, outputPath string) {
  12. decoder, err := decoder.NewFSPluginDecoder(inputPath)
  13. if err != nil {
  14. log.Error("failed to create plugin decoder , plugin path: %s, error: %v", inputPath, err)
  15. os.Exit(1)
  16. return
  17. }
  18. packager := packager.NewPackager(decoder)
  19. zipFile, err := packager.Pack(MaxPluginPackageSize)
  20. if err != nil {
  21. log.Error("failed to package plugin %v", err)
  22. os.Exit(1)
  23. return
  24. }
  25. err = os.WriteFile(outputPath, zipFile, 0644)
  26. if err != nil {
  27. log.Error("failed to write package file %v", err)
  28. os.Exit(1)
  29. return
  30. }
  31. log.Info("plugin packaged successfully, output path: %s", outputPath)
  32. }