代码拉取完成,页面将自动刷新
同步操作将从 进击的皇虫/CloudStore 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
package CloudStore
import (
"errors"
"fmt"
"os"
"path/filepath"
"strings"
"time"
"github.com/upyun/go-sdk/upyun"
)
type UpYun struct {
Bucket string
Operator string
Password string
Domain string
Client *upyun.UpYun
secret string
}
func NewUpYun(bucket, operator, password, domain, secret string) *UpYun {
if !strings.HasPrefix(domain, "http://") && !strings.HasPrefix(domain, "https://") {
domain = "http://" + domain
}
domain = strings.TrimRight(domain, "/")
client := upyun.NewUpYun(&upyun.UpYunConfig{
Bucket: bucket,
Operator: operator,
Password: password,
})
return &UpYun{
Bucket: bucket,
Operator: operator,
Password: password,
Domain: domain,
Client: client,
secret: secret,
}
}
func (u *UpYun) IsExist(object string) (err error) {
_, err = u.Client.GetInfo(objectAbs(object))
return
}
func (u *UpYun) Upload(tmpFile, saveFile string, headers ...map[string]string) (err error) {
_, err = os.Stat(tmpFile)
h := make(map[string]string)
if err != nil {
return
}
for _, header := range headers {
for k, v := range header {
h[k] = v
}
}
err = u.Client.Put(&upyun.PutObjectConfig{
Path: objectAbs(saveFile),
LocalPath: tmpFile,
Headers: h,
})
return
}
func (u *UpYun) Delete(objects ...string) (err error) {
var errs []string
for _, object := range objects {
err = u.Client.Delete(&upyun.DeleteObjectConfig{
Path: objectAbs(object),
})
if err != nil {
errs = append(errs, err.Error())
}
}
if len(errs) > 0 {
err = errors.New(strings.Join(errs, "; "))
}
return
}
// https://help.upyun.com/knowledge-base/cdn-token-limite/
func (u *UpYun) GetSignURL(object string, expire int64) (link string, err error) {
path := objectAbs(object)
if expire <= 0 {
return u.Domain + path, nil
}
endTime := time.Now().Unix() + expire
sign := MD5Crypt(fmt.Sprintf("%v&%v&%v", u.secret, endTime, path))
sign = strings.Join(strings.Split(sign, "")[12:20], "") + fmt.Sprint(endTime)
return u.Domain + path + "?_upt=" + sign, nil
}
func (u *UpYun) Lists(prefix string) (files []File, err error) {
chans := make(chan *upyun.FileInfo, 1000)
prefix = objectRel(prefix)
u.Client.List(&upyun.GetObjectsConfig{
Path: prefix,
ObjectsChan: chans,
})
var file File
for obj := range chans {
file = File{
ModTime: obj.Time,
Size: obj.Size,
IsDir: obj.IsDir,
Header: obj.Meta, // 注意:这里获取不到文件的header
Name: filepath.Join(prefix, objectRel(obj.Name)),
}
files = append(files, file)
}
return
}
func (u *UpYun) Download(object string, savePath string) (err error) {
_, err = u.Client.Get(&upyun.GetObjectConfig{
Path: objectAbs(object),
LocalPath: savePath,
})
return
}
func (u *UpYun) GetInfo(object string) (info File, err error) {
var fileInfo *upyun.FileInfo
fileInfo, err = u.Client.GetInfo(objectAbs(object))
if err != nil {
return
}
info = File{
ModTime: fileInfo.Time,
Name: objectRel(fileInfo.Name),
Size: fileInfo.Size,
IsDir: fileInfo.IsDir,
Header: fileInfo.Meta,
}
return
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。