@@ -22,15 +22,15 @@ type FileUrlModel struct {
22
22
//文件相对路径
23
23
P_file_path string `json:"path"`
24
24
//P_url string `json:"url"`
25
- //P_domain_id string `json:"domain_id "`
25
+ P_drive_id string `json:"drive_id "`
26
26
//P_crc64_hash string `json:"crc64_hash"`
27
27
P_sha1 string `json:"sha1"`
28
28
P_size int64 `json:"size"`
29
29
IsUrl bool
30
30
IsDir bool
31
31
}
32
32
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 ) {
34
34
defer func () {
35
35
if errr := recover (); errr != nil {
36
36
log .Println ("ApiFileDownloadUrlError " , " error=" , errr )
@@ -39,7 +39,7 @@ func ApiFileDownloadUrl(file_id string, expire_sec int) (downurl string, size in
39
39
}()
40
40
var apiurl = "https://api.aliyundrive.com/v2/file/get_download_url"
41
41
42
- var postjson = map [string ]interface {}{"drive_id" : _user . UserToken . P_default_drive_id ,
42
+ var postjson = map [string ]interface {}{"drive_id" : boxid ,
43
43
"file_id" : file_id ,
44
44
"expire_sec" : expire_sec ,
45
45
}
@@ -61,15 +61,16 @@ func ApiFileDownloadUrl(file_id string, expire_sec int) (downurl string, size in
61
61
return "" , 0 , errors .New ("error" )
62
62
}
63
63
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
65
66
size = info .Get ("size" ).Int ()
66
67
return url , size , nil
67
68
}
68
69
69
70
//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 ) {
71
72
//https://api.aliyundrive.com/v2/file/get
72
- //{"drive_id":"8699982 ","file_id":"60a521893abc43ae8386480788b1016a214724ac"}
73
+ //{"drive_id":"9999999 ","file_id":"60a521893abc43ae8386480788b1016a214724ac"}
73
74
//download_url url 15分钟有效
74
75
defer func () {
75
76
if errr := recover (); errr != nil {
@@ -80,7 +81,7 @@ func ApiFileGetUrl(file_id string, parentpath string) (urlinfo FileUrlModel, err
80
81
81
82
var apiurl = "https://api.aliyundrive.com/v2/file/get"
82
83
83
- var postjson = map [string ]interface {}{"drive_id" : _user . UserToken . P_default_drive_id ,
84
+ var postjson = map [string ]interface {}{"drive_id" : boxid ,
84
85
"file_id" : file_id }
85
86
86
87
b , _ := json .Marshal (postjson )
@@ -120,17 +121,17 @@ func ApiFileGetUrl(file_id string, parentpath string) (urlinfo FileUrlModel, err
120
121
if info .Get ("thumbnail" ).Exists () && strings .Index (info .Get ("thumbnail" ).String (), "illegal_thumbnail" ) > 0 {
121
122
size = 9560 //违规视频大小
122
123
}
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
124
125
} 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
126
127
}
127
128
}
128
129
129
130
//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 ) {
131
132
for i := 0 ; i < 3 ; i ++ {
132
133
var list []* FileUrlModel
133
- list , err := _ApiFileListAllForDown (parentid , parentpath , isfull )
134
+ list , err := _ApiFileListAllForDown (boxid , parentid , parentpath , isfull )
134
135
if err == nil {
135
136
return list , nil
136
137
}
@@ -139,7 +140,7 @@ func ApiFileListAllForDown(parentid string, parentpath string, isfull bool) (lis
139
140
}
140
141
141
142
//_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 ) {
143
144
defer func () {
144
145
if errr := recover (); errr != nil {
145
146
log .Println ("_ApiFileListAllForDownError " , " error=" , errr )
@@ -148,7 +149,7 @@ func _ApiFileListAllForDown(parentid string, parentpath string, isfull bool) (li
148
149
}()
149
150
var marker = ""
150
151
for {
151
- flist , next , ferr := ApiFileListUrl (parentid , parentpath , marker )
152
+ flist , next , ferr := ApiFileListUrl (boxid , parentid , parentpath , marker )
152
153
if ferr != nil {
153
154
return nil , errors .New ("error" ) //有错误直接退出
154
155
}
@@ -169,7 +170,7 @@ func _ApiFileListAllForDown(parentid string, parentpath string, isfull bool) (li
169
170
if list [i ].IsDir {
170
171
wg .Add (1 )
171
172
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 )
173
174
//注意这里,如果子文件夹遍历时出错了,直接退出,确保要么全部成功,要么全部失败,不丢失
174
175
if rerr != nil {
175
176
errnum ++
@@ -191,10 +192,10 @@ func _ApiFileListAllForDown(parentid string, parentpath string, isfull bool) (li
191
192
}
192
193
193
194
//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 ) {
195
196
var apiurl = "https://api.aliyundrive.com/v2/file/list"
196
197
197
- var postjson = map [string ]interface {}{"drive_id" : _user . UserToken . P_default_drive_id ,
198
+ var postjson = map [string ]interface {}{"drive_id" : boxid ,
198
199
"parent_file_id" : parentid ,
199
200
"limit" : 100 ,
200
201
"all" : false ,
@@ -250,17 +251,17 @@ func ApiFileListUrl(parentid string, parentpath string, marker string) (list []*
250
251
size = 9560 //违规视频大小
251
252
}
252
253
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 })
254
255
} 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 })
256
257
}
257
258
}
258
259
259
260
return list , next_marker , nil
260
261
}
261
262
262
263
//ApiPlay 调用本地播放器
263
- func ApiPlay (file_id string ) string {
264
+ func ApiPlay (boxid string , file_id string ) string {
264
265
defer func () {
265
266
if errr := recover (); errr != nil {
266
267
log .Println ("ApiPlayError " , " error=" , errr )
@@ -282,7 +283,7 @@ func ApiPlay(file_id string) string {
282
283
mpvpath = "mpv"
283
284
}
284
285
285
- downurl , _ , err := ApiFileDownloadUrl (file_id , 60 * 60 * 4 )
286
+ downurl , _ , err := ApiFileDownloadUrl (boxid , file_id , 60 * 60 * 3 )
286
287
if err != nil {
287
288
return utils .ToErrorMessageJSON ("获取视频链接失败" )
288
289
}
@@ -296,7 +297,7 @@ func ApiPlay(file_id string) string {
296
297
}
297
298
298
299
//ApiImage 在线预览图片
299
- func ApiImage (file_id string ) string {
300
+ func ApiImage (boxid string , file_id string ) string {
300
301
defer func () {
301
302
if errr := recover (); errr != nil {
302
303
log .Println ("ApiImageError " , " error=" , errr )
@@ -305,7 +306,7 @@ func ApiImage(file_id string) string {
305
306
306
307
var apiurl = "https://api.aliyundrive.com/v2/file/get"
307
308
308
- var postjson = map [string ]interface {}{"drive_id" : _user . UserToken . P_default_drive_id ,
309
+ var postjson = map [string ]interface {}{"drive_id" : boxid ,
309
310
"file_id" : file_id }
310
311
311
312
b , _ := json .Marshal (postjson )
@@ -337,7 +338,7 @@ func ApiImage(file_id string) string {
337
338
}
338
339
339
340
//ApiText 在线预览文本
340
- func ApiText (file_id string ) string {
341
+ func ApiText (boxid string , file_id string ) string {
341
342
defer func () {
342
343
if errr := recover (); errr != nil {
343
344
log .Println ("ApiTextError " , " error=" , errr )
@@ -346,7 +347,7 @@ func ApiText(file_id string) string {
346
347
347
348
var apiurl = "https://api.aliyundrive.com/v2/file/get"
348
349
349
- var postjson = map [string ]interface {}{"drive_id" : _user . UserToken . P_default_drive_id ,
350
+ var postjson = map [string ]interface {}{"drive_id" : boxid ,
350
351
"file_id" : file_id }
351
352
352
353
b , _ := json .Marshal (postjson )
@@ -373,45 +374,50 @@ func ApiText(file_id string) string {
373
374
return utils .ToErrorMessageJSON ("获取文本链接失败" )
374
375
}
375
376
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 )
394
380
if err == nil {
395
381
bodybs = conbs
396
382
}
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 )
399
385
if err == nil {
400
386
bodybs = conbs
401
387
}
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
+ }
406
409
}
407
410
}
408
411
}
409
412
text := string (bodybs )
410
413
temp := []rune (text )
411
414
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 "
414
417
}
415
418
text = strings .ReplaceAll (text , " " , " " )
419
+ if text == "" {
420
+ text = "文件内容是空的"
421
+ }
416
422
return utils .ToSuccessJSON ("text" , text )
417
423
}
0 commit comments