New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

qiniu-js

Package Overview
Dependencies
Maintainers
2
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

qiniu-js - npm Package Compare versions

Comparing version 3.4.0 to 3.4.1

20

esm/upload/base.js

@@ -157,3 +157,3 @@ var __assign = (this && this.__assign) || function () {

return __awaiter(this, void 0, void 0, function () {
var result, err_1, reqId, code, notReachRetryCount, needRetry;
var result, err_1, notReachRetryCount, needRetry;
return __generator(this, function (_a) {

@@ -201,12 +201,15 @@ switch (_a.label) {

err_1 = _a.sent();
if (this.aborted) {
this.logger.warn('upload is aborted.');
this.sendLog('', -2);
return [2 /*return*/];
}
this.clear();
this.logger.error(err_1);
this.clear();
if (err_1 instanceof QiniuRequestError) {
reqId = this.aborted ? '' : err_1.reqId;
code = this.aborted ? -2 : err_1.code;
this.sendLog(reqId, code);
this.sendLog(err_1.reqId, err_1.code);
// 检查并冻结当前的 host
this.checkAndFreezeHost(err_1);
notReachRetryCount = ++this.retryCount <= this.config.retryCount;
needRetry = !this.aborted && RETRY_CODE_LIST.includes(err_1.code);
needRetry = RETRY_CODE_LIST.includes(err_1.code);
// 以下条件满足其中之一则会进行重新上传:

@@ -229,3 +232,2 @@ // 1. 满足 needRetry 的条件且 retryCount 不为 0

Base.prototype.clear = function () {
this.logger.info('start cleaning all xhr.');
this.xhrList.forEach(function (xhr) {

@@ -235,7 +237,7 @@ xhr.onreadystatechange = null;

});
this.logger.info('cleanup completed.');
this.xhrList = [];
this.logger.info('cleanup uploading xhr.');
};
Base.prototype.stop = function () {
this.logger.info('stop.');
this.logger.info('aborted.');
this.clear();

@@ -242,0 +244,0 @@ this.aborted = true;

@@ -96,3 +96,17 @@ var __extends = (this && this.__extends) || (function () {

_a.sent();
pool = new utils.Pool(function (chunkInfo) { return _this.uploadChunk(chunkInfo); }, this.config.concurrentRequestLimit);
pool = new utils.Pool(function (chunkInfo) { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (this.aborted) {
pool.abort();
throw new Error('pool is aborted');
}
return [4 /*yield*/, this.uploadChunk(chunkInfo)];
case 1:
_a.sent();
return [2 /*return*/];
}
});
}); }, this.config.concurrentRequestLimit);
mkFileResponse = null;

@@ -99,0 +113,0 @@ localKey = this.getLocalKey();

@@ -48,32 +48,29 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

}
describe('test crc32', function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
test('file', function () { return __awaiter(void 0, void 0, void 0, function () {
var crc32One, crc32Two, crc32Three, crc32Four;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
crc32One = new CRC32();
return [4 /*yield*/, expect(crc32One.file(mockFile(0))).resolves.toEqual(0)];
case 1:
_a.sent();
crc32Two = new CRC32();
return [4 /*yield*/, expect(crc32Two.file(mockFile(0.5))).resolves.toEqual(1610895105)];
case 2:
_a.sent();
crc32Three = new CRC32();
return [4 /*yield*/, expect(crc32Three.file(mockFile(1))).resolves.toEqual(3172987001)];
case 3:
_a.sent();
crc32Four = new CRC32();
return [4 /*yield*/, expect(crc32Four.file(mockFile(2))).resolves.toEqual(847982614)];
case 4:
_a.sent();
return [2 /*return*/];
}
});
}); });
return [2 /*return*/];
});
}); });
describe('test crc32', function () {
test('file', function () { return __awaiter(void 0, void 0, void 0, function () {
var crc32One, crc32Two, crc32Three, crc32Four;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
crc32One = new CRC32();
return [4 /*yield*/, expect(crc32One.file(mockFile(0))).resolves.toEqual(0)];
case 1:
_a.sent();
crc32Two = new CRC32();
return [4 /*yield*/, expect(crc32Two.file(mockFile(0.5))).resolves.toEqual(1610895105)];
case 2:
_a.sent();
crc32Three = new CRC32();
return [4 /*yield*/, expect(crc32Three.file(mockFile(1))).resolves.toEqual(3172987001)];
case 3:
_a.sent();
crc32Four = new CRC32();
return [4 /*yield*/, expect(crc32Four.file(mockFile(2))).resolves.toEqual(847982614)];
case 4:
_a.sent();
return [2 /*return*/];
}
});
}); });
});
//# sourceMappingURL=crc32.test.js.map

