Skip to content

Commit

Permalink
v1.6.29
Browse files Browse the repository at this point in the history
  • Loading branch information
liupan1890 committed Jun 29, 2021
1 parent 647fab1 commit 7ee55a3
Show file tree
Hide file tree
Showing 54 changed files with 2,434 additions and 1,072 deletions.
387 changes: 89 additions & 298 deletions aliserver/aliyun/ApiFile.go

Large diffs are not rendered by default.

82 changes: 22 additions & 60 deletions aliserver/aliyun/ApiFileDown.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,12 @@ func ApiFileDownloadUrl(boxid string, file_id string, expire_sec int) (downurl s
"file_id": file_id,
"expire_sec": expire_sec,
}
postdata, _ := json.Marshal(postjson)
code, bodybytes := _APIHTTP(apiurl, &postdata)
body := string(*bodybytes)

b, _ := json.Marshal(postjson)
postdata := string(b)

code, _, body := utils.PostHTTPString(apiurl, GetAuthorization(), postdata)
if code == 401 {
//UserAccessToken 失效了,尝试刷新一次
ApiTokenRefresh("")
//刷新完了,重新尝试一遍
code, _, body = utils.PostHTTPString(apiurl, GetAuthorization(), postdata)
if code == 401 {
return "", 0, errors.New("401")
}
return "", 0, errors.New("401")
}
if code != 200 || !gjson.Valid(body) {
return "", 0, errors.New("error")
Expand Down Expand Up @@ -84,19 +77,12 @@ func ApiFileGetUrl(boxid string, file_id string, parentpath string) (urlinfo Fil
var postjson = map[string]interface{}{"drive_id": boxid,
"file_id": file_id}

b, _ := json.Marshal(postjson)
postdata := string(b)

code, _, body := utils.PostHTTPString(apiurl, GetAuthorization(), postdata)
postdata, _ := json.Marshal(postjson)
code, bodybytes := _APIHTTP(apiurl, &postdata)
if code == 401 {
//UserAccessToken 失效了,尝试刷新一次
ApiTokenRefresh("")
//刷新完了,重新尝试一遍
code, _, body = utils.PostHTTPString(apiurl, GetAuthorization(), postdata)
if code == 401 {
return urlinfo, errors.New("401")
}
return urlinfo, errors.New("401")
}
body := string(*bodybytes)
if code != 200 || !gjson.Valid(body) {
return urlinfo, errors.New("error")
}
Expand Down Expand Up @@ -136,7 +122,7 @@ func ApiFileListAllForDown(boxid string, parentid string, parentpath string, isf
return list, nil
}
}
return nil, errors.New("error")
return nil, err
}

