|
|
package upload
|
|
|
|
|
|
import (
|
|
|
"joybuywork/internal/repository/mtype"
|
|
|
"fmt"
|
|
|
"io/fs"
|
|
|
"os"
|
|
|
"path/filepath"
|
|
|
"strings"
|
|
|
"testing"
|
|
|
|
|
|
"github.com/aliyun/aliyun-oss-go-sdk/oss"
|
|
|
)
|
|
|
|
|
|
func TestName(t *testing.T) {
|
|
|
// 创建OSSClient实例。
|
|
|
// yourEndpoint填写Bucket对应的Endpoint,以华东1(杭州)为例,填写为https://oss-cn-hangzhou.aliyuncs.com。其它Region请按实际情况填写。
|
|
|
// 阿里云账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户。
|
|
|
client, err := oss.New("https://oss-cn-shenzhen.aliyuncs.com", "LTAI5tNvMLF181bTb3qCZxk4", "9HXWh6yTXhbBQ7WaMkS1c3o0UNtl7A")
|
|
|
if err != nil {
|
|
|
fmt.Println("Error:", err)
|
|
|
os.Exit(-1)
|
|
|
}
|
|
|
|
|
|
// 填写存储空间名称,例如examplebucket。
|
|
|
bucket, err := client.Bucket("client-project-resource")
|
|
|
if err != nil {
|
|
|
fmt.Println("Error:", err)
|
|
|
os.Exit(-1)
|
|
|
}
|
|
|
|
|
|
name := "ftg/answer_tmb/answer_bg.png"
|
|
|
fmt.Println(name)
|
|
|
|
|
|
// 依次填写Object的完整路径(例如exampledir/exampleobject.txt)和本地文件的完整路径(例如D:\\localpath\\examplefile.txt)。
|
|
|
err = bucket.PutObjectFromFile(name, "./a/answer_bg.png")
|
|
|
if err != nil {
|
|
|
fmt.Println("Error:", err)
|
|
|
os.Exit(-1)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
const offerwall = "offerwall/"
|
|
|
const taskcenter = "taskcenter/"
|
|
|
const ads = "ads/article/"
|
|
|
const static = "static/"
|
|
|
const staticH5 = "static/deepView"
|
|
|
|
|
|
func TestName2(t *testing.T) {
|
|
|
// 创建OSSClient实例。
|
|
|
// yourEndpoint填写Bucket对应的Endpoint,以华东1(杭州)为例,填写为https://oss-cn-hangzhou.aliyuncs.com。其它Region请按实际情况填写。
|
|
|
// 阿里云账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户。
|
|
|
client, err := oss.New("https://oss-cn-shenzhen.aliyuncs.com", "LTAI5tNvMLF181bTb3qCZxk4", "9HXWh6yTXhbBQ7WaMkS1c3o0UNtl7A")
|
|
|
if err != nil {
|
|
|
fmt.Println("Error:", err)
|
|
|
os.Exit(-1)
|
|
|
}
|
|
|
|
|
|
// 填写存储空间名称,例如examplebucket。
|
|
|
|
|
|
var del []string
|
|
|
bucket, err := client.Bucket("client-project-resource")
|
|
|
if err != nil {
|
|
|
fmt.Println("Error:", err)
|
|
|
os.Exit(-1)
|
|
|
}
|
|
|
|
|
|
files, _ := os.ReadDir("./a")
|
|
|
for _, v := range files {
|
|
|
//name := static + "games/" + v.Name()
|
|
|
name := "ftg/gasha/topic/lavender/" + v.Name()
|
|
|
|
|
|
//fn := strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(v.Name(), "zh_TW", "zh-TW"), "{{", ""), "}}", "")
|
|
|
//
|
|
|
//name := "ftg/gold/" + strings.ReplaceAll(fn, ".green.", ".dark_green.")
|
|
|
// 依次填写Object的完整路径(例如exampledir/exampleobject.txt)和本地文件的完整路径(例如D:\\localpath\\examplefile.txt)。
|
|
|
err = bucket.PutObjectFromFile(name, "./a/"+v.Name())
|
|
|
if err != nil {
|
|
|
fmt.Println("Error:", err)
|
|
|
os.Exit(-1)
|
|
|
}
|
|
|
t.Log(name)
|
|
|
|
|
|
del = append(del, name)
|
|
|
}
|
|
|
|
|
|
//res, err := bucket.DeleteObjects(del)
|
|
|
//if err != nil {
|
|
|
// fmt.Println("Error:", err)
|
|
|
// os.Exit(-1)
|
|
|
//}
|
|
|
//t.Log(res)
|
|
|
|
|
|
}
|
|
|
|
|
|
func TestName3(t *testing.T) {
|
|
|
// 创建OSSClient实例。
|
|
|
// yourEndpoint填写Bucket对应的Endpoint,以华东1(杭州)为例,填写为https://oss-cn-hangzhou.aliyuncs.com。其它Region请按实际情况填写。
|
|
|
// 阿里云账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户。
|
|
|
client, err := oss.New("https://oss-cn-shenzhen.aliyuncs.com", "LTAI5tNvMLF181bTb3qCZxk4", "9HXWh6yTXhbBQ7WaMkS1c3o0UNtl7A")
|
|
|
if err != nil {
|
|
|
fmt.Println("Error:", err)
|
|
|
os.Exit(-1)
|
|
|
}
|
|
|
|
|
|
//填写存储空间名称,例如examplebucket。
|
|
|
bucket, err := client.Bucket("client-project-resource")
|
|
|
if err != nil {
|
|
|
fmt.Println("Error:", err)
|
|
|
os.Exit(-1)
|
|
|
}
|
|
|
|
|
|
name := "ftg/gasha/topic"
|
|
|
var del []string
|
|
|
err = filepath.Walk("./a", func(path string, info fs.FileInfo, err error) error {
|
|
|
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
if info.IsDir() {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
filename := name + strings.ReplaceAll(strings.TrimPrefix(path, "a"), "\\", "/")
|
|
|
path = "./" + path
|
|
|
|
|
|
t.Log(filename, path)
|
|
|
|
|
|
//依次填写Object的完整路径(例如exampledir/exampleobject.txt)和本地文件的完整路径(例如D:\\localpath\\examplefile.txt)。
|
|
|
err = bucket.PutObjectFromFile(filename, path)
|
|
|
if err != nil {
|
|
|
fmt.Println("Error:", err)
|
|
|
os.Exit(-1)
|
|
|
}
|
|
|
|
|
|
del = append(del, filename)
|
|
|
|
|
|
return nil
|
|
|
})
|
|
|
|
|
|
//res, err := bucket.DeleteObjects(del)
|
|
|
//if err != nil {
|
|
|
// fmt.Println("Error:", err)
|
|
|
// os.Exit(-1)
|
|
|
//}
|
|
|
//t.Log(res)
|
|
|
|
|
|
t.Log(err)
|
|
|
}
|
|
|
|
|
|
func TestName4(t *testing.T) {
|
|
|
// 创建OSSClient实例。
|
|
|
// yourEndpoint填写Bucket对应的Endpoint,以华东1(杭州)为例,填写为https://oss-cn-hangzhou.aliyuncs.com。其它Region请按实际情况填写。
|
|
|
// 阿里云账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户。
|
|
|
client, err := oss.New("https://oss-cn-shenzhen.aliyuncs.com", "LTAI5tNvMLF181bTb3qCZxk4", "9HXWh6yTXhbBQ7WaMkS1c3o0UNtl7A")
|
|
|
if err != nil {
|
|
|
fmt.Println("Error:", err)
|
|
|
os.Exit(-1)
|
|
|
}
|
|
|
|
|
|
// 填写存储空间名称,例如examplebucket。
|
|
|
|
|
|
var del []string
|
|
|
bucket, err := client.Bucket("client-project-resource")
|
|
|
if err != nil {
|
|
|
fmt.Println("Error:", err)
|
|
|
os.Exit(-1)
|
|
|
}
|
|
|
|
|
|
files, _ := os.ReadDir("./a")
|
|
|
for _, v := range files {
|
|
|
//name := static + v.Name()
|
|
|
name := "ftg/dice/" + v.Name()
|
|
|
|
|
|
t.Log(name)
|
|
|
|
|
|
del = append(del, name)
|
|
|
}
|
|
|
|
|
|
for mark := range mtype.MarkToLangType {
|
|
|
del = append(del, fmt.Sprintf("taskcenter/lang/dev/%s.json", mark))
|
|
|
}
|
|
|
|
|
|
t.Log(del)
|
|
|
|
|
|
res, err := bucket.DeleteObjects(del)
|
|
|
if err != nil {
|
|
|
fmt.Println("Error:", err)
|
|
|
os.Exit(-1)
|
|
|
}
|
|
|
t.Log(res)
|
|
|
|
|
|
}
|