Skip to content

Commit 904b25d

Browse files
authored
Dev/1.6.0 (#99)
* feat: 去掉灯塔 sdk依赖
1 parent dda33bf commit 904b25d

File tree

11 files changed

+66
-1321
lines changed

11 files changed

+66
-1321
lines changed

demo-album/lib/cos-wx-sdk-v5.js

Lines changed: 17 additions & 654 deletions
Large diffs are not rendered by default.

demo-album/lib/cos-wx-sdk-v5.min.js

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.

demo/lib/cos-wx-sdk-v5.js

Lines changed: 17 additions & 654 deletions
Large diffs are not rendered by default.

demo/lib/cos-wx-sdk-v5.min.js

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/tools.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var COS = require('./lib/cos-wx-sdk-v5');
22
var config = require('./config');
3+
const Beacon = require('./lib/beacon_mp.min');
34

45
// 签名回调
56
var getAuthorization = function (options, callback) {
@@ -86,8 +87,8 @@ var getAuthorization = function (options, callback) {
8687
};
8788

8889
var cos = new COS({
89-
// path style 指正式请求时,Bucket 是在 path 里,这样用相同园区多个 bucket 只需要配置一个园区域名
90-
// ForcePathStyle: true,
90+
// EnableTracker: true, // 开启灯塔上报
91+
// Beacon,
9192
getAuthorization: getAuthorization,
9293
// 是否使用全球加速域名。开启该配置后仅以下接口支持操作:putObject、getObject、headObject、optionsObject、multipartInit、multipartListPart、multipartUpload、multipartAbort、multipartComplete、multipartList、sliceUploadFile、uploadFiles
9394
// UseAccelerate: true,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cos-wx-sdk-v5",
3-
"version": "1.5.0",
3+
"version": "1.6.0",
44
"description": "小程序 SDK for [腾讯云对象存储服务](https://cloud.tencent.com/product/cos)",
55
"main": "demo/lib/cos-wx-sdk-v5.min.js",
66
"scripts": {

src/advance.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,7 @@ async function uploadFile(params, callback) {
947947
self.options.UseAccelerate ||
948948
(typeof self.options.Domain === 'string' && self.options.Domain.includes('accelerate.'));
949949
params.tracker = new Tracker({
950+
Beacon: self.options.Beacon,
950951
bucket: params.Bucket,
951952
region: params.Region,
952953
apiName: 'uploadFile',
@@ -1046,6 +1047,7 @@ async function uploadFiles(params, callback) {
10461047
self.options.UseAccelerate ||
10471048
(typeof self.options.Domain === 'string' && self.options.Domain.includes('accelerate.'));
10481049
fileParams.tracker = new Tracker({
1050+
Beacon: self.options.Beacon,
10491051
bucket: fileParams.Bucket,
10501052
region: fileParams.Region,
10511053
apiName: 'uploadFiles',

src/cos.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ var defaultOptions = {
3939
SimpleUploadMethod: 'postObject', // 高级上传内部判断需要走简单上传时,指定的上传方法,可选postObject或putObject
4040
EnableTracker: false, // 默认关闭上报
4141
DeepTracker: false, // 上报时是否对每个分块上传做单独上报
42+
Beacon: null, // 灯塔上报组件,如有需要请自行传入
4243
TrackerDelay: 5000, // 周期性上报,单位毫秒。0代表实时上报
4344
CustomId: '', // 自定义上报id
4445
AutoSwitchHost: false,
46+
CopySourceParser: null, // 自定义拷贝源解析器
4547
};
4648

4749
// 对外暴露的类

src/tracker.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
const pkg = require('../package.json');
2-
const BeaconAction = require('../lib/beacon_mp.min');
32
let beacon = null;
43

5-
const getBeacon = (delay) => {
4+
const getBeacon = (Beacon, delay) => {
65
if (!beacon) {
7-
beacon = new BeaconAction({
6+
// 生成 beacon
7+
if (!Beacon || typeof Beacon !== 'function') {
8+
throw new Error('Beacon not found');
9+
}
10+
beacon = new Beacon({
811
appkey: '0AND0VEVB24UBGDU',
912
versionCode: pkg.version,
1013
channelID: 'mp_sdk', //渠道,选填
@@ -202,8 +205,20 @@ function formatParams(params) {
202205
// 链路追踪器
203206
class Tracker {
204207
constructor(opt) {
205-
const { parent, traceId, bucket, region, apiName, fileKey, fileSize, accelerate, customId, delay, deepTracker } =
206-
opt;
208+
const {
209+
parent,
210+
traceId,
211+
bucket,
212+
region,
213+
apiName,
214+
fileKey,
215+
fileSize,
216+
accelerate,
217+
customId,
218+
delay,
219+
deepTracker,
220+
Beacon,
221+
} = opt;
207222
const appid = (bucket && bucket.substr(bucket.lastIndexOf('-') + 1)) || '';
208223
this.parent = parent;
209224
this.deepTracker = deepTracker;
@@ -254,7 +269,7 @@ class Tracker {
254269
startTime: new Date().getTime(), // sdk api调用起始时间,不是纯网络耗时
255270
endTime: 0, // sdk api调用结束时间,不是纯网络耗时
256271
};
257-
this.beacon = getBeacon(delay);
272+
this.beacon = getBeacon(Beacon, delay);
258273
}
259274

260275
// 格式化sdk回调

0 commit comments

Comments
 (0)