//_ApiFileListAllForDown 读取一个文件夹包含的文件列表 isfull==true时遍历所有子文件夹
Expand All @@ -151,7 +137,7 @@ func _ApiFileListAllForDown(boxid string, parentid string, parentpath string, is
for {
flist, next, ferr := ApiFileListUrl(boxid, parentid, parentpath, marker)
if ferr != nil {
return nil, errors.New("error") //有错误直接退出
return nil, ferr //有错误直接退出
}
if len(flist) > 0 {
list = append(list, flist...)
Expand Down Expand Up @@ -205,20 +191,14 @@ func ApiFileListUrl(boxid string, parentid string, parentpath string, marker str
if marker != "" {
postjson["marker"] = marker
}
b, _ := json.Marshal(postjson)
postdata := string(b)

//"image_thumbnail_process":"image/resize,w_160/format,jpeg",
//"image_url_process":"image/resize,w_1920/format,jpeg",
//"video_thumbnail_process":"video/snapshot,t_0,f_jpg,ar_auto,w_300",

code, _, body := utils.PostHTTPString(apiurl, GetAuthorization(), postdata)
if code == 401 {
//UserAccessToken 失效了,尝试刷新一次
ApiTokenRefresh("")
//刷新完了,重新尝试一遍
code, _, body = utils.PostHTTPString(apiurl, GetAuthorization(), postdata)
}
postdata, _ := json.Marshal(postjson)
code, bodybytes := _APIHTTP(apiurl, &postdata)
body := string(*bodybytes)
if code != 200 || !gjson.Valid(body) {
return nil, "", errors.New("error")
}
Expand All @@ -233,7 +213,7 @@ func ApiFileListUrl(boxid string, parentid string, parentpath string, marker str
file_id := info.Get("file_id").String()
name := utils.ClearFileName(info.Get("name").String(), true)
if name == "" {
return nil, "", errors.New("error")
return nil, "", errors.New("nameerror")
}
if filetype == "file" {
//url := info.Get("url").String()
Expand Down Expand Up @@ -309,19 +289,10 @@ func ApiImage(boxid string, file_id string) string {
var postjson = map[string]interface{}{"drive_id": boxid,
"file_id": file_id}

b, _ := json.Marshal(postjson)
postdata := string(b)
postdata, _ := json.Marshal(postjson)
code, bodybytes := _APIHTTP(apiurl, &postdata)
body := string(*bodybytes)

code, _, body := utils.PostHTTPString(apiurl, GetAuthorization(), postdata)
if code == 401 {
//UserAccessToken 失效了,尝试刷新一次
ApiTokenRefresh("")
//刷新完了,重新尝试一遍
code, _, body = utils.PostHTTPString(apiurl, GetAuthorization(), postdata)
if code == 401 {
return utils.ToErrorMessageJSON("获取图片链接失败")
}
}
if code != 200 || !gjson.Valid(body) {
return utils.ToErrorMessageJSON("获取图片链接失败")
}
Expand Down Expand Up @@ -350,19 +321,10 @@ func ApiText(boxid string, file_id string) string {
var postjson = map[string]interface{}{"drive_id": boxid,
"file_id": file_id}

b, _ := json.Marshal(postjson)
postdata := string(b)
postdata, _ := json.Marshal(postjson)
code, bodybytes := _APIHTTP(apiurl, &postdata)
body := string(*bodybytes)

code, _, body := utils.PostHTTPString(apiurl, GetAuthorization(), postdata)
if code == 401 {
//UserAccessToken 失效了,尝试刷新一次
ApiTokenRefresh("")
//刷新完了,重新尝试一遍
code, _, body = utils.PostHTTPString(apiurl, GetAuthorization(), postdata)
if code == 401 {
return utils.ToErrorMessageJSON("获取文本链接失败")
}
}
if code != 200 || !gjson.Valid(body) {
return utils.ToErrorMessageJSON("获取文本链接失败")
}
Expand Down Expand Up @@ -412,8 +374,8 @@ func ApiText(boxid string, file_id string) string {
text := string(bodybs)
temp := []rune(text)
length4 := len(temp)
if length4 > 1024*100 { //1万字
text = string(temp[0:1024*100]) + "\n\n\n\n剩余" + strconv.FormatInt(int64(length4-1024*100), 10) + "字被省略.....\n\n\n\n"
if length4 > 1024*500 { //1万字
text = string(temp[0:1024*500]) + "\n\n\n\n剩余" + strconv.FormatInt(int64(length4-1024*500), 10) + "字被省略.....\n\n\n\n"
}
text = strings.ReplaceAll(text, " ", " ")
if text == "" {
Expand Down
91 changes: 28 additions & 63 deletions aliserver/aliyun/ApiFileUpload.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package aliyun

import (
"aliserver/utils"
"encoding/json"
"errors"
"log"
Expand All @@ -26,16 +25,9 @@ func UploadCreatForder(boxid string, parentid string, name string) (dirid string
"check_name_mode": "refuse",
"type": "folder"}

b, _ := json.Marshal(postjson)
postdata := string(b)

code, _, body := utils.PostHTTPString(apiurl, GetAuthorization(), postdata)
if code == 401 {
//UserAccessToken 失效了,尝试刷新一次
ApiTokenRefresh("")
//刷新完了,重新尝试一遍
code, _, body = utils.PostHTTPString(apiurl, GetAuthorization(), postdata)
}
postdata, _ := json.Marshal(postjson)
code, bodybytes := _APIHTTP(apiurl, &postdata)
body := string(*bodybytes)
if code != 201 || !gjson.Valid(body) { //注意这里是201
return "", errors.New("创建文件夹失败")
}
Expand Down Expand Up @@ -71,17 +63,13 @@ func UploadCreatFile(boxid string, parentid string, name string, size int64, has
"content_hash": strings.ToLower(hash),
}

b, _ := json.Marshal(postjson)
postdata := string(b)

code, _, body := utils.PostHTTPString(apiurl, GetAuthorization(), postdata)
if code == 401 {
//UserAccessToken 失效了,尝试刷新一次
ApiTokenRefresh("")
//刷新完了,重新尝试一遍
code, _, body = utils.PostHTTPString(apiurl, GetAuthorization(), postdata)
}
postdata, _ := json.Marshal(postjson)
code, bodybytes := _APIHTTP(apiurl, &postdata)
body := string(*bodybytes)
if code != 201 || !gjson.Valid(body) { //注意这里是201
if strings.Contains(body, "file size is exceed") {
return false, "", "", "", errors.New("创建文件失败(单文件最大30GB)")
}
return false, "", "", "", errors.New("创建文件失败")
}
info := gjson.Parse(body)
Expand Down Expand Up @@ -124,19 +112,14 @@ func UploadFileCheckHash(boxid string, file_id string, hash string) (Same bool,
var postjson = map[string]interface{}{"drive_id": boxid,
"file_id": file_id}

b, _ := json.Marshal(postjson)
postdata := string(b)
postdata, _ := json.Marshal(postjson)
code, bodybytes := _APIHTTP(apiurl, &postdata)
body := string(*bodybytes)

code, _, body := utils.PostHTTPString(apiurl, GetAuthorization(), postdata)
if code == 401 {
//UserAccessToken 失效了,尝试刷新一次
ApiTokenRefresh("")
//刷新完了,重新尝试一遍
code, _, body = utils.PostHTTPString(apiurl, GetAuthorization(), postdata)
if code == 401 {
return false, errors.New("401")
}
return false, errors.New("401")
}

if code != 200 || !gjson.Valid(body) {
return false, errors.New("error")
}
Expand All @@ -160,19 +143,12 @@ func UploadFileDelete(boxid string, file_id string) (Delete bool, err error) {
var postjson = map[string]interface{}{"drive_id": boxid,
"file_id": file_id}

b, _ := json.Marshal(postjson)
postdata := string(b)

code, _, _ := utils.PostHTTPString(apiurl, GetAuthorization(), postdata)
postdata, _ := json.Marshal(postjson)
code, _ := _APIHTTP(apiurl, &postdata)
if code == 401 {
//UserAccessToken 失效了,尝试刷新一次
ApiTokenRefresh("")
//刷新完了,重新尝试一遍
code, _, _ = utils.PostHTTPString(apiurl, GetAuthorization(), postdata)
if code == 401 {
return false, errors.New("401")
}
return false, errors.New("401")
}

if code != 204 && code != 202 {
return false, errors.New("error")
}
Expand All @@ -197,19 +173,13 @@ func UploadFileComplete(boxid string, parentid string, name string, file_id stri
"content_type": "",
}

b, _ := json.Marshal(postjson)
postdata := string(b)

code, _, body := utils.PostHTTPString(apiurl, GetAuthorization(), postdata)
postdata, _ := json.Marshal(postjson)
code, bodybytes := _APIHTTP(apiurl, &postdata)
body := string(*bodybytes)
if code == 401 {
//UserAccessToken 失效了,尝试刷新一次
ApiTokenRefresh("")
//刷新完了,重新尝试一遍
code, _, body = utils.PostHTTPString(apiurl, GetAuthorization(), postdata)
if code == 401 {
return errors.New("401")
}
return errors.New("401")
}

if code != 200 || !gjson.Valid(body) {
return errors.New("error")
}
Expand Down Expand Up @@ -242,19 +212,14 @@ func UploadFilePartUrl(boxid string, parentid string, name string, file_id strin
},
}

b, _ := json.Marshal(postjson)
postdata := string(b)
postdata, _ := json.Marshal(postjson)
code, bodybytes := _APIHTTP(apiurl, &postdata)
body := string(*bodybytes)

code, _, body := utils.PostHTTPString(apiurl, GetAuthorization(), postdata)
if code == 401 {
//UserAccessToken 失效了,尝试刷新一次
ApiTokenRefresh("")
//刷新完了,重新尝试一遍
code, _, body = utils.PostHTTPString(apiurl, GetAuthorization(), postdata)
if code == 401 {
return "", errors.New("401")
}
return "", errors.New("401")
}

if code != 200 || !gjson.Valid(body) {
return "", errors.New("error")
}
Expand Down
41 changes: 35 additions & 6 deletions aliserver/aliyun/ApiLink.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type LinkFileModel struct {
FileList []string `json:"FileList"`
Name string `json:"Name"`
Size int64 `json:"Size"`
Message string `json:"-"`
Message string `json:"Message"`
}

type LinkSearchModel struct {
Expand Down Expand Up @@ -69,7 +69,7 @@ func ApiFileListAllForLink(boxid string, file_id string, name string) (link *Lin
return link, nil
}
}
return nil, errors.New("error")
return nil, err
}

//_ApiFileListAllForLink 读取一个文件夹的信息(文件列表)(遍历子文件夹)
Expand All @@ -85,7 +85,7 @@ func _ApiFileListAllForLink(boxid string, file_id string, name string) (link *Li
for {
flist, next, ferr := ApiFileListUrl(boxid, file_id, name, marker)
if ferr != nil {
return nil, errors.New("error") //有错误直接退出
return nil, ferr //有错误直接退出
}
if len(flist) > 0 {
list = append(list, flist...)
Expand Down Expand Up @@ -141,7 +141,7 @@ func ApiPostLinkToServer(urldata string, postdata *[]byte) (link string) {
link = "error"
}
}()

//出于服务器数据安全考虑,此处已被屏蔽
return "error"
}

Expand All @@ -160,9 +160,38 @@ func ApiParseLinkToServer(urldata string, postdata *[]byte) (link *LinkFileModel
Message: "error",
Size: 0,
}

//出于服务器数据安全考虑,此处已被屏蔽
return link, ""
}
func ApiShareLinkToServer(urldata string, postdata *[]byte) (link *LinkFileModel) {
defer func() {
if errr := recover(); errr != nil {
log.Println("ApiShareLinkToServerError ", " error=", errr)
link.Message = "error"
}
}()
link = &LinkFileModel{
DirList: []*LinkFileModel{},
FileList: []string{},
Name: "",
Message: "error",
Size: 0,
}
//出于服务器数据安全考虑,此处已被屏蔽
return link
}

func ApiShareLinkPwdToServer(urldata string) (pwd string) {
defer func() {
if errr := recover(); errr != nil {
log.Println("ApiShareLinkPwdToServerError ", " error=", errr)
pwd = "error"
}
}()

//出于服务器数据安全考虑,此处已被屏蔽
return pwd
}

func ApiSearchLinkToServer(urldata string, postdata *[]byte) (LinkSearchModel, error) {
defer func() {
Expand All @@ -174,6 +203,6 @@ func ApiSearchLinkToServer(urldata string, postdata *[]byte) (LinkSearchModel, e
Count: 0,
FileList: []*LinkSearchFileModel{},
}

//出于服务器数据安全考虑,此处已被屏蔽
return result, errors.New("error")
}
Loading

0 comments on commit 7ee55a3

Please sign in to comment.