@soga/uploader 0.0.18 → 0.0.19
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.
|
@@ -9,7 +9,7 @@ export declare class Uploader {
|
|
|
9
9
|
protected fileRepository: Repository<UploadFile>;
|
|
10
10
|
protected partRepository: Repository<UploadPart>;
|
|
11
11
|
constructor(params: UploaderParams);
|
|
12
|
-
protected processorMap: Map<
|
|
12
|
+
protected processorMap: Map<string, BaseProcessor>;
|
|
13
13
|
init(): Promise<void>;
|
|
14
14
|
start(): Promise<void>;
|
|
15
15
|
stopAll(change_db?: boolean): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Uploader=void 0;const types_1=require("@soga/types"),typeorm_1=require("typeorm"),entities_1=require("@soga/entities"),baidu_1=require("../processor/baidu"),ali_1=require("../processor/ali");class Uploader{params;uid;dataSource;fileRepository;partRepository;constructor(t){this.params=t,this.uid=t.uid,this.dataSource=t.dataSource,this.fileRepository=this.dataSource.getRepository(entities_1.UploadFile),this.partRepository=this.dataSource.getRepository(entities_1.UploadPart)}processorMap=new Map;async init(){}async start(){await Promise.all([this.startAli(),this.startBaidu()])}async stopAll(t=!1){const s=this.processorMap.values();for(const a of s)await a.stopAll(t)}async stopFiles(t,s=!1){const a=this.processorMap.values();for(const i of a)await i.stopFiles(t,s)}async repairAllParts(){await Promise.all([this.partRepository.update({uid:this.uid,baidu_status:types_1.UploadStatus.ERROR},{baidu_status:types_1.UploadStatus.NULL}),this.partRepository.update({uid:this.uid,ali_status:types_1.UploadStatus.ERROR},{ali_status:types_1.UploadStatus.NULL})])}async repairParts(t){await Promise.all([this.partRepository.update({file_id:(0,typeorm_1.In)(t),baidu_status:types_1.UploadStatus.ERROR},{baidu_status:types_1.UploadStatus.NULL}),this.partRepository.update({file_id:(0,typeorm_1.In)(t),ali_status:types_1.UploadStatus.ERROR},{ali_status:types_1.UploadStatus.NULL})])}async startHost(t,s){if(this.processorMap.has(
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Uploader=void 0;const types_1=require("@soga/types"),typeorm_1=require("typeorm"),entities_1=require("@soga/entities"),baidu_1=require("../processor/baidu"),ali_1=require("../processor/ali");class Uploader{params;uid;dataSource;fileRepository;partRepository;constructor(t){this.params=t,this.uid=t.uid,this.dataSource=t.dataSource,this.fileRepository=this.dataSource.getRepository(entities_1.UploadFile),this.partRepository=this.dataSource.getRepository(entities_1.UploadPart)}processorMap=new Map;async init(){}async start(){await Promise.all([this.startAli(),this.startBaidu()])}async stopAll(t=!1){const s=this.processorMap.values();for(const a of s)await a.stopAll(t)}async stopFiles(t,s=!1){const a=this.processorMap.values();for(const i of a)await i.stopFiles(t,s)}async repairAllParts(){await Promise.all([this.partRepository.update({uid:this.uid,baidu_status:types_1.UploadStatus.ERROR},{baidu_status:types_1.UploadStatus.NULL}),this.partRepository.update({uid:this.uid,ali_status:types_1.UploadStatus.ERROR},{ali_status:types_1.UploadStatus.NULL})])}async repairParts(t){await Promise.all([this.partRepository.update({file_id:(0,typeorm_1.In)(t),baidu_status:types_1.UploadStatus.ERROR},{baidu_status:types_1.UploadStatus.NULL}),this.partRepository.update({file_id:(0,typeorm_1.In)(t),ali_status:types_1.UploadStatus.ERROR},{ali_status:types_1.UploadStatus.NULL})])}async startHost(t,s){const a=`${s}_${t}`;if(this.processorMap.has(a)){const t=this.processorMap.get(a);return void await t.start()}const i={uid:this.uid,dataSource:this.dataSource,unique:t,createCloudRecord:this.params.createCloudRecord.bind(this),onProgress:this.params.onProgress?.bind(this),onSuccess:this.params.onSuccess?.bind(this),onError:this.params.onError?.bind(this)};if(s==types_1.HostType.BAIDU){const t=await(0,baidu_1.getBaiduProcessor)({...i,getAccessToken:this.params.getBaiduAccessToken.bind(this)});this.processorMap.set(a,t),await t.start()}else if(s==types_1.HostType.ALI){const t=await(0,ali_1.getAliProcessor)({...i,getAccessToken:this.params.getAliAccessToken.bind(this)});this.processorMap.set(a,t),await t.start()}}async startAli(){const t=(await this.fileRepository.createQueryBuilder("file").select("DISTINCT file.ali_host_id").where("file.uid = :uid",{uid:this.uid}).getRawMany()).map((t=>t.ali_host_id));if(t.length)for(const s of t)await this.startHost(s,types_1.HostType.ALI)}async startBaidu(){const t=(await this.fileRepository.createQueryBuilder("file").select("DISTINCT file.baidu_host_id").where("file.uid = :uid",{uid:this.uid}).getRawMany()).map((t=>t.baidu_host_id));if(t.length)for(const s of t)await this.startHost(s,types_1.HostType.BAIDU)}}exports.Uploader=Uploader;
|