-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmkzip.go
62 lines (59 loc) · 1.9 KB
/
mkzip.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package xqiniu
import (
"encoding/base64"
"github.com/google/uuid"
"github.com/qiniu/api.v7/v7/storage"
"time"
)
type ZipData struct {
QiniuFileKey string
ZipRename string
}
func (q Client) CreateMkzipIndex(zips []ZipData, indexFileanme string)(reply Reply ,err error) {
var data []byte
for _, item := range zips {
url := q.PrivateURL(PrivateURL{
Key: item.QiniuFileKey,
Duration: time.Minute * 120,
Attname: item.QiniuFileKey,
})
s := "/url/" + base64.URLEncoding.EncodeToString([]byte(url)) +
"/alias/" + base64.URLEncoding.EncodeToString([]byte(item.ZipRename)) +
"\n"
data = append(data, []byte(s)...)
}
return q.BytesUpdate(BytesUpdate{
QiniuFileKey: indexFileanme,
Data: data,
RputExtra: storage.RputExtra{},
PutPolicy: storage.PutPolicy{},
})
}
type Pfop struct {
Source []ZipData
QiniuZipFileKey string
NotifyURL string
}
func (q Client) Pfop(data Pfop) (persistentID PersistentID,err error) {
indexFileKey := "golang/og/go-better-qiniu/mkzip-index/" + uuid.New().String() + ".txt"
indexReply, err := q.CreateMkzipIndex(data.Source, indexFileKey) ; if err != nil {return "", err}
om := storage.NewOperationManager(q.Credentials(), &q.StorageConfig)
key := indexReply.Key
fops := "mkzip/4/|saveas/" + base64.URLEncoding.EncodeToString([]byte(q.Bucket + ":" + data.QiniuZipFileKey))
pipeline := ""
notifyURL := data.NotifyURL
stringPersistentID, err := om.Pfop(q.Bucket, key, fops, pipeline, notifyURL, false) ; if err != nil {return "", err }
persistentID = NewPersistentID(stringPersistentID)
return
}
type PersistentID string
func NewPersistentID (s string) PersistentID {
return PersistentID(s)
}
func (id PersistentID) String() string {
return string(id)
}
func (q Client) Prefop(persistentID PersistentID) (ret storage.PrefopRet ,err error) {
om := storage.NewOperationManager(q.Credentials(), &q.StorageConfig)
return om.Prefop(persistentID.String())
}