🎇 139yun family support

pull/548/head
微凉 2022-01-11 23:43:55 +08:00
parent 602994e213
commit ddf6a4955f
5 changed files with 315 additions and 89 deletions

View File

@ -9,6 +9,7 @@ import (
"github.com/Xhofe/alist/utils" "github.com/Xhofe/alist/utils"
"github.com/go-resty/resty/v2" "github.com/go-resty/resty/v2"
jsoniter "github.com/json-iterator/go" jsoniter "github.com/json-iterator/go"
log "github.com/sirupsen/logrus"
"path" "path"
"time" "time"
) )
@ -18,11 +19,16 @@ func (driver Cloud139) Request(pathname string, method int, headers, query, form
req := base.RestyClient.R() req := base.RestyClient.R()
randStr := randomStr(16) randStr := randomStr(16)
ts := time.Now().Format("2006-01-02 15:04:05") ts := time.Now().Format("2006-01-02 15:04:05")
log.Debugf("%+v", data)
body, err := utils.Json.Marshal(data) body, err := utils.Json.Marshal(data)
if err != nil { if err != nil {
return nil, err return nil, err
} }
sign := calSign(string(body), ts, randStr) sign := calSign(string(body), ts, randStr)
svcType := "1"
if isFamily(account) {
svcType = "2"
}
req.SetHeaders(map[string]string{ req.SetHeaders(map[string]string{
"Accept": "application/json, text/plain, */*", "Accept": "application/json, text/plain, */*",
"CMS-DEVICE": "default", "CMS-DEVICE": "default",
@ -40,7 +46,7 @@ func (driver Cloud139) Request(pathname string, method int, headers, query, form
"x-inner-ntwk": "2", "x-inner-ntwk": "2",
"x-m4c-caller": "PC", "x-m4c-caller": "PC",
"x-m4c-src": "10002", "x-m4c-src": "10002",
"x-SvcType": "1", "x-SvcType": svcType,
}) })
if headers != nil { if headers != nil {
req.SetHeaders(headers) req.SetHeaders(headers)
@ -75,6 +81,7 @@ func (driver Cloud139) Request(pathname string, method int, headers, query, form
if err != nil { if err != nil {
return nil, err return nil, err
} }
log.Debugln(res.String())
if !e.Success { if !e.Success {
return nil, errors.New(e.Message) return nil, errors.New(e.Message)
} }

View File

@ -54,6 +54,12 @@ func (driver Cloud139) Items() []base.Item {
Type: base.TypeString, Type: base.TypeString,
Required: true, Required: true,
}, },
{
Name: "site_id",
Label: "cloud_id",
Type: base.TypeString,
Required: false,
},
} }
} }
@ -105,7 +111,11 @@ func (driver Cloud139) Files(path string, account *model.Account) ([]model.File,
if err != nil { if err != nil {
return nil, err return nil, err
} }
if isFamily(account) {
files, err = driver.familyGetFiles(file.Id, account)
} else {
files, err = driver.GetFiles(file.Id, account) files, err = driver.GetFiles(file.Id, account)
}
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -169,12 +179,26 @@ func (driver Cloud139) MakeDir(path string, account *model.Account) error {
}, },
} }
pathname := "/orchestration/personalCloud/catalog/v1.0/createCatalogExt" pathname := "/orchestration/personalCloud/catalog/v1.0/createCatalogExt"
if isFamily(account) {
data = base.Json{
"cloudID": account.SiteId,
"commonAccountInfo": base.Json{
"account": account.Username,
"accountType": 1,
},
"docLibName": utils.Base(path),
}
pathname = "/orchestration/familyCloud/cloudCatalog/v1.0/createCloudDoc"
}
_, err = driver.Post(pathname, _, err = driver.Post(pathname,
data, nil, account) data, nil, account)
return err return err
} }
func (driver Cloud139) Move(src string, dst string, account *model.Account) error { func (driver Cloud139) Move(src string, dst string, account *model.Account) error {
if isFamily(account) {
return base.ErrNotSupport
}
srcFile, err := driver.File(src, account) srcFile, err := driver.File(src, account)
if err != nil { if err != nil {
return err return err
@ -211,6 +235,9 @@ func (driver Cloud139) Move(src string, dst string, account *model.Account) erro
} }
func (driver Cloud139) Rename(src string, dst string, account *model.Account) error { func (driver Cloud139) Rename(src string, dst string, account *model.Account) error {
if isFamily(account) {
return base.ErrNotSupport
}
srcFile, err := driver.File(src, account) srcFile, err := driver.File(src, account)
if err != nil { if err != nil {
return err return err
@ -243,6 +270,9 @@ func (driver Cloud139) Rename(src string, dst string, account *model.Account) er
} }
func (driver Cloud139) Copy(src string, dst string, account *model.Account) error { func (driver Cloud139) Copy(src string, dst string, account *model.Account) error {
if isFamily(account) {
return base.ErrNotSupport
}
srcFile, err := driver.File(src, account) srcFile, err := driver.File(src, account)
if err != nil { if err != nil {
return err return err
@ -251,19 +281,21 @@ func (driver Cloud139) Copy(src string, dst string, account *model.Account) erro
if err != nil { if err != nil {
return err return err
} }
argName := "contentInfoList" var contentInfoList []string
var catalogInfoList []string
if srcFile.IsDir() { if srcFile.IsDir() {
argName = "catalogInfoList" catalogInfoList = append(catalogInfoList, srcFile.Id)
} else {
contentInfoList = append(contentInfoList, srcFile.Id)
} }
data := base.Json{ data := base.Json{
"createBatchOprTaskReq": base.Json{ "createBatchOprTaskReq": base.Json{
"taskType": 3, "taskType": 3,
"actionType": 309, "actionType": 309,
"taskInfo": base.Json{ "taskInfo": base.Json{
"contentInfoList": []string{}, "contentInfoList": contentInfoList,
"catalogInfoList": []string{}, "catalogInfoList": catalogInfoList,
"newCatalogID": dstParentFile.Id, "newCatalogID": dstParentFile.Id,
argName: []string{srcFile.Id},
}, },
"commonAccountInfo": base.Json{ "commonAccountInfo": base.Json{
"account": "18627147660", "account": "18627147660",
@ -281,9 +313,12 @@ func (driver Cloud139) Delete(path string, account *model.Account) error {
if err != nil { if err != nil {
return err return err
} }
argName := "contentInfoList" var contentInfoList []string
var catalogInfoList []string
if file.IsDir() { if file.IsDir() {
argName = "catalogInfoList" catalogInfoList = append(catalogInfoList, file.Id)
} else {
contentInfoList = append(contentInfoList, file.Id)
} }
data := base.Json{ data := base.Json{
"createBatchOprTaskReq": base.Json{ "createBatchOprTaskReq": base.Json{
@ -291,7 +326,8 @@ func (driver Cloud139) Delete(path string, account *model.Account) error {
"actionType": 201, "actionType": 201,
"taskInfo": base.Json{ "taskInfo": base.Json{
"newCatalogID": "", "newCatalogID": "",
argName: []string{file.Id}, "contentInfoList": contentInfoList,
"catalogInfoList": contentInfoList,
}, },
"commonAccountInfo": base.Json{ "commonAccountInfo": base.Json{
"account": "18627147660", "account": "18627147660",
@ -300,6 +336,19 @@ func (driver Cloud139) Delete(path string, account *model.Account) error {
}, },
} }
pathname := "/orchestration/personalCloud/batchOprTask/v1.0/createBatchOprTask" pathname := "/orchestration/personalCloud/batchOprTask/v1.0/createBatchOprTask"
if isFamily(account) {
data = base.Json{
"catalogList": catalogInfoList,
"contentList": contentInfoList,
"commonAccountInfo": base.Json{
"account": "18627147660",
"accountType": 1,
},
"sourceCatalogType": 1002,
"taskType": 2,
}
pathname = "/orchestration/familyCloud/batchOprTask/v1.0/createBatchOprTask"
}
_, err = driver.Post(pathname, data, nil, account) _, err = driver.Post(pathname, data, nil, account)
return err return err
} }
@ -333,6 +382,23 @@ func (driver Cloud139) Upload(file *model.FileStream, account *model.Account) er
}, },
} }
pathname := "/orchestration/personalCloud/uploadAndDownload/v1.0/pcUploadFileRequest" pathname := "/orchestration/personalCloud/uploadAndDownload/v1.0/pcUploadFileRequest"
if isFamily(account) {
data = newJson(base.Json{
"fileCount": 1,
"manualRename": 2,
"operation": 0,
"path": "",
"seqNo": "",
"totalSize": file.Size,
"uploadContentList": []base.Json{{
"contentName": file.Name,
"contentSize": file.Size,
// "digest": "5a3231986ce7a6b46e408612d385bafa"
}},
}, account)
pathname = "/orchestration/familyCloud/content/v1.0/getFileUploadURL"
return base.ErrNotSupport
}
var resp UploadResp var resp UploadResp
_, err = driver.Post(pathname, data, &resp, account) _, err = driver.Post(pathname, data, &resp, account)
if err != nil { if err != nil {

74
drivers/139/family.go Normal file
View File

@ -0,0 +1,74 @@
package _39
import (
"github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/drivers/base"
"github.com/Xhofe/alist/model"
"github.com/Xhofe/alist/utils"
jsoniter "github.com/json-iterator/go"
"path"
)
func (driver Cloud139) familyGetFiles(catalogID string, account *model.Account) ([]model.File, error) {
pageNum := 1
files := make([]model.File, 0)
for {
data := newJson(base.Json{
"catalogID": catalogID,
"contentSortType": 0,
"pageInfo": base.Json{
"pageNum": pageNum,
"pageSize": 100,
},
"sortDirection": 1,
}, account)
var resp QueryContentListResp
_, err := driver.Post("/orchestration/familyCloud/content/v1.0/queryContentList", data, &resp, account)
if err != nil {
return nil, err
}
for _, catalog := range resp.Data.CloudCatalogList {
f := model.File{
Id: catalog.CatalogID,
Name: catalog.CatalogName,
Size: 0,
Type: conf.FOLDER,
Driver: driver.Config().Name,
UpdatedAt: getTime(catalog.LastUpdateTime),
}
files = append(files, f)
}
for _, content := range resp.Data.CloudContentList {
f := model.File{
Id: content.ContentID,
Name: content.ContentName,
Size: int64(content.ContentSize),
Type: utils.GetFileType(path.Ext(content.ContentName)),
Driver: driver.Config().Name,
UpdatedAt: getTime(content.LastUpdateTime),
Thumbnail: content.ThumbnailURL,
//Thumbnail: content.BigthumbnailURL,
}
files = append(files, f)
}
if 100*pageNum > resp.Data.TotalCount {
break
}
pageNum++
}
return files, nil
}
func (driver Cloud139) familyLink(contentId string, account *model.Account) (string, error) {
data := newJson(base.Json{
"contentID": contentId,
//"path":"",
}, account)
res, err := driver.Post("/orchestration/familyCloud/content/v1.0/getFileDownLoadURL",
data, nil, account)
if err != nil {
return "", err
}
return jsoniter.Get(res, "data", "downloadURL").ToString(), nil
}

View File

@ -9,85 +9,85 @@ type BaseResp struct {
type Catalog struct { type Catalog struct {
CatalogID string `json:"catalogID"` CatalogID string `json:"catalogID"`
CatalogName string `json:"catalogName"` CatalogName string `json:"catalogName"`
CatalogType int `json:"catalogType"` //CatalogType int `json:"catalogType"`
CreateTime string `json:"createTime"` //CreateTime string `json:"createTime"`
UpdateTime string `json:"updateTime"` UpdateTime string `json:"updateTime"`
IsShared bool `json:"isShared"` //IsShared bool `json:"isShared"`
CatalogLevel int `json:"catalogLevel"` //CatalogLevel int `json:"catalogLevel"`
ShareDoneeCount int `json:"shareDoneeCount"` //ShareDoneeCount int `json:"shareDoneeCount"`
OpenType int `json:"openType"` //OpenType int `json:"openType"`
ParentCatalogID string `json:"parentCatalogId"` //ParentCatalogID string `json:"parentCatalogId"`
DirEtag int `json:"dirEtag"` //DirEtag int `json:"dirEtag"`
Tombstoned int `json:"tombstoned"` //Tombstoned int `json:"tombstoned"`
ProxyID interface{} `json:"proxyID"` //ProxyID interface{} `json:"proxyID"`
Moved int `json:"moved"` //Moved int `json:"moved"`
IsFixedDir int `json:"isFixedDir"` //IsFixedDir int `json:"isFixedDir"`
IsSynced interface{} `json:"isSynced"` //IsSynced interface{} `json:"isSynced"`
Owner string `json:"owner"` //Owner string `json:"owner"`
Modifier interface{} `json:"modifier"` //Modifier interface{} `json:"modifier"`
Path string `json:"path"` //Path string `json:"path"`
ShareType int `json:"shareType"` //ShareType int `json:"shareType"`
SoftLink interface{} `json:"softLink"` //SoftLink interface{} `json:"softLink"`
ExtProp1 interface{} `json:"extProp1"` //ExtProp1 interface{} `json:"extProp1"`
ExtProp2 interface{} `json:"extProp2"` //ExtProp2 interface{} `json:"extProp2"`
ExtProp3 interface{} `json:"extProp3"` //ExtProp3 interface{} `json:"extProp3"`
ExtProp4 interface{} `json:"extProp4"` //ExtProp4 interface{} `json:"extProp4"`
ExtProp5 interface{} `json:"extProp5"` //ExtProp5 interface{} `json:"extProp5"`
ETagOprType int `json:"ETagOprType"` //ETagOprType int `json:"ETagOprType"`
} }
type Content struct { type Content struct {
ContentID string `json:"contentID"` ContentID string `json:"contentID"`
ContentName string `json:"contentName"` ContentName string `json:"contentName"`
ContentSuffix string `json:"contentSuffix"` //ContentSuffix string `json:"contentSuffix"`
ContentSize int `json:"contentSize"` ContentSize int `json:"contentSize"`
ContentDesc string `json:"contentDesc"` //ContentDesc string `json:"contentDesc"`
ContentType int `json:"contentType"` //ContentType int `json:"contentType"`
ContentOrigin int `json:"contentOrigin"` //ContentOrigin int `json:"contentOrigin"`
UpdateTime string `json:"updateTime"` UpdateTime string `json:"updateTime"`
CommentCount int `json:"commentCount"` //CommentCount int `json:"commentCount"`
ThumbnailURL string `json:"thumbnailURL"` ThumbnailURL string `json:"thumbnailURL"`
BigthumbnailURL string `json:"bigthumbnailURL"` //BigthumbnailURL string `json:"bigthumbnailURL"`
PresentURL string `json:"presentURL"` //PresentURL string `json:"presentURL"`
PresentLURL string `json:"presentLURL"` //PresentLURL string `json:"presentLURL"`
PresentHURL string `json:"presentHURL"` //PresentHURL string `json:"presentHURL"`
ContentTAGList interface{} `json:"contentTAGList"` //ContentTAGList interface{} `json:"contentTAGList"`
ShareDoneeCount int `json:"shareDoneeCount"` //ShareDoneeCount int `json:"shareDoneeCount"`
Safestate int `json:"safestate"` //Safestate int `json:"safestate"`
Transferstate int `json:"transferstate"` //Transferstate int `json:"transferstate"`
IsFocusContent int `json:"isFocusContent"` //IsFocusContent int `json:"isFocusContent"`
UpdateShareTime interface{} `json:"updateShareTime"` //UpdateShareTime interface{} `json:"updateShareTime"`
UploadTime string `json:"uploadTime"` //UploadTime string `json:"uploadTime"`
OpenType int `json:"openType"` //OpenType int `json:"openType"`
AuditResult int `json:"auditResult"` //AuditResult int `json:"auditResult"`
ParentCatalogID string `json:"parentCatalogId"` //ParentCatalogID string `json:"parentCatalogId"`
Channel string `json:"channel"` //Channel string `json:"channel"`
GeoLocFlag string `json:"geoLocFlag"` //GeoLocFlag string `json:"geoLocFlag"`
Digest string `json:"digest"` //Digest string `json:"digest"`
Version string `json:"version"` //Version string `json:"version"`
FileEtag string `json:"fileEtag"` //FileEtag string `json:"fileEtag"`
FileVersion string `json:"fileVersion"` //FileVersion string `json:"fileVersion"`
Tombstoned int `json:"tombstoned"` //Tombstoned int `json:"tombstoned"`
ProxyID string `json:"proxyID"` //ProxyID string `json:"proxyID"`
Moved int `json:"moved"` //Moved int `json:"moved"`
MidthumbnailURL string `json:"midthumbnailURL"` //MidthumbnailURL string `json:"midthumbnailURL"`
Owner string `json:"owner"` //Owner string `json:"owner"`
Modifier string `json:"modifier"` //Modifier string `json:"modifier"`
ShareType int `json:"shareType"` //ShareType int `json:"shareType"`
ExtInfo struct { //ExtInfo struct {
Uploader string `json:"uploader"` // Uploader string `json:"uploader"`
Address string `json:"address"` // Address string `json:"address"`
} `json:"extInfo"` //} `json:"extInfo"`
Exif struct { //Exif struct {
CreateTime string `json:"createTime"` // CreateTime string `json:"createTime"`
Longitude interface{} `json:"longitude"` // Longitude interface{} `json:"longitude"`
Latitude interface{} `json:"latitude"` // Latitude interface{} `json:"latitude"`
LocalSaveTime interface{} `json:"localSaveTime"` // LocalSaveTime interface{} `json:"localSaveTime"`
} `json:"exif"` //} `json:"exif"`
CollectionFlag interface{} `json:"collectionFlag"` //CollectionFlag interface{} `json:"collectionFlag"`
TreeInfo interface{} `json:"treeInfo"` //TreeInfo interface{} `json:"treeInfo"`
IsShared bool `json:"isShared"` //IsShared bool `json:"isShared"`
ETagOprType int `json:"ETagOprType"` //ETagOprType int `json:"ETagOprType"`
} }
type GetDiskResp struct { type GetDiskResp struct {
@ -130,3 +130,58 @@ type UploadResp struct {
} `json:"uploadResult"` } `json:"uploadResult"`
} `json:"data"` } `json:"data"`
} }
type CloudContent struct {
ContentID string `json:"contentID"`
Modifier string `json:"modifier"`
Nickname string `json:"nickname"`
CloudNickName string `json:"cloudNickName"`
ContentName string `json:"contentName"`
ContentType int `json:"contentType"`
ContentSuffix string `json:"contentSuffix"`
ContentSize int `json:"contentSize"`
ContentDesc string `json:"contentDesc"`
CreateTime string `json:"createTime"`
Shottime interface{} `json:"shottime"`
LastUpdateTime string `json:"lastUpdateTime"`
ThumbnailURL string `json:"thumbnailURL"`
MidthumbnailURL string `json:"midthumbnailURL"`
BigthumbnailURL string `json:"bigthumbnailURL"`
PresentURL string `json:"presentURL"`
PresentLURL string `json:"presentLURL"`
PresentHURL string `json:"presentHURL"`
ParentCatalogID string `json:"parentCatalogID"`
Uploader string `json:"uploader"`
UploaderNickName string `json:"uploaderNickName"`
TreeInfo interface{} `json:"treeInfo"`
UpdateTime interface{} `json:"updateTime"`
ExtInfo struct {
Uploader string `json:"uploader"`
} `json:"extInfo"`
EtagOprType interface{} `json:"etagOprType"`
}
type CloudCatalog struct {
CatalogID string `json:"catalogID"`
CatalogName string `json:"catalogName"`
CloudID string `json:"cloudID"`
CreateTime string `json:"createTime"`
LastUpdateTime string `json:"lastUpdateTime"`
Creator string `json:"creator"`
CreatorNickname string `json:"creatorNickname"`
}
type QueryContentListResp struct {
BaseResp
Data struct {
Result struct {
ResultCode string `json:"resultCode"`
ResultDesc string `json:"resultDesc"`
} `json:"result"`
Path string `json:"path"`
CloudContentList []CloudContent `json:"cloudContentList"`
CloudCatalogList []CloudCatalog `json:"cloudCatalogList"`
TotalCount int `json:"totalCount"`
RecallContent interface{} `json:"recallContent"`
} `json:"data"`
}

View File

@ -2,6 +2,7 @@ package _39
import ( import (
"encoding/base64" "encoding/base64"
"github.com/Xhofe/alist/drivers/base"
"github.com/Xhofe/alist/model" "github.com/Xhofe/alist/model"
"github.com/Xhofe/alist/utils" "github.com/Xhofe/alist/utils"
"math/rand" "math/rand"
@ -55,3 +56,26 @@ func unicode(str string) string {
textUnquoted := textQuoted[1 : len(textQuoted)-1] textUnquoted := textQuoted[1 : len(textQuoted)-1]
return textUnquoted return textUnquoted
} }
func MergeMap(mObj ...map[string]interface{}) map[string]interface{} {
newObj := map[string]interface{}{}
for _, m := range mObj {
for k, v := range m {
newObj[k] = v
}
}
return newObj
}
func newJson(data map[string]interface{}, account *model.Account) map[string]interface{} {
common := map[string]interface{}{
"catalogType": 3,
"cloudID": account.SiteId,
"cloudType": 1,
"commonAccountInfo": base.Json{
"account": account.Username,
"accountType": 1,
},
}
return MergeMap(data, common)
}