Skip to content

Commit

Permalink
Dev/1.6.0 (#99)
Browse files Browse the repository at this point in the history
* feat: 去掉灯塔 sdk依赖
  • Loading branch information
livehigh authored Mar 5, 2024
1 parent dda33bf commit 904b25d
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 1,321 deletions.
671 changes: 17 additions & 654 deletions demo-album/lib/cos-wx-sdk-v5.js

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions demo-album/lib/cos-wx-sdk-v5.min.js

Large diffs are not rendered by default.

File renamed without changes.
671 changes: 17 additions & 654 deletions demo/lib/cos-wx-sdk-v5.js

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions demo/lib/cos-wx-sdk-v5.min.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions demo/tools.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var COS = require('./lib/cos-wx-sdk-v5');
var config = require('./config');
const Beacon = require('./lib/beacon_mp.min');

// 签名回调
var getAuthorization = function (options, callback) {
Expand Down Expand Up @@ -86,8 +87,8 @@ var getAuthorization = function (options, callback) {
};

var cos = new COS({
// path style 指正式请求时,Bucket 是在 path 里,这样用相同园区多个 bucket 只需要配置一个园区域名
// ForcePathStyle: true,
// EnableTracker: true, // 开启灯塔上报
// Beacon,
getAuthorization: getAuthorization,
// 是否使用全球加速域名。开启该配置后仅以下接口支持操作:putObject、getObject、headObject、optionsObject、multipartInit、multipartListPart、multipartUpload、multipartAbort、multipartComplete、multipartList、sliceUploadFile、uploadFiles
// UseAccelerate: true,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cos-wx-sdk-v5",
"version": "1.5.0",
"version": "1.6.0",
"description": "小程序 SDK for [腾讯云对象存储服务](https://cloud.tencent.com/product/cos)",
"main": "demo/lib/cos-wx-sdk-v5.min.js",
"scripts": {
Expand Down
2 changes: 2 additions & 0 deletions src/advance.js
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,7 @@ async function uploadFile(params, callback) {
self.options.UseAccelerate ||
(typeof self.options.Domain === 'string' && self.options.Domain.includes('accelerate.'));
params.tracker = new Tracker({
Beacon: self.options.Beacon,
bucket: params.Bucket,
region: params.Region,
apiName: 'uploadFile',
Expand Down Expand Up @@ -1046,6 +1047,7 @@ async function uploadFiles(params, callback) {
self.options.UseAccelerate ||
(typeof self.options.Domain === 'string' && self.options.Domain.includes('accelerate.'));
fileParams.tracker = new Tracker({
Beacon: self.options.Beacon,
bucket: fileParams.Bucket,
region: fileParams.Region,
apiName: 'uploadFiles',
Expand Down
2 changes: 2 additions & 0 deletions src/cos.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ var defaultOptions = {
SimpleUploadMethod: 'postObject', // 高级上传内部判断需要走简单上传时,指定的上传方法,可选postObject或putObject
EnableTracker: false, // 默认关闭上报
DeepTracker: false, // 上报时是否对每个分块上传做单独上报
Beacon: null, // 灯塔上报组件,如有需要请自行传入
TrackerDelay: 5000, // 周期性上报,单位毫秒。0代表实时上报
CustomId: '', // 自定义上报id
AutoSwitchHost: false,
CopySourceParser: null, // 自定义拷贝源解析器
};

// 对外暴露的类
Expand Down
27 changes: 21 additions & 6 deletions src/tracker.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
const pkg = require('../package.json');
const BeaconAction = require('../lib/beacon_mp.min');
let beacon = null;

const getBeacon = (delay) => {
const getBeacon = (Beacon, delay) => {
if (!beacon) {
beacon = new BeaconAction({
// 生成 beacon
if (!Beacon || typeof Beacon !== 'function') {
throw new Error('Beacon not found');
}
beacon = new Beacon({
appkey: '0AND0VEVB24UBGDU',
versionCode: pkg.version,
channelID: 'mp_sdk', //渠道,选填
Expand Down Expand Up @@ -202,8 +205,20 @@ function formatParams(params) {
// 链路追踪器
class Tracker {
constructor(opt) {
const { parent, traceId, bucket, region, apiName, fileKey, fileSize, accelerate, customId, delay, deepTracker } =
opt;
const {
parent,
traceId,
bucket,
region,
apiName,
fileKey,
fileSize,
accelerate,
customId,
delay,
deepTracker,
Beacon,
} = opt;
const appid = (bucket && bucket.substr(bucket.lastIndexOf('-') + 1)) || '';
this.parent = parent;
this.deepTracker = deepTracker;
Expand Down Expand Up @@ -254,7 +269,7 @@ class Tracker {
startTime: new Date().getTime(), // sdk api调用起始时间,不是纯网络耗时
endTime: 0, // sdk api调用结束时间,不是纯网络耗时
};
this.beacon = getBeacon(delay);
this.beacon = getBeacon(Beacon, delay);
}

// 格式化sdk回调
Expand Down
1 change: 1 addition & 0 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ var apiWrapper = function (apiName, apiFn) {
typeof params.Body === 'string' ? params.Body.length : params.Body.size || params.Body.byteLength || -1;
}
tracker = new Tracker({
Beacon: self.options.Beacon,
bucket: params.Bucket,
region: params.Region,
apiName: apiName,
Expand Down

0 comments on commit 904b25d

Please sign in to comment.