mirror of
https://github.com/tickstep/aliyunpan.git
synced 2025-02-02 21:27:15 +08:00
add deleteFile func for javascript plugin
This commit is contained in:
parent
90cec4b827
commit
52fbe51499
@ -38,16 +38,22 @@ func (js *JsPlugin) Start() error {
|
||||
// 内置log
|
||||
console := js.vm.NewObject()
|
||||
console.Set("log", jsLog)
|
||||
js.vm.Set("console", console)
|
||||
js.vm.Set("console", console) // console.log()
|
||||
|
||||
// 内置系统函数PluginUtil
|
||||
pluginObj := js.vm.NewObject()
|
||||
js.vm.Set("PluginUtil", pluginObj)
|
||||
|
||||
// PluginUtil.Http
|
||||
httpObj := js.vm.NewObject()
|
||||
pluginObj.Set("Http", httpObj)
|
||||
httpObj.Set("get", HttpGet)
|
||||
httpObj.Set("post", HttpPost)
|
||||
httpObj.Set("get", HttpGet) // PluginUtil.Http.get()
|
||||
httpObj.Set("post", HttpPost) // PluginUtil.Http.post()
|
||||
|
||||
// PluginUtil.LocalFS
|
||||
localFS := js.vm.NewObject()
|
||||
pluginObj.Set("LocalFS", localFS)
|
||||
localFS.Set("deleteFile", DeleteLocalFile) // PluginUtil.LocalFS.deleteFile()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package plugins
|
||||
import (
|
||||
"github.com/tickstep/library-go/logger"
|
||||
"github.com/tickstep/library-go/requester"
|
||||
"os"
|
||||
)
|
||||
|
||||
// HttpGet Http的get请求
|
||||
@ -26,3 +27,16 @@ func HttpPost(header map[string]string, url string, data interface{}) string {
|
||||
}
|
||||
return string(body)
|
||||
}
|
||||
|
||||
// DeleteLocalFile 删除本地文件,不支持文件夹
|
||||
func DeleteLocalFile(localFilePath string) bool {
|
||||
err := os.Remove(localFilePath)
|
||||
if err != nil {
|
||||
// 删除失败
|
||||
return false
|
||||
} else {
|
||||
// 删除成功
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
10
internal/plugins/plugin_util_test.go
Normal file
10
internal/plugins/plugin_util_test.go
Normal file
@ -0,0 +1,10 @@
|
||||
package plugins
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDeleteLocalFile(t *testing.T) {
|
||||
fmt.Println(DeleteLocalFile("/Volumes/Downloads/dev/upload/2"))
|
||||
}
|
Loading…
Reference in New Issue
Block a user