@@ -10,2 +10,3 @@ export declare type RunTask<T> = (...args: T[]) => Promise<void>;

private limit;
aborted: boolean;
queue: Array<QueueContent<T>>;

@@ -15,4 +16,5 @@ processing: Array<QueueContent<T>>;

enqueue(task: T): Promise<void>;
run(item: QueueContent<T>): void;
check(): void;
private run;
private check;
abort(): void;
}

@@ -5,2 +5,3 @@ var Pool = /** @class */ (function () {

this.limit = limit;
this.aborted = false;
this.queue = [];

@@ -32,2 +33,4 @@ this.processing = [];

var _this = this;
if (this.aborted)
return;
var processingNum = this.processing.length;

@@ -39,2 +42,6 @@ var availableNum = this.limit - processingNum;

};
Pool.prototype.abort = function () {
this.queue = [];
this.aborted = true;
};
return Pool;

@@ -41,0 +48,0 @@ }());

@@ -9,4 +9,5 @@ module.exports = {

"lib",
"examples",
"node_modules"
]
};

@@ -336,3 +336,3 @@ "use strict";

return __awaiter(this, void 0, void 0, function () {
var result, err_1, reqId, code, notReachRetryCount, needRetry;
var result, err_1, notReachRetryCount, needRetry;
return __generator(this, function (_a) {

@@ -402,13 +402,20 @@ switch (_a.label) {

err_1 = _a.sent();
if (this.aborted) {
this.logger.warn('upload is aborted.');
this.sendLog('', -2);
return [2
/*return*/
];
}
this.clear();
this.logger.error(err_1);
this.clear();
if (err_1 instanceof _errors.QiniuRequestError) {
reqId = this.aborted ? '' : err_1.reqId;
code = this.aborted ? -2 : err_1.code;
this.sendLog(reqId, code); // 检查并冻结当前的 host
this.sendLog(err_1.reqId, err_1.code); // 检查并冻结当前的 host
this.checkAndFreezeHost(err_1);
notReachRetryCount = ++this.retryCount <= this.config.retryCount;
needRetry = !this.aborted && RETRY_CODE_LIST.includes(err_1.code); // 以下条件满足其中之一则会进行重新上传:
needRetry = RETRY_CODE_LIST.includes(err_1.code); // 以下条件满足其中之一则会进行重新上传:
// 1. 满足 needRetry 的条件且 retryCount 不为 0

@@ -441,3 +448,2 @@ // 2. uploadId 无效时在 resume 里会清除本地数据,并且这里触发重新上传

Base.prototype.clear = function () {
this.logger.info('start cleaning all xhr.');
this.xhrList.forEach(function (xhr) {

@@ -447,8 +453,8 @@ xhr.onreadystatechange = null;

});
this.logger.info('cleanup completed.');
this.xhrList = [];
this.logger.info('cleanup uploading xhr.');
};
Base.prototype.stop = function () {
this.logger.info('stop.');
this.logger.info('aborted.');
this.clear();

@@ -455,0 +461,0 @@ this.aborted = true;

@@ -269,3 +269,24 @@ "use strict";

pool = new utils.Pool(function (chunkInfo) {
return _this.uploadChunk(chunkInfo);
return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (this.aborted) {
pool.abort();
throw new Error('pool is aborted');
}
return [4
/*yield*/
, this.uploadChunk(chunkInfo)];
case 1:
_a.sent();
return [2
/*return*/
];
}
});
});
}, this.config.concurrentRequestLimit);

@@ -272,0 +293,0 @@ mkFileResponse = null;

@@ -179,54 +179,47 @@ "use strict";

describe('test crc32', function () {
return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
test('file', function () {
return __awaiter(void 0, void 0, void 0, function () {
var crc32One, crc32Two, crc32Three, crc32Four;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
crc32One = new _crc.CRC32();
return [4
/*yield*/
, expect(crc32One.file(mockFile(0))).resolves.toEqual(0)];
test('file', function () {
return __awaiter(void 0, void 0, void 0, function () {
var crc32One, crc32Two, crc32Three, crc32Four;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
crc32One = new _crc.CRC32();
return [4
/*yield*/
, expect(crc32One.file(mockFile(0))).resolves.toEqual(0)];
case 1:
_a.sent();
case 1:
_a.sent();
crc32Two = new _crc.CRC32();
return [4
/*yield*/
, expect(crc32Two.file(mockFile(0.5))).resolves.toEqual(1610895105)];
crc32Two = new _crc.CRC32();
return [4
/*yield*/
, expect(crc32Two.file(mockFile(0.5))).resolves.toEqual(1610895105)];
case 2:
_a.sent();
case 2:
_a.sent();
crc32Three = new _crc.CRC32();
return [4
/*yield*/
, expect(crc32Three.file(mockFile(1))).resolves.toEqual(3172987001)];
crc32Three = new _crc.CRC32();
return [4
/*yield*/
, expect(crc32Three.file(mockFile(1))).resolves.toEqual(3172987001)];
case 3:
_a.sent();
case 3:
_a.sent();
crc32Four = new _crc.CRC32();
return [4
/*yield*/
, expect(crc32Four.file(mockFile(2))).resolves.toEqual(847982614)];
crc32Four = new _crc.CRC32();
return [4
/*yield*/
, expect(crc32Four.file(mockFile(2))).resolves.toEqual(847982614)];
case 4:
_a.sent();
case 4:
_a.sent();
return [2
/*return*/
];
}
});
});
return [2
/*return*/
];
}
});
return [2
/*return*/
];
});
});
});

