Skip to content

Commit

Permalink
1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanqin committed Dec 18, 2024
1 parent 5055a7a commit e6a9ac1
Show file tree
Hide file tree
Showing 154 changed files with 175 additions and 2,364 deletions.
4 changes: 2 additions & 2 deletions AppScope/app.json5
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"app": {
"bundleName": "com.tencent.cloud.cos",
"vendor": "example",
"versionCode": 1010100,
"versionName": "1.1.0",
"versionCode": 1010101,
"versionName": "1.1.1",
"icon": "$media:app_icon",
"label": "$string:app_name"
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
``` bash
"dependencies": {
...
"@tencentcloud/cos":"1.1.0"
"@tencentcloud/cos":"1.1.1"
}
```
2. SDK 需要网络权限,用于与 COS 服务器进行通信,请在应用模块下的 module.json5 中添加如下权限声明:
Expand Down
2 changes: 1 addition & 1 deletion cosSdk/BuildProfile.ets
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Use these variables when you tailor your ArkTS code. They must be of the const type.
*/
export const HAR_VERSION = '1.1.0';
export const HAR_VERSION = '1.1.1';
export const BUILD_MODE_NAME = 'release';
export const DEBUG = false;
export const TARGET_NAME = 'default';
Expand Down
3 changes: 3 additions & 0 deletions cosSdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.1.1
- 进度回调增加频控

## 1.1.0
- 更换http网络库到rcp
- http重定向默认不开启
Expand Down
2 changes: 1 addition & 1 deletion cosSdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
``` bash
"dependencies": {
...
"@tencentcloud/cos":"1.1.0"
"@tencentcloud/cos":"1.1.1"
}
```
2. SDK 需要网络权限,用于与 COS 服务器进行通信,请在应用模块下的 module.json5 中添加如下权限声明:
Expand Down
Binary file removed cosSdk/foundation110.har
Binary file not shown.
Binary file added cosSdk/foundation111.har
Binary file not shown.
8 changes: 4 additions & 4 deletions cosSdk/oh-package-lock.json5

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions cosSdk/oh-package.json5
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tencentcloud/cos",
"version": "1.1.0",
"version": "1.1.1",
"description": "Tencent cloud cos sdk",
"main": "Index.ets",
"keywords": ["对象存储", "COS", "腾讯云"],
Expand All @@ -9,7 +9,7 @@
"author": "Cos",
"license": "Apache-2.0",
"dependencies": {
"@tencentcloud/foundation": "file:./foundation110.har"
"@tencentcloud/foundation": "file:./foundation111.har"
// "@tencentcloud/foundation": "file:../foundation"
}
}
5 changes: 3 additions & 2 deletions cosSdk/src/main/ets/CosXmlBaseService.ets
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export class CosXmlBaseService {
if (cosXmlRequest instanceof GetObjectRequest) {
responseBodyConverter =
new ResponseFileConverter<T2>(cosXmlRequest.filePath, cosXmlRequest.fileOffset, cosXmlResult,
cosXmlRequest.onProgress);
this.cosXmlServiceConfig.progressGranularity, cosXmlRequest.onProgress);
} else if (cosXmlRequest instanceof GetObjectArrayBufferRequest) {
responseBodyConverter = new ResponseArrayBufferConverter<T2>(cosXmlResult);
} else {
Expand All @@ -196,7 +196,8 @@ export class CosXmlBaseService {
cosXmlRequest.getQueries(),
cosXmlRequest.isNeedMD5,
cosXmlRequest.isSignedInURL,
this.cosXmlServiceConfig.requestConfiguration
this.cosXmlServiceConfig.requestConfiguration,
this.cosXmlServiceConfig.progressGranularity
);
qcloudHttpRequest.noSignHeaderKeys =
new Set(Array.from(cosXmlRequest.noSignHeaderKeys).concat(Array.from(this.cosXmlServiceConfig.noSignHeaderKeys)));
Expand Down
6 changes: 6 additions & 0 deletions cosSdk/src/main/ets/CosXmlServiceConfig.ets
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ export class CosXmlServiceConfig {
*/
region: string|undefined;

/**
* 单次网络请求的进度回调的时间颗粒度,默认为200ms
* 主要用于进度回调的频控,防止频率过高导致的anr等问题
*/
progressGranularity: number = 200;

constructor(region?: string) {
this.region = region;
}
Expand Down
12 changes: 6 additions & 6 deletions cosSdk/src/main/ets/converter/ResponseFileConverter.ets
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HttpHeader, HttpProgress, HttpRequest, HttpUtils } from '@tencentcloud/foundation';
import { HttpHeader, HttpProgress, HttpRequest, HttpUtils, ProgressController } from '@tencentcloud/foundation';
import { CosXmlResult } from '../model/CosXmlResult';
import { CosResponseBodyConverter } from './CosResponseBodyConverter';
import fs from '@ohos.file.fs';
Expand All @@ -10,19 +10,19 @@ export class ResponseFileConverter<T> extends CosResponseBodyConverter<T> {
private filePath: string;
private fileOffset: number = 0;
private cosXmlResult: CosXmlResult;
private onProgress?:Callback<HttpProgress>;
private progressController: ProgressController;
private file?: fs.File;
// 重试修改range前已经下载的长度
private lastTimeBytes: number = 0;
// 已传输的数据长度
private bytesTotal: number = 0;

constructor(filePath: string, fileOffset: number, cosXmlResult: CosXmlResult, onProgress?:Callback<HttpProgress>) {
constructor(filePath: string, fileOffset: number, cosXmlResult: CosXmlResult, progressGranularity: number, onProgress?:Callback<HttpProgress>) {
super();
this.filePath = filePath;
this.fileOffset = fileOffset;
this.cosXmlResult = cosXmlResult;
this.onProgress = onProgress;
this.progressController = new ProgressController(onProgress, progressGranularity);
}

// 拿到header 因为http状态码最后才能拿到 需要跟进content type判断文件写入等
Expand Down Expand Up @@ -61,8 +61,8 @@ export class ResponseFileConverter<T> extends CosResponseBodyConverter<T> {
this.bytesTotal += fs.writeSync(this.file.fd, arrayBuffer, {
offset: this.bytesTotal + this.fileOffset,
})
if (this.onProgress) {
this.onProgress(new HttpProgress(this.bytesTotal, this.contentLength+this.lastTimeBytes));
if (this.progressController) {
this.progressController.updateProgress(this.bytesTotal, this.contentLength+this.lastTimeBytes);
}
}

Expand Down
39 changes: 39 additions & 0 deletions cosSdk/src/ohosTest/ets/test/transfer/Download.test.ets
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,45 @@ export default function downloadTest(cosXmlBaseService: CosXmlBaseService) {
}
downloadTask.start();
})

// it('big_522m', 0, async (done: Function) => {
// let context = TestUtils.getContext();
// let filePath = context.filesDir + '/big_object';
// let request = new GetObjectRequest(TestConst.PERSIST_BUCKET, TestConst.PERSIST_BUCKET_BIG_FILE_PATH, filePath);
// let config = new CosXmlServiceConfig(TestConst.PERSIST_BUCKET_REGION);
// config.readTimeout = 15000 * 1000;
// let credentialCallBack: CredentialCallBack|undefined;
// if(cosXmlBaseService){
// credentialCallBack = cosXmlBaseService.credentialCallBack;
// } else {
// credentialCallBack = CosXmlBaseService.default().credentialCallBack;
// }
// let cosBaseService = new CosXmlBaseService(context, config, credentialCallBack);
// await TestUtils.requestAddCredential(request, TestUtils.getCosXmlBaseService(cosBaseService));
// let downloadTask = TestUtils.getCosXmlBaseService(cosXmlBaseService).download(request);
// let progressCount = 0;
// downloadTask.onProgress = (progress: HttpProgress)=>{
// Logger.info(`已下载:${progress.complete},总大小:${progress.target}`)
// progressCount++;
// }
// downloadTask.onResult = {
// onSuccess: async (request: GetObjectRequest, result: CosXmlDownloadTaskResult)=>{
// Logger.info(`下载成功:`)
// Logger.info(`下载_progressCount:${progressCount}/`)
// Logger.info(result)
// expect(true).assertTrue();
// done();
// },
// onFail: (request: GetObjectRequest, error: CosError)=>{
// Logger.info(`下载失败:`)
// Logger.info(`下载_progressCount:${progressCount}/`)
// TestUtils.printError(error);
// expect().assertFail();
// done();
// }
// }
// downloadTask.start();
// })
// it('big', 0, async (done: Function) => {
// let context = TestUtils.getContext();
// let filePath = context.filesDir + '/522m.zip';
Expand Down
9 changes: 8 additions & 1 deletion cosSdk/src/ohosTest/ets/test/transfer/Upload.test.ets
Original file line number Diff line number Diff line change
Expand Up @@ -229,19 +229,26 @@ export default function uploadTest(cosXmlBaseService: CosXmlBaseService) {
let filePath = FileUtils.getFile(100 * 1024 * 1024,'bigUpload');
let putRequest = new PutObjectRequest(TestConst.PERSIST_BUCKET, `uploadTest/UT/bigUpload`, filePath);
await TestUtils.requestAddCredential(putRequest, TestUtils.getCosXmlBaseService(cosXmlBaseService));
let task: UploadTask = TestUtils.getCosXmlBaseService(cosXmlBaseService).upload(putRequest);
let task: UploadTask = TestUtils.getCosXmlBaseService(cosXmlBaseService).upload(
putRequest,

);
let progressCount = 0;
task.onProgress = (progress: HttpProgress) => {
Logger.info(`bigUpload_onProgress:${progress.complete}/${progress.target}`)
progressCount++;
};
task.onResult = {
onSuccess: (request, result) => {
Logger.info(`bigUpload_success`)
Logger.info(`bigUpload_progressCount:${progressCount}/`)
Logger.info(result)
expect(true).assertTrue();
done();
},
onFail: (request, error) => {
Logger.info(`bigUpload_fail`)
Logger.info(`bigUpload_progressCount:${progressCount}/`)
Logger.info(error)
expect().assertFail()
done();
Expand Down
Binary file removed cosTransferPractice/cosSdk-1.1.0.har
Binary file not shown.
Binary file added cosTransferPractice/cosSdk-1.1.1.har
Binary file not shown.
21 changes: 11 additions & 10 deletions cosTransferPractice/oh-package-lock.json5

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions cosTransferPractice/oh-package.json5
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"license": "",
"dependencies": {
// "@tencentcloud/cos": "file:../cosSdk"
"@tencentcloud/cos": "file:./cosSdk-1.1.0.har"
// "@tencentcloud/cos": "^1.1.0"
// "@tencentcloud/cos": "file:./cosSdk-1.1.1.har"
"@tencentcloud/cos": "^1.1.1"
},
"devDependencies": {},
"dynamicDependencies": {}
Expand Down
8 changes: 4 additions & 4 deletions cosTransferPractice/src/main/ets/Const.ets
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ export enum CredentialType {

export class Const {
public static readonly CREDENTIAL_TYPE: CredentialType = CredentialType.STS;// 临时密钥STS和固定密钥CONST
public static readonly STS_CREDENTIAL_URL = "http://x.x.x.x:3000/sts";
public static readonly STS_CREDENTIAL_URL = "http://*********:3000/sts";
public static readonly CONST_SECRET_ID = "XXXXXXXXXXXXXXXXXXXXXXX";
public static readonly CONST_SECRET_KEY = "XXXXXXXXXXXXXXXXXXXXXXX";

public static readonly TEST_BUCKET_REGION = "ap-guangzhou";
public static readonly TEST_BUCKET = "mobile-ut-1253960454";
public static readonly TEST_BUCKET_REGION = "ap-nanjing";
public static readonly TEST_BUCKET = "000garenwang-1253960454";
public static readonly TEST_UPLOAD_DIR = "uploadTest/";
public static readonly TEST_DOWNLOAD_PATH = "do_not_remove/video.mp4";
public static readonly TEST_DOWNLOAD_PATH = "test_video.mp4";
}
2 changes: 1 addition & 1 deletion foundation/BuildProfile.ets
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Use these variables when you tailor your ArkTS code. They must be of the const type.
*/
export const HAR_VERSION = '1.1.0';
export const HAR_VERSION = '1.1.1';
export const BUILD_MODE_NAME = 'release';
export const DEBUG = false;
export const TARGET_NAME = 'default';
Expand Down
2 changes: 1 addition & 1 deletion foundation/Index.ets
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export { QCloudCredential} from './src/main/ets/authentation/QCloudCredential'
export { CredentialCache} from './src/main/ets/authentation/CredentialCache'
export { QCloudSignatureBuilder, CredentialCallBack, SelfSignCallBack} from './src/main/ets/authentation/QCloudSignatureBuilder'
export { HttpRequest } from './src/main/ets/net/HttpRequest'
export { HttpProgress } from './src/main/ets/net/HttpProgress'
export { HttpProgress, ProgressController } from './src/main/ets/net/HttpProgress'
export { HttpResponse } from './src/main/ets/net/HttpResponse'
export { ResponseBodyConverter } from './src/main/ets/net/ResponseBodyConverter'
export { RequestBodySerializer, BaseRequestBodyWrapper } from './src/main/ets/net/RequestBodySerializer'
Expand Down
2 changes: 1 addition & 1 deletion foundation/oh-package.json5
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tencentcloud/foundation",
"version": "1.1.0",
"version": "1.1.1",
"description": "Tencent cloud cos sdk basic library",
"main": "Index.ets",
"author": "Cos",
Expand Down
32 changes: 32 additions & 0 deletions foundation/src/main/ets/net/HttpProgress.ets
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,36 @@ export class HttpProgress{
this.target = target;
}

}

/**
* 进度控制器,目前用于频控
*/
export class ProgressController {
private lastUpdateTime = 0;
private timeGranularity: number | undefined;
private onProgress: Callback<HttpProgress> | undefined;

// 时间颗粒度默认为200ms
constructor(onProgress: Callback<HttpProgress> | undefined, timeGranularity: number | undefined) {
this.onProgress = onProgress;
this.timeGranularity = timeGranularity;
}

public updateProgress(complete: number, target: number) {
if(this.timeGranularity) {
const now = Date.now();
const progress = (complete / target) * 100;
if (progress >= 100 || now - this.lastUpdateTime >= this.timeGranularity) {
this.lastUpdateTime = now;
if (this.onProgress) {
this.onProgress(new HttpProgress(complete, target));
}
}
} else {
if (this.onProgress) {
this.onProgress(new HttpProgress(complete, target));
}
}
}
}
6 changes: 4 additions & 2 deletions foundation/src/main/ets/net/HttpRequest.ets
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ export class HttpRequest<T> {
dnsOverHttps?: string;
dnsServers?: string[];
requestConfiguration?: rcp.Configuration;
progressGranularity?: number;

constructor(method: http.RequestMethod, protocol: string, host: string, port: number, path: string,
requestBodySerializer: RequestBodySerializer | undefined, responseBodyConverter: ResponseBodyConverter<T>,
headers?: Map<string, string>, queries?: Map<string, string | undefined>, isNeedMD5?: boolean,
isSignedInURL?: boolean, requestConfiguration?: rcp.Configuration) {
isSignedInURL?: boolean, requestConfiguration?: rcp.Configuration, progressGranularity?: number) {
this.method = method;
this.protocol = protocol;
this.host = host;
Expand All @@ -47,7 +48,8 @@ export class HttpRequest<T> {
this.noSignQueryKeys = new Set();
this.isNeedMD5 = isNeedMD5 || false;
this.isSignedInURL = isSignedInURL || false;
this.requestConfiguration = requestConfiguration
this.requestConfiguration = requestConfiguration;
this.progressGranularity = progressGranularity;
}

addHeader(key: string, value: string): void {
Expand Down
4 changes: 2 additions & 2 deletions foundation/src/main/ets/net/QCloudHttpRequest.ets
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export class QCloudHttpRequest<T> extends HttpRequest<T> {
constructor(method: http.RequestMethod, protocol: string, host: string, port: number, path: string,
requestBodySerializer: RequestBodySerializer | undefined, responseBodyConverter: ResponseBodyConverter<T>,
headers?: Map<string, string>, queries?: Map<string, string | undefined>, isNeedMD5?: boolean,
isSignedInURL?: boolean, requestConfiguration?: rcp.Configuration) {
isSignedInURL?: boolean, requestConfiguration?: rcp.Configuration, progressGranularity?: number) {
super(method, protocol, host, port, path, requestBodySerializer, responseBodyConverter, headers, queries, isNeedMD5,
isSignedInURL, requestConfiguration);
isSignedInURL, requestConfiguration, progressGranularity);
}
}
Loading

0 comments on commit e6a9ac1

Please sign in to comment.