@soga/part-uploader 0.2.33 → 0.2.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -13,23 +13,15 @@ export declare class AliHelper extends BaseUploader {
|
|
|
13
13
|
protected getExpiredAt(): number;
|
|
14
14
|
private initAxios;
|
|
15
15
|
protected init(): Promise<void>;
|
|
16
|
-
protected getUploadId(): Promise<
|
|
16
|
+
protected getUploadId(): Promise<any>;
|
|
17
17
|
protected cacheUploadId(upload_id: string): Promise<void>;
|
|
18
18
|
protected clearCache(): Promise<void>;
|
|
19
|
-
protected getFileId(): Promise<
|
|
19
|
+
protected getFileId(): Promise<any>;
|
|
20
20
|
protected cacheFileId(file_id: string): Promise<void>;
|
|
21
|
-
protected getPartInfoList(): Promise<
|
|
22
|
-
part_number: number;
|
|
23
|
-
upload_url: string;
|
|
24
|
-
expired_at: number;
|
|
25
|
-
}[]>;
|
|
21
|
+
protected getPartInfoList(): Promise<any>;
|
|
26
22
|
protected cachePartInfoList(part_info_list: {
|
|
27
23
|
part_number: number;
|
|
28
24
|
upload_url: string;
|
|
29
|
-
}[]): Promise<
|
|
30
|
-
part_number: number;
|
|
31
|
-
upload_url: string;
|
|
32
|
-
expired_at: number;
|
|
33
|
-
}[]>;
|
|
25
|
+
}[]): Promise<any>;
|
|
34
26
|
protected getProofCode(access_token: string): Promise<string>;
|
|
35
27
|
}
|
|
@@ -10,7 +10,7 @@ export declare class BaiduHelper extends BaseUploader {
|
|
|
10
10
|
protected init(): Promise<void>;
|
|
11
11
|
protected initMd5List(): Promise<void>;
|
|
12
12
|
protected getSearchParams(payload: Record<string, string>): string;
|
|
13
|
-
protected getUploadId(): Promise<
|
|
13
|
+
protected getUploadId(): Promise<any>;
|
|
14
14
|
protected cacheUploadId(upload_id: string): Promise<void>;
|
|
15
15
|
protected clearCache(): Promise<void>;
|
|
16
16
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.BaiduUploader=void 0;const form_data_1=__importDefault(require("form-data")),utils_1=require("@soga/utils"),baidu_helper_1=require("./baidu-helper"),axios_1=__importDefault(require("axios")),path_1=require("path"),types_1=require("@soga/types");class BaiduUploader extends baidu_helper_1.BaiduHelper{queue_list=[];get cloudPath(){return`${this.params.cloud_folder_path}/dpan_p_${this.params.part.md5}.bin`}async start(){await this.init();const t=await this.precreate();let a=t.data;return t.need_upload&&(await this.uploadChunks(),a=await this.postcreate()),await this.
|
|
1
|
+
"use strict";var __importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.BaiduUploader=void 0;const form_data_1=__importDefault(require("form-data")),utils_1=require("@soga/utils"),baidu_helper_1=require("./baidu-helper"),axios_1=__importDefault(require("axios")),path_1=require("path"),types_1=require("@soga/types");class BaiduUploader extends baidu_helper_1.BaiduHelper{queue_list=[];get cloudPath(){return`${this.params.cloud_folder_path}/dpan_p_${this.params.part.md5}.bin`}async start(){await this.init();const t=await this.precreate();let a=t.data;return t.need_upload&&(await this.uploadChunks(),a=await this.postcreate()),await this.postProgress({type:types_1.UploadProcessStep.upload_baidu,percent:1,host_type:types_1.HostType.BAIDU}),await this.clearCache(),a}async postcreate(){const t=await this.getUploadId(),a=this.cloudPath,e=this.md5_list,s=this.params.part.size,{access_token:i}=await this.sdk.getBaiduHostAuthData({host_id:this.params.host_id,refresh:!1}),r=`https://pan.baidu.com/rest/2.0/xpan/file?method=create&access_token=${i}`,o=this.getSearchParams({path:a,size:`${s}`,isdir:"0",block_list:JSON.stringify(e),uploadid:t||void 0,rtype:"2"}),d=await axios_1.default.post(r,o);if(!d)return;const{data:p}=d;if(!p.errno)return{fs_id:p.fs_id};{const t=`upload create file error: ${p.errno}`;await this.throwError({code:15300,message:t,stack:JSON.stringify(p)})}}async uploadChunks(){const t=this.queue_list.map((t=>t)),a=async()=>{if(t.length){const e=t.shift(),s=await this.getChunkInfo(e);await this.uploadOneChunk(s);const i=Math.min((e+1)*this.chunk_size,this.params.part.size)/this.params.part.size;await this.postProgress({type:types_1.UploadProcessStep.upload_baidu,percent:.98*i,host_type:types_1.HostType.BAIDU}),await a()}};await a()}async precreate(){const t=this.md5_list,{md4:a,md5:e,size:s}=this.params.part,{access_token:i}=await this.sdk.getBaiduHostAuthData({host_id:this.params.host_id,refresh:!1}),r=await this.getUploadId(),o=`https://pan.baidu.com/rest/2.0/xpan/file?method=precreate&access_token=${i}`,d=this.getSearchParams({path:this.cloudPath,size:`${s}`,isdir:"0",block_list:JSON.stringify(t),autoinit:"1",rtype:"2","content-md5":e,"slice-md5":a,uploadid:r}),p=await axios_1.default.post(o,d,{headers:{"User-Agent":this.params.ua}});if(!p)return;const{data:h}=p;if(!h.errno)return 1==h.return_type?(h.uploadid&&h.uploadid!=r&&await this.cacheUploadId(h.uploadid),this.queue_list=h.block_list,{need_upload:!0}):{need_upload:!1,data:{fs_id:h.info.fs_id}};{const t=`precreate error: ${h.errno}`;await this.throwError({code:15100,message:t,stack:JSON.stringify(h)})}}async uploadOneChunk(t){const a=await this.getUploadId(),e=this.cloudPath,{access_token:s}=await this.sdk.getBaiduHostAuthData({host_id:this.params.host_id,refresh:!1}),i=`https://d.pcs.baidu.com/rest/2.0/pcs/superfile2?access_token=${s}&method=upload&type=tmpfile&path=${e}&uploadid=${a}&partseq=${t.index}`,r=new form_data_1.default;r.append("file",t.buffer,`${t.filename}`);const o=await axios_1.default.post(i,r,{timeout:6e4});if(o)return o.data.md5}async getChunkInfo(t){const a=this.group_list[t],e=this.params.part.path,s=await(0,utils_1.getFileBufferSlice)(e,a.start,a.end),{md5_list:i}=this;return{index:t,buffer:s,md5:i[t],filename:(0,path_1.parse)(e).base,size:s.byteLength}}}exports.BaiduUploader=BaiduUploader;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soga/part-uploader",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.48",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -25,14 +25,14 @@
|
|
|
25
25
|
"@types/fs-extra": "^11.0.4",
|
|
26
26
|
"@types/glob": "^8.1.0",
|
|
27
27
|
"@types/jest": "^29.5.14",
|
|
28
|
-
"@types/node": "^
|
|
29
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
30
|
-
"@typescript-eslint/parser": "^
|
|
31
|
-
"eslint": "^
|
|
32
|
-
"eslint-config-prettier": "^
|
|
33
|
-
"eslint-plugin-jest": "^
|
|
28
|
+
"@types/node": "^22.15.29",
|
|
29
|
+
"@typescript-eslint/eslint-plugin": "^8.33.0",
|
|
30
|
+
"@typescript-eslint/parser": "^8.33.0",
|
|
31
|
+
"eslint": "^9.28.0",
|
|
32
|
+
"eslint-config-prettier": "^10.1.5",
|
|
33
|
+
"eslint-plugin-jest": "^28.12.0",
|
|
34
34
|
"eslint-plugin-prettier": "^5.2.3",
|
|
35
|
-
"glob": "^
|
|
35
|
+
"glob": "^11.0.2",
|
|
36
36
|
"jest": "^29.7.0",
|
|
37
37
|
"prettier": "^3.0.2",
|
|
38
38
|
"rimraf": "^6.0.1",
|
|
@@ -45,13 +45,13 @@
|
|
|
45
45
|
"author": "",
|
|
46
46
|
"license": "ISC",
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@soga/bridge": "^0.2.
|
|
49
|
-
"@soga/sdk": "^0.2.
|
|
50
|
-
"@soga/types": "^0.2.
|
|
51
|
-
"@soga/utils": "^0.2.
|
|
48
|
+
"@soga/bridge": "^0.2.48",
|
|
49
|
+
"@soga/sdk": "^0.2.48",
|
|
50
|
+
"@soga/types": "^0.2.48",
|
|
51
|
+
"@soga/utils": "^0.2.48",
|
|
52
52
|
"axios": "^1.7.9",
|
|
53
53
|
"form-data": "^4.0.2",
|
|
54
54
|
"fs-extra": "^11.2.0"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "e43283e6c50e52cc9823197eed3efc72d4c43af5"
|
|
57
57
|
}
|