Skip to content

Commit 647fab1

Browse files
committed
v1.6.21
1 parent a7ffb77 commit 647fab1

File tree

118 files changed

+7988
-3571
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+7988
-3571
lines changed

aliserver/aliyun/ApiFile.go

+233-52
Large diffs are not rendered by default.

aliserver/aliyun/ApiFileDown.go

+56-50
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ type FileUrlModel struct {
2222
//文件相对路径
2323
P_file_path string `json:"path"`
2424
//P_url string `json:"url"`
25-
//P_domain_id string `json:"domain_id"`
25+
P_drive_id string `json:"drive_id"`
2626
//P_crc64_hash string `json:"crc64_hash"`
2727
P_sha1 string `json:"sha1"`
2828
P_size int64 `json:"size"`
2929
IsUrl bool
3030
IsDir bool
3131
}
3232

33-
func ApiFileDownloadUrl(file_id string, expire_sec int) (downurl string, size int64, err error) {
33+
func ApiFileDownloadUrl(boxid string, file_id string, expire_sec int) (downurl string, size int64, err error) {
3434
defer func() {
3535
if errr := recover(); errr != nil {
3636
log.Println("ApiFileDownloadUrlError ", " error=", errr)
@@ -39,7 +39,7 @@ func ApiFileDownloadUrl(file_id string, expire_sec int) (downurl string, size in
3939
}()
4040
var apiurl = "https://api.aliyundrive.com/v2/file/get_download_url"
4141

42-
var postjson = map[string]interface{}{"drive_id": _user.UserToken.P_default_drive_id,
42+
var postjson = map[string]interface{}{"drive_id": boxid,
4343
"file_id": file_id,
4444
"expire_sec": expire_sec,
4545
}
@@ -61,15 +61,16 @@ func ApiFileDownloadUrl(file_id string, expire_sec int) (downurl string, size in
6161
return "", 0, errors.New("error")
6262
}
6363
info := gjson.Parse(body)
64-
url := info.Get("url").String()
64+
//url := info.Get("internal_url").String() //internal_url url
65+
url := info.Get("url").String() //internal_url url
6566
size = info.Get("size").Int()
6667
return url, size, nil
6768
}
6869

6970
//ApiFileGetUrl 读取一个文件的信息
70-
func ApiFileGetUrl(file_id string, parentpath string) (urlinfo FileUrlModel, err error) {
71+
func ApiFileGetUrl(boxid string, file_id string, parentpath string) (urlinfo FileUrlModel, err error) {
7172
//https://api.aliyundrive.com/v2/file/get
72-
//{"drive_id":"8699982","file_id":"60a521893abc43ae8386480788b1016a214724ac"}
73+
//{"drive_id":"9999999","file_id":"60a521893abc43ae8386480788b1016a214724ac"}
7374
//download_url url 15分钟有效
7475
defer func() {
7576
if errr := recover(); errr != nil {
@@ -80,7 +81,7 @@ func ApiFileGetUrl(file_id string, parentpath string) (urlinfo FileUrlModel, err
8081

8182
var apiurl = "https://api.aliyundrive.com/v2/file/get"
8283

83-
var postjson = map[string]interface{}{"drive_id": _user.UserToken.P_default_drive_id,
84+
var postjson = map[string]interface{}{"drive_id": boxid,
8485
"file_id": file_id}
8586

8687
b, _ := json.Marshal(postjson)
@@ -120,17 +121,17 @@ func ApiFileGetUrl(file_id string, parentpath string) (urlinfo FileUrlModel, err
120121
if info.Get("thumbnail").Exists() && strings.Index(info.Get("thumbnail").String(), "illegal_thumbnail") > 0 {
121122
size = 9560 //违规视频大小
122123
}
123-
return FileUrlModel{P_file_id: file_id, P_file_path: parentpath, P_file_name: name, P_sha1: content_hash, P_size: size, IsUrl: true, IsDir: false}, nil
124+
return FileUrlModel{P_drive_id: boxid, P_file_id: file_id, P_file_path: parentpath, P_file_name: name, P_sha1: content_hash, P_size: size, IsUrl: true, IsDir: false}, nil
124125
} else {
125-
return FileUrlModel{P_file_id: file_id, P_file_path: parentpath, P_file_name: name, IsUrl: false, IsDir: true}, nil
126+
return FileUrlModel{P_drive_id: boxid, P_file_id: file_id, P_file_path: parentpath, P_file_name: name, IsUrl: false, IsDir: true}, nil
126127
}
127128
}
128129

129130
//ApiFileListAllForDown 读取一个文件夹包含的文件列表 isfull==true时遍历所有子文件夹
130-
func ApiFileListAllForDown(parentid string, parentpath string, isfull bool) (list []*FileUrlModel, err error) {
131+
func ApiFileListAllForDown(boxid string, parentid string, parentpath string, isfull bool) (list []*FileUrlModel, err error) {
131132
for i := 0; i < 3; i++ {
132133
var list []*FileUrlModel
133-
list, err := _ApiFileListAllForDown(parentid, parentpath, isfull)
134+
list, err := _ApiFileListAllForDown(boxid, parentid, parentpath, isfull)
134135
if err == nil {
135136
return list, nil
136137
}
@@ -139,7 +140,7 @@ func ApiFileListAllForDown(parentid string, parentpath string, isfull bool) (lis
139140
}
140141

141142
//_ApiFileListAllForDown 读取一个文件夹包含的文件列表 isfull==true时遍历所有子文件夹
142-
func _ApiFileListAllForDown(parentid string, parentpath string, isfull bool) (list []*FileUrlModel, err error) {
143+
func _ApiFileListAllForDown(boxid string, parentid string, parentpath string, isfull bool) (list []*FileUrlModel, err error) {
143144
defer func() {
144145
if errr := recover(); errr != nil {
145146
log.Println("_ApiFileListAllForDownError ", " error=", errr)
@@ -148,7 +149,7 @@ func _ApiFileListAllForDown(parentid string, parentpath string, isfull bool) (li
148149
}()
149150
var marker = ""
150151
for {
151-
flist, next, ferr := ApiFileListUrl(parentid, parentpath, marker)
152+
flist, next, ferr := ApiFileListUrl(boxid, parentid, parentpath, marker)
152153
if ferr != nil {
153154
return nil, errors.New("error") //有错误直接退出
154155
}
@@ -169,7 +170,7 @@ func _ApiFileListAllForDown(parentid string, parentpath string, isfull bool) (li
169170
if list[i].IsDir {
170171
wg.Add(1)
171172
go func(i int) {
172-
rlist, rerr := ApiFileListAllForDown(list[i].P_file_id, list[i].P_file_path+"/"+list[i].P_file_name, true)
173+
rlist, rerr := ApiFileListAllForDown(boxid, list[i].P_file_id, list[i].P_file_path+"/"+list[i].P_file_name, true)
173174
//注意这里,如果子文件夹遍历时出错了,直接退出,确保要么全部成功,要么全部失败,不丢失
174175
if rerr != nil {
175176
errnum++
@@ -191,10 +192,10 @@ func _ApiFileListAllForDown(parentid string, parentpath string, isfull bool) (li
191192
}
192193

193194
//ApiFileListUrl 真的读取子文件列表,不能有catch,出错要直接崩溃,上级调用会catch
194-
func ApiFileListUrl(parentid string, parentpath string, marker string) (list []*FileUrlModel, next_marker string, err error) {
195+
func ApiFileListUrl(boxid string, parentid string, parentpath string, marker string) (list []*FileUrlModel, next_marker string, err error) {
195196
var apiurl = "https://api.aliyundrive.com/v2/file/list"
196197

197-
var postjson = map[string]interface{}{"drive_id": _user.UserToken.P_default_drive_id,
198+
var postjson = map[string]interface{}{"drive_id": boxid,
198199
"parent_file_id": parentid,
199200
"limit": 100,
200201
"all": false,
@@ -250,17 +251,17 @@ func ApiFileListUrl(parentid string, parentpath string, marker string) (list []*
250251
size = 9560 //违规视频大小
251252
}
252253

253-
list = append(list, &FileUrlModel{P_file_id: file_id, P_file_path: parentpath, P_file_name: name, P_sha1: content_hash, P_size: size, IsUrl: true, IsDir: false})
254+
list = append(list, &FileUrlModel{P_drive_id: boxid, P_file_id: file_id, P_file_path: parentpath, P_file_name: name, P_sha1: content_hash, P_size: size, IsUrl: true, IsDir: false})
254255
} else {
255-
list = append(list, &FileUrlModel{P_file_id: file_id, P_file_path: parentpath, P_file_name: name, IsUrl: false, IsDir: true})
256+
list = append(list, &FileUrlModel{P_drive_id: boxid, P_file_id: file_id, P_file_path: parentpath, P_file_name: name, IsUrl: false, IsDir: true})
256257
}
257258
}
258259

259260
return list, next_marker, nil
260261
}
261262

262263
//ApiPlay 调用本地播放器
263-
func ApiPlay(file_id string) string {
264+
func ApiPlay(boxid string, file_id string) string {
264265
defer func() {
265266
if errr := recover(); errr != nil {
266267
log.Println("ApiPlayError ", " error=", errr)
@@ -282,7 +283,7 @@ func ApiPlay(file_id string) string {
282283
mpvpath = "mpv"
283284
}
284285

285-
downurl, _, err := ApiFileDownloadUrl(file_id, 60*60*4)
286+
downurl, _, err := ApiFileDownloadUrl(boxid, file_id, 60*60*3)
286287
if err != nil {
287288
return utils.ToErrorMessageJSON("获取视频链接失败")
288289
}
@@ -296,7 +297,7 @@ func ApiPlay(file_id string) string {
296297
}
297298

298299
//ApiImage 在线预览图片
299-
func ApiImage(file_id string) string {
300+
func ApiImage(boxid string, file_id string) string {
300301
defer func() {
301302
if errr := recover(); errr != nil {
302303
log.Println("ApiImageError ", " error=", errr)
@@ -305,7 +306,7 @@ func ApiImage(file_id string) string {
305306

306307
var apiurl = "https://api.aliyundrive.com/v2/file/get"
307308

308-
var postjson = map[string]interface{}{"drive_id": _user.UserToken.P_default_drive_id,
309+
var postjson = map[string]interface{}{"drive_id": boxid,
309310
"file_id": file_id}
310311

311312
b, _ := json.Marshal(postjson)
@@ -337,7 +338,7 @@ func ApiImage(file_id string) string {
337338
}
338339

339340
//ApiText 在线预览文本
340-
func ApiText(file_id string) string {
341+
func ApiText(boxid string, file_id string) string {
341342
defer func() {
342343
if errr := recover(); errr != nil {
343344
log.Println("ApiTextError ", " error=", errr)
@@ -346,7 +347,7 @@ func ApiText(file_id string) string {
346347

347348
var apiurl = "https://api.aliyundrive.com/v2/file/get"
348349

349-
var postjson = map[string]interface{}{"drive_id": _user.UserToken.P_default_drive_id,
350+
var postjson = map[string]interface{}{"drive_id": boxid,
350351
"file_id": file_id}
351352

352353
b, _ := json.Marshal(postjson)
@@ -373,45 +374,50 @@ func ApiText(file_id string) string {
373374
return utils.ToErrorMessageJSON("获取文本链接失败")
374375
}
375376
bodybs := *bodybs1
376-
if bodybs[0] == 0xFF && bodybs[1] == 0xFE {
377-
conbs, err := utils.UTF16LEToUtf8(bodybs)
378-
if err == nil {
379-
bodybs = conbs
380-
}
381-
} else if bodybs[0] == 0xFE && bodybs[1] == 0xFF {
382-
conbs, err := utils.UTF16BEToUtf8(bodybs)
383-
if err == nil {
384-
bodybs = conbs
385-
}
386-
} else if bodybs[0] == 0xEF && bodybs[1] == 0xBB && bodybs[2] == 0xBF {
387-
//utf8
388-
} else {
389-
plist := chardet.Possible(bodybs)
390-
if utils.IsContain(plist, "utf-8") {
391-
//utf8
392-
} else if utils.IsContain(plist, "gb18030") {
393-
conbs, err := utils.GB18030ToUtf8(bodybs)
377+
if len(bodybs) > 0 {
378+
if bodybs[0] == 0xFF && bodybs[1] == 0xFE {
379+
conbs, err := utils.UTF16LEToUtf8(bodybs)
394380
if err == nil {
395381
bodybs = conbs
396382
}
397-
} else if utils.IsContain(plist, "gbk") {
398-
conbs, err := utils.GbkToUtf8(bodybs)
383+
} else if bodybs[0] == 0xFE && bodybs[1] == 0xFF {
384+
conbs, err := utils.UTF16BEToUtf8(bodybs)
399385
if err == nil {
400386
bodybs = conbs
401387
}
402-
} else if utils.IsContain(plist, "big5") {
403-
conbs, err := utils.Big5ToUtf8(bodybs)
404-
if err == nil {
405-
bodybs = conbs
388+
} else if bodybs[0] == 0xEF && bodybs[1] == 0xBB && bodybs[2] == 0xBF {
389+
//utf8
390+
} else {
391+
plist := chardet.Possible(bodybs)
392+
if utils.IsContain(plist, "utf-8") {
393+
//utf8
394+
} else if utils.IsContain(plist, "gb18030") {
395+
conbs, err := utils.GB18030ToUtf8(bodybs)
396+
if err == nil {
397+
bodybs = conbs
398+
}
399+
} else if utils.IsContain(plist, "gbk") {
400+
conbs, err := utils.GbkToUtf8(bodybs)
401+
if err == nil {
402+
bodybs = conbs
403+
}
404+
} else if utils.IsContain(plist, "big5") {
405+
conbs, err := utils.Big5ToUtf8(bodybs)
406+
if err == nil {
407+
bodybs = conbs
408+
}
406409
}
407410
}
408411
}
409412
text := string(bodybs)
410413
temp := []rune(text)
411414
length4 := len(temp)
412-
if length4 > 20480 { //1万字
413-
text = string(temp[0:20480]) + "\n\n\n\n剩余" + strconv.FormatInt(int64(length4-20480), 10) + "字被省略.....\n\n\n\n"
415+
if length4 > 1024*100 { //1万字
416+
text = string(temp[0:1024*100]) + "\n\n\n\n剩余" + strconv.FormatInt(int64(length4-1024*100), 10) + "字被省略.....\n\n\n\n"
414417
}
415418
text = strings.ReplaceAll(text, " ", " ")
419+
if text == "" {
420+
text = "文件内容是空的"
421+
}
416422
return utils.ToSuccessJSON("text", text)
417423
}

0 commit comments

Comments
 (0)