diff --git a/internal/command/upload.go b/internal/command/upload.go index c411cce..23908e6 100644 --- a/internal/command/upload.go +++ b/internal/command/upload.go @@ -298,7 +298,7 @@ func RunUpload(localPaths []string, savePath string, opt *UploadOptions) { folderCreateMutex = &sync.Mutex{} - pluginManger = plugins.NewPluginManager(config.GetConfigDir()) + pluginManger = plugins.NewPluginManager(config.GetPluginDir()) ) executor.SetParallel(opt.AllParallel) statistic.StartTimer() // 开始计时 diff --git a/internal/config/pan_config.go b/internal/config/pan_config.go index 1ec0ddb..9676323 100644 --- a/internal/config/pan_config.go +++ b/internal/config/pan_config.go @@ -308,6 +308,10 @@ func GetConfigDir() string { return configDir } +func GetPluginDir() string { + return strings.TrimSuffix(GetConfigDir(), "/") + "/plugin" +} + func (c *PanConfig) ActiveUser() *PanUser { if c.activeUser == nil { if c.UserList == nil { diff --git a/internal/plugins/js_plugin.go b/internal/plugins/js_plugin.go index 01624da..7b3d483 100644 --- a/internal/plugins/js_plugin.go +++ b/internal/plugins/js_plugin.go @@ -53,7 +53,7 @@ func (js *JsPlugin) Start() error { func (js *JsPlugin) LoadScript(script string) error { _, err := js.vm.RunString(script) if err != nil { - logger.Verboseln("JS代码有问题!") + logger.Verboseln("JS代码有问题!{}", err) return err } return nil diff --git a/internal/plugins/plugin_manager.go b/internal/plugins/plugin_manager.go index 3172dd1..c216dcf 100644 --- a/internal/plugins/plugin_manager.go +++ b/internal/plugins/plugin_manager.go @@ -58,6 +58,9 @@ func (p *PluginManager) GetPlugin() (Plugin, error) { if files, e := ioutil.ReadDir(jsPluginPath); e == nil { for _, f := range files { if !f.IsDir() { + if strings.HasPrefix(strings.ToLower(f.Name()), ".") || strings.HasPrefix(strings.ToLower(f.Name()), "~") { + continue + } if strings.HasSuffix(strings.ToLower(f.Name()), ".js") { // this is a js file bytes, re := ioutil.ReadFile(path.Clean(jsPluginPath + string(os.PathSeparator) + f.Name())) diff --git a/internal/plugins/plugin_manager_test.go b/internal/plugins/plugin_manager_test.go index 6f88dc1..db57447 100644 --- a/internal/plugins/plugin_manager_test.go +++ b/internal/plugins/plugin_manager_test.go @@ -2,6 +2,7 @@ package plugins import ( "fmt" + jsoniter "github.com/json-iterator/go" "testing" ) @@ -28,6 +29,10 @@ func TestPlugin(t *testing.T) { DriveId: "19519221", DriveFilePath: "aliyunpan/Downloads/11001d48564f43b3bc5662874f04bb11/token.bat", } + b, _ := jsoniter.Marshal(ctx) + fmt.Println(string(b)) + b, _ = jsoniter.Marshal(params) + fmt.Println(string(b)) r, e := plugin.UploadFilePrepareCallback(ctx, params) if e != nil { fmt.Println(e)