@soga/uploader 0.0.6 → 0.0.7
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.
|
@@ -19,6 +19,7 @@ export declare class Uploader {
|
|
|
19
19
|
stopAll(): Promise<void>;
|
|
20
20
|
stopFiles(ids: number[]): Promise<void>;
|
|
21
21
|
unpauseFiles(ids: number[]): Promise<void>;
|
|
22
|
+
unpauseAll(): Promise<void>;
|
|
22
23
|
repairFiles(ids: number[]): Promise<void>;
|
|
23
24
|
private startHost;
|
|
24
25
|
private startAli;
|
|
@@ -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(s){this.params=s,this.uid=s.uid,this.dataSource=s.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 startHosts({ali_host_id:s,baidu_host_id:t}){s&&await this.startHost(s,types_1.HostType.ALI),t&&await this.startHost(t,types_1.HostType.BAIDU)}async stopAll(){const s=this.processorMap.values();for(const t of s)await t.stopAll()}async stopFiles(s){const t=this.processorMap.values();for(const
|
|
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(s){this.params=s,this.uid=s.uid,this.dataSource=s.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 startHosts({ali_host_id:s,baidu_host_id:t}){s&&await this.startHost(s,types_1.HostType.ALI),t&&await this.startHost(t,types_1.HostType.BAIDU)}async stopAll(){const s=this.processorMap.values();for(const t of s)await t.stopAll()}async stopFiles(s){const t=this.processorMap.values();for(const a of t)await a.stopFiles(s)}async unpauseFiles(s){await this.partRepository.update({file_id:(0,typeorm_1.In)(s),is_paused:!0},{is_paused:!1}),await this.fileRepository.update({id:(0,typeorm_1.In)(s),is_paused:!0},{is_paused:!1});const t=this.processorMap.values();for(const s of t)await s.start()}async unpauseAll(){await this.partRepository.update({uid:this.uid,is_paused:!0},{is_paused:!1}),await this.fileRepository.update({uid:this.uid,is_paused:!0},{is_paused:!1});const s=this.processorMap.values();for(const t of s)await t.start()}async repairFiles(s){const t=this.processorMap.values();for(const a of t)await a.repairFiles(s)}async startHost(s,t){const a={uid:this.uid,dataSource:this.dataSource,unique:s,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(t==types_1.HostType.BAIDU){const t=await(0,baidu_1.getBaiduProcessor)({...a,getAccessToken:this.params.getBaiduAccessToken.bind(this)});this.processorMap.has(s)||this.processorMap.set(s,t),await t.start()}else if(t==types_1.HostType.ALI){const t=await(0,ali_1.getAliProcessor)({...a,getAccessToken:this.params.getAliAccessToken.bind(this)});this.processorMap.has(s)||this.processorMap.set(s,t),await t.start()}}async startAli(){const s=(await this.fileRepository.createQueryBuilder("file").select("DISTINCT file.ali_host_id").getRawMany()).map((s=>s.ali_host_id));if(s.length)for(const t of s)await this.startHost(t,types_1.HostType.ALI)}async startBaidu(){const s=(await this.fileRepository.createQueryBuilder("file").select("DISTINCT file.baidu_host_id").getRawMany()).map((s=>s.baidu_host_id));if(s.length)for(const t of s)await this.startHost(t,types_1.HostType.BAIDU)}}exports.Uploader=Uploader;
|