Skip to content

Commit e0c2426

Browse files
authored
Bump to v7.13.0 (#436)
1 parent d71615f commit e0c2426

21 files changed

+2048
-431
lines changed

CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
## CHANGE LOG
22

3+
## 7.13.0
4+
- 对象存储,新增空间级别上传加速开关
5+
- 对象存储,优化断点续传开启方式
6+
- 对象存储,优化回调签名验证函数,新增兼容 Qiniu 签名
7+
- 对象存储,修复上传失败无法完成自动重试
8+
- 在 Node.js 18 及以上触发
9+
- 7.12.0 引入
10+
- 对象存储,新增空间的创建、删除、按标签列举
11+
- 对象存储,调整查询区域主备域名
12+
- 修复内部 HttpClient 部分方法参数类型声明不正确
13+
314
## 7.12.0
415
- 对象存储,新增支持 Promise 风格异步
516
- 对象存储,修复分片上传 v1 在特定条件可能无法从断点继续上传

index.d.ts

+108-13
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,14 @@ export declare namespace conf {
148148
useHttpsDomain?: boolean;
149149

150150
/**
151+
* 在使用前需要提前开通加速域名
152+
* 详见:https://developer.qiniu.com/kodo/12656/transfer-acceleration
153+
* @default false
154+
*/
155+
accelerateUploading?: boolean;
156+
157+
/**
158+
* @deprecated 实际已无加速上传能力,使用 accelerateUploading 代替
151159
* @default true
152160
*/
153161
useCdnDomain?: boolean;
@@ -181,10 +189,15 @@ export declare namespace conf {
181189
}
182190
class Config {
183191
useHttpsDomain: boolean;
192+
accelerateUploading: boolean;
193+
/**
194+
* @deprecated 实际已无加速上传能力,使用 accelerateUploading 代替
195+
*/
184196
useCdnDomain: boolean;
185197
ucEndpointsProvider?: httpc.EndpointsProvider | null;
186198
queryRegionsEndpointsProvider?: httpc.EndpointsProvider | null;
187199
regionsProvider?: httpc.RegionsProvider | null;
200+
regionsQueryResultCachePath?: string | null;
188201
zone?: Zone | null;
189202
zoneExpire?: number;
190203

@@ -337,7 +350,7 @@ export declare namespace form_up {
337350
export declare namespace resume_up {
338351
type UploadResult = {
339352
data: any;
340-
resp: IncomingMessage;
353+
resp: Omit<IncomingMessage, 'url'> & { requestUrls: string[] };
341354
}
342355

343356
class ResumeUploader {
@@ -412,13 +425,14 @@ export declare namespace resume_up {
412425

413426
/**
414427
* @default null
428+
* @deprecated 使用 `resumeRecorder` 与 `resumeKey` 代替
415429
*/
416-
resumeRecordFile?: string
430+
resumeRecordFile?: string | null
417431

418432
/**
419433
* @default null
420434
*/
421-
progressCallback?: (uploadBytes: number, totalBytes: number) => void
435+
progressCallback?: ((uploadBytes: number, totalBytes: number) => void) | null
422436

423437
/**
424438
* @default v1
@@ -435,6 +449,18 @@ export declare namespace resume_up {
435449
*/
436450
metadata?: Record<string, string>
437451

452+
/**
453+
* 断点续传记录器,请通过 `createResumeRecorder` 或 `createResumeRecorderSync` 获取,优先级比 `resumeRecordFile` 低
454+
* @default null
455+
*/
456+
resumeRecorder?: ResumeRecorder
457+
458+
/**
459+
* 断点续传记录文件的具体文件名,不设置时会由当次上传自动生成
460+
* @default null
461+
*/
462+
resumeKey?: string | null
463+
438464
/**
439465
* 上传可选参数
440466
* @param fname 请求体中的文件的名称
@@ -445,11 +471,32 @@ export declare namespace resume_up {
445471
* @param partSize 分片上传v2必传字段 默认大小为4MB 分片大小范围为1 MB - 1 GB
446472
* @param version 分片上传版本 目前支持v1/v2版本 默认v1
447473
* @param metadata 元数据设置,参数名称必须以 x-qn-meta-${name}: 开头
474+
* @param resumeRecorder 断点续传记录器,请通过 `createResumeRecorder` 或 `createResumeRecorderSync` 获取,优先级比 `resumeRecordFile` 低
475+
* @param resumeKey 断点续传记录文件的具体文件名,不设置时会由当次上传自动生成,推荐不设置
448476
*/
449477
constructor(fname?: string, params?: Record<string, string>, mimeType?: string, resumeRecordFile?: string,
450478
progressCallback?: (uploadBytes: number, totalBytes: number) => void,
451-
partSize?:number, version?:string, metadata?: Record<string, string>);
479+
partSize?:number, version?:string, metadata?: Record<string, string>,
480+
resumeRecorder?: ResumeRecorder, resumeKey?: string);
481+
}
482+
483+
/**
484+
* 历史原因其方法当前仅支持了同步调用这一不推荐的使用方式,暂不公开具体内部信息,仅供 TypeScript 类型检查使用。
485+
* 实际不存在这个类,未来会变更为 interface。
486+
*/
487+
abstract class ResumeRecorder {
452488
}
489+
490+
/**
491+
*
492+
* @param baseDirPath 默认值为 `os.tmpdir()`,该方法若 baseDirPath 不存在将自动创建
493+
*/
494+
function createResumeRecorder (baseDirPath?: string): Promise<ResumeRecorder>
495+
496+
/**
497+
* `createResumeRecorder` 的同步版本,不推荐使用
498+
*/
499+
function createResumeRecorderSync (baseDirPath?: string): ResumeRecorder
453500
}
454501

455502
export declare namespace util {
@@ -514,8 +561,22 @@ export declare namespace util {
514561
* @param requestURI 回调的URL中的requestURI
515562
* @param reqBody 回调的URL中的requestURI 请求Body,仅当请求的ContentType为application/x-www-form-urlencoded时才需要传入该参数
516563
* @param callbackAuth 回调时请求的Authorization头部值
564+
* @param extra 当回调为 Qiniu 签名时需要传入
565+
* @param extra.reqMethod 请求方法,例如 GET,POST
566+
* @param extra.reqContentType 请求类型,例如 application/json 或者 application/x-www-form-urlencoded
567+
* @param extra.reqHeaders 请求头部
517568
*/
518-
function isQiniuCallback(mac: auth.digest.Mac, requestURI: string, reqBody: string | null, callbackAuth: string): boolean;
569+
function isQiniuCallback(
570+
mac: auth.digest.Mac,
571+
requestURI: string,
572+
reqBody: string | null,
573+
callbackAuth: string,
574+
extra?: {
575+
reqMethod: string,
576+
reqContentType?: string,
577+
reqHeaders?: Record<string, string>
578+
}
579+
): boolean;
519580
}
520581

521582
export declare namespace httpc {
@@ -531,7 +592,7 @@ export declare namespace httpc {
531592
// responseWrapper.js
532593
interface ResponseWrapperOptions<T = any> {
533594
data: T;
534-
resp: IncomingMessage;
595+
resp: Omit<IncomingMessage, 'url'> & { requestUrls: string[] };
535596
}
536597

537598
interface ResponseError {
@@ -541,7 +602,7 @@ export declare namespace httpc {
541602

542603
class ResponseWrapper<T = any> {
543604
data: T extends void ? undefined | ResponseError : T & ResponseError;
544-
resp: IncomingMessage;
605+
resp: Omit<IncomingMessage, 'url'> & { requestUrls: string[] };
545606
constructor(options: ResponseWrapperOptions);
546607
ok(): boolean;
547608
needRetry(): boolean;
@@ -643,17 +704,17 @@ export declare namespace httpc {
643704
middlewares?: middleware.Middleware[];
644705
}
645706

646-
interface GetOptions<T = any> extends ReqOpts<T> {
707+
interface GetOptions<T = any> extends Omit<ReqOpts<T>, 'urllibOptions'> {
647708
params: Record<string, string>;
648709
headers: Record<string, string>;
649710
}
650711

651-
interface PostOptions<T = any> extends ReqOpts<T> {
712+
interface PostOptions<T = any> extends Omit<ReqOpts<T>, 'urllibOptions'> {
652713
data: string | Buffer | Readable;
653714
headers: Record<string, string>;
654715
}
655716

656-
interface PutOptions<T = any> extends ReqOpts<T> {
717+
interface PutOptions<T = any> extends Omit<ReqOpts<T>, 'urllibOptions'> {
657718
data: string | Buffer | Readable;
658719
headers: Record<string, string>
659720
}
@@ -664,9 +725,9 @@ export declare namespace httpc {
664725
middlewares: middleware.Middleware[];
665726
constructor(options: HttpClientOptions)
666727
sendRequest(requestOptions: ReqOpts): Promise<ResponseWrapper>
667-
get(getOptions: GetOptions): Promise<ResponseWrapper>
668-
post(postOptions: PostOptions): Promise<ResponseWrapper>
669-
put(putOptions: PutOptions): Promise<ResponseWrapper>
728+
get(getOptions: GetOptions, urllibOptions?: RequestOptions): Promise<ResponseWrapper>
729+
post(postOptions: PostOptions, urllibOptions?: RequestOptions): Promise<ResponseWrapper>
730+
put(putOptions: PutOptions, urllibOptions?: RequestOptions): Promise<ResponseWrapper>
670731
}
671732

672733
// endpoint.js
@@ -688,12 +749,15 @@ export declare namespace httpc {
688749
getValue(options?: {scheme?: string}): string;
689750

690751
getEndpoints(): Promise<httpc.Endpoint[]>;
752+
753+
clone(): Endpoint;
691754
}
692755

693756
// region.js
694757
enum SERVICE_NAME {
695758
UC = 'uc',
696759
UP = 'up',
760+
UP_ACC = 'up_acc',
697761
IO = 'io',
698762
RS = 'rs',
699763
RSF = 'rsf',
@@ -764,6 +828,7 @@ export declare namespace httpc {
764828
class Region implements RegionsProvider {
765829
static fromZone(zone: conf.Zone, options?: RegionFromZoneOptions): Region;
766830
static fromRegionId(regionId: string, options?: RegionFromRegionIdOptions): Region;
831+
static merge(...r: Region[]): Region;
767832

768833
// non-unique
769834
regionId?: string;
@@ -777,6 +842,10 @@ export declare namespace httpc {
777842

778843
getRegions(): Promise<httpc.Region[]>;
779844

845+
clone(): Region;
846+
847+
merge(...r: Region[]): Region;
848+
780849
get isLive(): boolean;
781850
}
782851

@@ -1288,6 +1357,32 @@ export declare namespace rs {
12881357
* @param callbackFunc
12891358
*/
12901359
listBucket(callbackFunc?: callback): Promise<httpc.ResponseWrapper<GetBucketsResult>>
1360+
listBucket(options: { shared: string, tagCondition: Record<string, string> }, callbackFunc?: callback): Promise<httpc.ResponseWrapper<GetBucketsResult>>
1361+
1362+
/**
1363+
* 创建空间
1364+
* @param bucket 空间名
1365+
* @param options 选项
1366+
* @param options.regionId 区域 ID
1367+
* @param callbackFunc 回调函数
1368+
*/
1369+
createBucket(
1370+
bucket: string,
1371+
options: {
1372+
regionId: string
1373+
},
1374+
callbackFunc?: callback
1375+
): Promise<httpc.ResponseWrapper<void>>
1376+
1377+
/**
1378+
* 删除空间
1379+
* @param bucket 空间名
1380+
* @param callbackFunc 回调函数
1381+
*/
1382+
deleteBucket(
1383+
bucket: string,
1384+
callbackFunc?: callback
1385+
): Promise<httpc.ResponseWrapper<void>>
12911386

12921387
/**
12931388
* 获取空间详情

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "qiniu",
3-
"version": "7.12.0",
3+
"version": "7.13.0",
44
"description": "Node wrapper for Qiniu Resource (Cloud) Storage API",
55
"main": "index.js",
66
"directories": {
@@ -58,6 +58,7 @@
5858
"encodeurl": "^1.0.1",
5959
"formstream": "^1.1.0",
6060
"mime": "^2.4.4",
61+
"mkdirp": "^0.5.5",
6162
"mockdate": "^3.0.5",
6263
"tunnel-agent": "^0.6.0",
6364
"typescript": "^4.9.4",

qiniu/conf.js

+27-14
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,30 @@ exports.FormMimeRaw = 'application/octet-stream';
2727
exports.RS_HOST = 'rs.qiniu.com';
2828
exports.RPC_TIMEOUT = 600000; // 600s
2929
let QUERY_REGION_BACKUP_HOSTS = [
30-
'uc.qbox.me',
31-
'api.qiniu.com'
30+
'kodo-config.qiniuapi.com',
31+
'uc.qbox.me'
3232
];
3333
Object.defineProperty(exports, 'QUERY_REGION_BACKUP_HOSTS', {
3434
get: () => QUERY_REGION_BACKUP_HOSTS,
3535
set: v => {
3636
QUERY_REGION_BACKUP_HOSTS = v;
3737
}
3838
});
39-
let QUERY_REGION_HOST = 'kodo-config.qiniuapi.com';
39+
let QUERY_REGION_HOST = 'uc.qiniuapi.com';
4040
Object.defineProperty(exports, 'QUERY_REGION_HOST', {
4141
get: () => QUERY_REGION_HOST,
4242
set: v => {
4343
QUERY_REGION_HOST = v;
4444
QUERY_REGION_BACKUP_HOSTS = [];
4545
}
4646
});
47-
let UC_HOST = 'uc.qbox.me';
47+
let UC_BACKUP_HOSTS = QUERY_REGION_BACKUP_HOSTS.slice();
48+
let UC_HOST = QUERY_REGION_HOST;
4849
Object.defineProperty(exports, 'UC_HOST', {
4950
get: () => UC_HOST,
5051
set: v => {
5152
UC_HOST = v;
53+
UC_BACKUP_HOSTS = [];
5254
QUERY_REGION_HOST = v;
5355
QUERY_REGION_BACKUP_HOSTS = [];
5456
}
@@ -64,27 +66,37 @@ const Config = (function () {
6466
* @constructor
6567
* @param {Object} [options]
6668
* @param {boolean} [options.useHttpsDomain]
67-
* @param {boolean} [options.useCdnDomain]
69+
* @param {boolean} [options.accelerateUploading] enable accelerate uploading. should active the domains in portal before using
6870
* @param {EndpointsProvider} [options.ucEndpointsProvider]
6971
* @param {EndpointsProvider} [options.queryRegionsEndpointsProvider]
7072
* @param {RegionsProvider} [options.regionsProvider]
71-
* @param {Zone} [options.zone]
72-
* @param {number} [options.zoneExpire]
73+
* @param {string} [options.regionsQueryResultCachePath]
74+
*
75+
* @param {boolean} [options.useCdnDomain] DEPRECATED: use accelerateUploading instead
76+
* @param {Zone} [options.zone] DEPRECATED: use RegionsProvider instead
77+
* @param {number} [options.zoneExpire] DEPRECATED
7378
*/
7479
function Config (options) {
7580
options = options || {};
7681
// use http or https protocol
7782
this.useHttpsDomain = !!(options.useHttpsDomain || false);
78-
// use cdn accelerated domains, this is not work with auto query region
79-
this.useCdnDomain = !!(options.useCdnDomain && true);
83+
84+
// use accelerate upload domains
85+
this.accelerateUploading = !!(options.accelerateUploading || false);
86+
8087
// custom uc endpoints
8188
this.ucEndpointsProvider = options.ucEndpointsProvider || null;
8289
// custom query region endpoints
8390
this.queryRegionsEndpointsProvider = options.queryRegionsEndpointsProvider || null;
8491
// custom regions
8592
this.regionsProvider = options.regionsProvider || null;
93+
// custom cache persisting path for regions query result
94+
// only worked with default CachedRegionsProvider
95+
this.regionsQueryResultCachePath = options.regionsQueryResultCachePath;
8696

8797
// deprecated
98+
// use cdn accelerated domains, this is not work with auto query region
99+
this.useCdnDomain = !!(options.useCdnDomain && true);
88100
// zone of the bucket
89101
this.zone = options.zone || null;
90102
this.zoneExpire = options.zoneExpire || -1;
@@ -98,11 +110,10 @@ const Config = (function () {
98110
return this.ucEndpointsProvider;
99111
}
100112

101-
return new Endpoint(
102-
UC_HOST,
103-
{
113+
return new StaticEndpointsProvider(
114+
[UC_HOST].concat(UC_BACKUP_HOSTS).map(h => new Endpoint(h, {
104115
defaultScheme: this.useHttpsDomain ? 'https' : 'http'
105-
}
116+
}))
106117
);
107118
};
108119

@@ -216,9 +227,11 @@ const Config = (function () {
216227
const cacheKey = [
217228
endpointsMd5,
218229
accessKey,
219-
bucketName
230+
bucketName,
231+
this.accelerateUploading.toString()
220232
].join(':');
221233
return new CachedRegionsProvider({
234+
persistPath: this.regionsQueryResultCachePath,
222235
cacheKey,
223236
baseRegionsProvider: new QueryRegionsProvider({
224237
accessKey: accessKey,

0 commit comments

Comments
 (0)