@soga/part-uploader 0.2.8 → 0.2.15

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,4 +1,5 @@
1
1
  import { FilePartItem } from '@soga/types';
2
+ import { MessagePort } from 'node:worker_threads';
2
3
  export type CommonPartUploaderParams = {
3
4
  file_id: number;
4
5
  host_id: number;
@@ -6,6 +7,7 @@ export type CommonPartUploaderParams = {
6
7
  output_root: string;
7
8
  part: FilePartItem;
8
9
  sdk_domain: string;
10
+ port?: MessagePort;
9
11
  };
10
12
  export type UploadBaiduParams = CommonPartUploaderParams & {
11
13
  cloud_folder_path: string;
@@ -3,8 +3,10 @@ import { CommonPartUploaderParams } from '../types/main';
3
3
  import { HostType, UploadProcessStep, UploadWorkerMessage } from '@soga/types';
4
4
  import { Sdk } from '@soga/sdk';
5
5
  import { CompleteGroupList } from '../utils/chunk';
6
+ import { MessagePort } from 'node:worker_threads';
6
7
  type LevelDataType = string | number | boolean | object | null;
7
8
  export declare class BaseUploader {
9
+ protected port: MessagePort | null;
8
10
  protected GROUP_LIST_KEY: string;
9
11
  protected chunk_size: number;
10
12
  protected group_list: CompleteGroupList;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.BaseUploader=void 0;const utils_1=require("@soga/utils"),level_1=require("level"),path_1=require("path"),sdk_1=require("@soga/sdk"),worker_threads_1=require("worker_threads"),chunk_1=require("../utils/chunk");class BaseUploader{GROUP_LIST_KEY="group_list";chunk_size=4194304;group_list=[];host_type;controller=new AbortController;is_stop=!1;db;sdk;baseParams;constructor(s,t){this.host_type=t,this.baseParams=s}async init(){this.initLevel(),this.sdk=(0,sdk_1.getSdk)(this.baseParams.sdk_domain),await this.initGroupList()}async initGroupList(){const s=await this.db.get(this.GROUP_LIST_KEY);if(s)return void(this.group_list=s);const t=(0,chunk_1.groupChunk)(this.baseParams.part,this.chunk_size);this.group_list=t,await this.db.put(this.GROUP_LIST_KEY,t)}initLevel(){const s=`upload_part_${this.host_type}_${this.baseParams.part_id}`,t=(0,path_1.resolve)(this.baseParams.output_root,s),e=new level_1.Level(t,{valueEncoding:"json"});this.db=e}async throwError(s){throw new utils_1.SimpleError(s)}async postProgress(s){await this.postMessage({id:this.baseParams.file_id,type:"percent",data:{part_id:this.baseParams.part_id,host_type:this.host_type,percent:s.percent}})}async postMessage(s){worker_threads_1.parentPort&&worker_threads_1.parentPort.postMessage(s)}}exports.BaseUploader=BaseUploader;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.BaseUploader=void 0;const utils_1=require("@soga/utils"),level_1=require("level"),path_1=require("path"),sdk_1=require("@soga/sdk"),chunk_1=require("../utils/chunk");class BaseUploader{port=null;GROUP_LIST_KEY="group_list";chunk_size=4194304;group_list=[];host_type;controller=new AbortController;is_stop=!1;db;sdk;baseParams;constructor(s,t){this.host_type=t,this.baseParams=s,this.port=s.port??null}async init(){this.initLevel(),this.sdk=(0,sdk_1.getSdk)(this.baseParams.sdk_domain),await this.initGroupList()}async initGroupList(){const s=await this.db.get(this.GROUP_LIST_KEY);if(s)return void(this.group_list=s);const t=(0,chunk_1.groupChunk)(this.baseParams.part,this.chunk_size);this.group_list=t,await this.db.put(this.GROUP_LIST_KEY,t)}initLevel(){const s=`upload_part_${this.host_type}_${this.baseParams.part_id}`,t=(0,path_1.resolve)(this.baseParams.output_root,s),e=new level_1.Level(t,{valueEncoding:"json"});this.db=e}async throwError(s){throw new utils_1.SimpleError(s)}async postProgress(s){await this.postMessage({id:this.baseParams.file_id,type:"percent",data:{part_id:this.baseParams.part_id,host_type:this.host_type,percent:s.percent}})}async postMessage(s){this.port&&this.port.postMessage(s)}}exports.BaseUploader=BaseUploader;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soga/part-uploader",
3
- "version": "0.2.8",
3
+ "version": "0.2.15",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -55,5 +55,5 @@
55
55
  "peerDependencies": {
56
56
  "level": "*"
57
57
  },
58
- "gitHead": "2f239908854aa1f8ad224b83316d0c33c20feea1"
58
+ "gitHead": "2592173a0ca38f6ff55cbbc8e29d7b1ac4bb4072"
59
59
  }