@soga/part-uploader 0.2.33 → 0.2.44
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.
|
@@ -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.44",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -53,5 +53,5 @@
|
|
|
53
53
|
"form-data": "^4.0.2",
|
|
54
54
|
"fs-extra": "^11.2.0"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "e23f4953ec0493ea57b00256ae012fb38d9b64c2"
|
|
57
57
|
}
|