@@ -21,2 +21,3 @@ "use strict";

this.limit = limit;
this.aborted = false;
this.queue = [];

@@ -62,2 +63,3 @@ this.processing = [];

if (this.aborted) return;
var processingNum = this.processing.length;

@@ -70,2 +72,7 @@ var availableNum = this.limit - processingNum;

Pool.prototype.abort = function () {
this.queue = [];
this.aborted = true;
};
return Pool;

@@ -72,0 +79,0 @@ }();

{
"name": "qiniu-js",
"jsName": "qiniu",
"version": "3.4.0",
"version": "3.4.1",
"private": false,

@@ -6,0 +6,0 @@ "description": "Javascript SDK for Qiniu Resource (Cloud) Storage AP",

@@ -26,3 +26,3 @@ # Qiniu-JavaScript-SDK

Qiniu-JavaScript-SDK (下文简称为 JS-SDK)适用于 :IE11、Edge、Chrome、Firefox、Safari 等浏览器,基于七牛云存储官方 API 构建,其中上传功能基于 H5 File API。开发者基于 JS-SDK 可以方便的从浏览器端上传文件至七牛云存储,并对上传成功后的图片进行丰富的数据处理操作。
JS-SDK 兼容支持 H5 File API 的浏览器,在低版本浏览器下,需要额外的插件如 plupload,JS-SDK 提供了一些接口可以结合插件来进行上传工作,注意:(在低版本浏览器需要引入 [babel-polyfill](https://babeljs.cn/docs/usage/polyfill/) 来解决 sdk 里某些语法或者属性浏览器不能识别的问题)。
JS-SDK 兼容支持 H5 File API 的浏览器,在低版本浏览器下,需要额外的插件如 plupload,JS-SDK 提供了一些接口可以结合插件来进行上传工作,注意:(在低版本浏览器需要引入 [babel-polyfill](https://babeljs.cn/docs/usage/polyfill/) 来解决 SDK 里某些语法或者属性浏览器不能识别的问题)。

@@ -44,3 +44,4 @@ Qiniu-JavaScript-SDK 为客户端 SDK,没有包含 `token` 生成实现,为了安全,`token` 建议通过网络从服务端获取,具体生成代码可以参考以下服务端 SDK 的文档。

* [JavaScript SDK 在线示例](http://jssdk-v2.demo.qiniu.io/)
* [JavaScript SDK 在线示例 V3](https://js-sdk-demo.qiniu.io)
* [JavaScript SDK 在线示例 V2](http://jssdk-v2.demo.qiniu.io)

@@ -86,6 +87,12 @@ <!--

`https://cdnjs.cloudflare.com/ajax/libs/qiniu-js/<version>/qiniu.min.js`
```
https://cdnjs.cloudflare.com/ajax/libs/qiniu-js/<version>/qiniu.min.js
// 当上方资源链接访问不稳定时,可选使用下方资源链接
https://cdn.staticfile.org/qiniu-js/<version>/qiniu.min.js
```
通过 script 标签引入该文件,会在全局生成名为 `qiniu` 的对象
* 使用 NPM 安装

@@ -113,3 +120,3 @@

`qiniu.upload` 返回一个 `observable` 对象用来控制上传行为,`observable` 对像通过 `subscribe` 方法可以被 `observer` 所订阅,订阅同时会开始触发上传,同时返回一个 `subscription` 对象,该对象有一个 `unsubscribe` 方法取消订阅,同时终止上传行为。对于不支持 sdk 的浏览器可以参考 demo1 中用插件处理和 form 直传的方式; 一般 form 提交常常会导致网页跳转,demo1 中 form 直传通过加入 iframe,并结合后端 sdk 上传来解决网页跳转问题,实现 form 无刷新上传。分片上传时,JS-SDK支持断点续传功能,会把已上传片的后端返回值ctx信息存储到本地,有效期为一天,超过一天后,当继续上传该文件时会清除掉本地存储信息重新上传。
`qiniu.upload` 返回一个 `observable` 对象用来控制上传行为,`observable` 对像通过 `subscribe` 方法可以被 `observer` 所订阅,订阅同时会开始触发上传,同时返回一个 `subscription` 对象,该对象有一个 `unsubscribe` 方法取消订阅,同时终止上传行为。对于不支持 SDK 的浏览器可以参考 demo1 中用插件处理和 form 直传的方式; 一般 form 提交常常会导致网页跳转,demo1 中 form 直传通过加入 iframe,并结合后端 SDK 上传来解决网页跳转问题,实现 form 无刷新上传。分片上传时,JS-SDK支持断点续传功能,会把已上传片的后端返回值ctx信息存储到本地,有效期为一天,超过一天后,当继续上传该文件时会清除掉本地存储信息重新上传。

@@ -198,3 +205,3 @@ ### Example

* complete: 接收上传完成后的后端返回信息,具体返回结构取决于后端sdk的配置,可参考 [上传策略](https://developer.qiniu.com/kodo/manual/1206/put-policy)。
* complete: 接收上传完成后的后端返回信息,具体返回结构取决于后端 SDK 的配置,可参考 [上传策略](https://developer.qiniu.com/kodo/manual/1206/put-policy)。

@@ -506,14 +513,4 @@ * subscription: 为一个带有 `unsubscribe` 方法的类实例,通过调用 `subscription.unsubscribe()` 停止当前文件上传。

这里又分为两种方法:
通过在生成 `token` 时指定 [上传策略](https://developer.qiniu.com/kodo/1206/put-policy) 中的 `mimeLimit` 字段限定上传文件的类型,该功能由生成 `token` 的服务端 SDK 提供,请查看对应的服务端 SDK 文档。
1. 通过在 `token` 中设定 `mimeLimit` 字段限定上传文件的类型,该设定是在后端 sdk 设置,请查看相应的 sdk 文档,示例
```JavaScript
"image/\*": 表示只允许上传图片类型;
"image/jpeg;image/png": 表示只允许上传 jpg 和 png 类型的图片;
"!application/json;text/plain": 表示禁止上传 json 文本和纯文本。(注意最前面的感叹号)
```
2. 通过 `putExtra` 的 `mimeType` 参数直接在前端限定
### 贡献代码

@@ -520,0 +517,0 @@

@@ -268,9 +268,12 @@ import { QiniuErrorName, QiniuError, QiniuRequestError } from '../errors'

} catch (err) {
if (this.aborted) {
this.logger.warn('upload is aborted.')
this.sendLog('', -2)
return
}
this.clear()
this.logger.error(err)
this.clear()
if (err instanceof QiniuRequestError) {
const reqId = this.aborted ? '' : err.reqId
const code = this.aborted ? -2 : err.code
this.sendLog(reqId, code)
this.sendLog(err.reqId, err.code)

@@ -281,3 +284,3 @@ // 检查并冻结当前的 host

const notReachRetryCount = ++this.retryCount <= this.config.retryCount
const needRetry = !this.aborted && RETRY_CODE_LIST.includes(err.code)
const needRetry = RETRY_CODE_LIST.includes(err.code)

@@ -299,3 +302,2 @@ // 以下条件满足其中之一则会进行重新上传:

private clear() {
this.logger.info('start cleaning all xhr.')
this.xhrList.forEach(xhr => {

@@ -305,8 +307,8 @@ xhr.onreadystatechange = null

})
this.logger.info('cleanup completed.')
this.xhrList = []
this.logger.info('cleanup uploading xhr.')
}
public stop() {
this.logger.info('stop.')
this.logger.info('aborted.')
this.clear()

@@ -313,0 +315,0 @@ this.aborted = true

@@ -95,3 +95,10 @@ import { uploadChunk, uploadComplete, initUploadParts, UploadChunkData } from '../api'

const pool = new utils.Pool(
(chunkInfo: ChunkInfo) => this.uploadChunk(chunkInfo),
async (chunkInfo: ChunkInfo) => {
if (this.aborted) {
pool.abort()
throw new Error('pool is aborted')
}
await this.uploadChunk(chunkInfo)
},
this.config.concurrentRequestLimit

@@ -98,0 +105,0 @@ )

@@ -11,3 +11,3 @@ import { CRC32 } from './crc32'

describe('test crc32', async () => {
describe('test crc32', () => {
test('file', async () => {

@@ -14,0 +14,0 @@ const crc32One = new CRC32()

@@ -10,2 +10,3 @@ export type RunTask<T> = (...args: T[]) => Promise<void>

export class Pool<T> {
aborted = false
queue: Array<QueueContent<T>> = []

@@ -27,3 +28,3 @@ processing: Array<QueueContent<T>> = []

run(item: QueueContent<T>) {
private run(item: QueueContent<T>) {
this.queue = this.queue.filter(v => v !== item)

@@ -41,3 +42,4 @@ this.processing.push(item)

check() {
private check() {
if (this.aborted) return
const processingNum = this.processing.length

@@ -49,2 +51,7 @@ const availableNum = this.limit - processingNum

}
abort() {
this.queue = []
this.aborted = true
}
}

@@ -30,2 +30,3 @@ {

"dist",
"site",
"lib",

@@ -32,0 +33,0 @@ "esm"

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc