release 7.x

This commit is contained in:
cool 2023-09-28 15:37:23 +08:00
parent bd120d1126
commit 314dc6bbf9
24 changed files with 200 additions and 60 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@cool-midway/cloud",
"version": "7.0.0",
"version": "7.0.0-beta1",
"description": "",
"main": "dist/index.js",
"typings": "index.d.ts",
@ -27,7 +27,7 @@
"url": "https://cool-js.com"
},
"devDependencies": {
"@cool-midway/core": "^6.0.0",
"@cool-midway/core": "7.0.0-beta2",
"@midwayjs/cli": "^2.0.0",
"@midwayjs/core": "^3.9.0",
"@midwayjs/decorator": "^3.9.0",

View File

@ -1,6 +1,6 @@
{
"name": "@cool-midway/cloud",
"version": "7.0.0",
"version": "7.0.0-beta1",
"description": "",
"main": "index.js",
"typings": "index.d.ts",
@ -23,7 +23,7 @@
"url": "https://cool-js.com"
},
"devDependencies": {
"@cool-midway/core": "^6.0.0",
"@cool-midway/core": "7.0.0-beta2",
"@midwayjs/cli": "^2.0.0",
"@midwayjs/core": "^3.0.0",
"@midwayjs/decorator": "^3.0.0",

View File

@ -1,6 +1,6 @@
{
"name": "@cool-midway/core",
"version": "7.0.0-beta1",
"version": "7.0.0-beta3",
"description": "",
"main": "dist/index.js",
"typings": "index.d.ts",

View File

@ -66,6 +66,8 @@ export interface CoolConfig {
cos?: COSConfig;
/** qiniu */
qiniu?: QINIUConfig;
/** aws */
aws: AWSConfig;
};
/** IOT 配置 */
iot?: CoolIotConfig;
@ -106,6 +108,8 @@ export enum CLOUDTYPE {
COS = "cos",
/** 七牛云存储 */
QINIU = "qiniu",
/** AWS S3 */
AWS = "aws",
}
/**
@ -130,6 +134,8 @@ export interface CoolFileConfig {
cos: COSConfig;
/** 七牛云 配置 */
qiniu: QINIUConfig;
/** AWS s3 配置 */
aws: AWSConfig;
/** 文件前缀 */
domain: string;
}
@ -195,6 +201,25 @@ export interface QINIUConfig {
fileKey?: string;
}
export interface AWSConfig {
/** accessKeyId */
accessKeyId: string;
/** secretAccessKey */
secretAccessKey: string;
/** bucket */
bucket: string;
/** region */
region: string;
/** fields */
fields?: any;
/** conditions */
conditions?: any[];
/** expires */
expires?: number
/** publicDomain */
publicDomain?: string;
}
/**
*
*/

View File

@ -1,6 +1,6 @@
{
"name": "@cool-midway/core",
"version": "7.0.0-beta1",
"version": "7.0.0-beta3",
"description": "",
"main": "index.js",
"typings": "index.d.ts",

View File

@ -300,8 +300,7 @@ export abstract class BaseService {
await this.modifyBefore(param, "update");
if (!param.id && !(param instanceof Array))
throw new CoolValidateException(ERRINFO.NOID);
await this.addOrUpdate(param);
await this.modifyAfter(param, "update");
await this.addOrUpdate(param, 'update');
}
/**
@ -311,8 +310,7 @@ export abstract class BaseService {
async add(param: any | any[]): Promise<Object> {
if (!this.entity) throw new CoolValidateException(ERRINFO.NOENTITY);
await this.modifyBefore(param, "add");
await this.addOrUpdate(param);
await this.modifyAfter(param, "add");
await this.addOrUpdate(param, 'add');
return {
id:
param instanceof Array
@ -329,17 +327,28 @@ export abstract class BaseService {
* |
* @param param
*/
async addOrUpdate(param: any | any[]) {
async addOrUpdate(param: any | any[], type: 'add' | 'update' = 'add') {
if (!this.entity) throw new CoolValidateException(ERRINFO.NOENTITY);
delete param.createTime;
if (param.id) {
param.updateTime = new Date();
await this.entity.save(param);
} else {
param.createTime = new Date();
param.updateTime = new Date();
await this.entity.save(param);
// 判断是否是批量操作
if (param instanceof Array) {
param.forEach((item) => {
item.updateTime = new Date();
item.createTime = new Date();
});
await this.entity.save(param);
} else{
if (type == 'update') {
param.updateTime = new Date();
await this.entity.update(param.id, param);
}
if(type =='add'){
param.createTime = new Date();
param.updateTime = new Date();
await this.entity.insert(param);
}
}
await this.modifyAfter(param, type);
}
/**
@ -502,7 +511,8 @@ export abstract class BaseService {
}
const sqls = find.getSql().split("FROM");
sqlArr.push("FROM");
sqlArr.push(sqls[1]);
// 取sqls的最后一个
sqlArr.push(sqls[sqls.length - 1]);
return sqlArr.join(" ");
}

View File

@ -1,6 +1,6 @@
{
"name": "@cool-midway/es",
"version": "6.0.2",
"version": "7.0.0-beta2",
"description": "cool-js.com elasticsearch",
"main": "dist/index.js",
"typings": "index.d.ts",
@ -24,7 +24,7 @@
],
"license": "MIT",
"devDependencies": {
"@cool-midway/core": "^6.0.0",
"@cool-midway/core": "7.0.0-beta3",
"@midwayjs/cli": "^2.0.9",
"@midwayjs/core": "^3.9.0",
"@midwayjs/decorator": "^3.9.0",

View File

@ -1,6 +1,6 @@
{
"name": "@cool-midway/es",
"version": "6.0.2",
"version": "7.0.0-beta2",
"description": "cool-js.com elasticsearch",
"main": "index.js",
"typings": "index.d.ts",
@ -22,7 +22,7 @@
},
"license": "MIT",
"devDependencies": {
"@cool-midway/core": "^6.0.0",
"@cool-midway/core": "7.0.0-beta3",
"@midwayjs/cli": "^1.2.38",
"@midwayjs/core": "^3.0.0",
"@midwayjs/decorator": "^3.0.0",

View File

@ -1,6 +1,6 @@
{
"name": "@cool-midway/file",
"version": "6.0.2",
"version": "7.0.0-beta2",
"description": "",
"main": "dist/index.js",
"typings": "index.d.ts",
@ -27,7 +27,7 @@
"url": "https://cool-js.com"
},
"devDependencies": {
"@cool-midway/core": "^6.0.0",
"@cool-midway/core": "7.0.0-beta2",
"@midwayjs/cli": "^2.0.9",
"@midwayjs/core": "^3.9.0",
"@midwayjs/decorator": "^3.9.0",
@ -42,6 +42,8 @@
"typescript": "^4.9.4"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.414.0",
"@aws-sdk/s3-presigned-post": "^3.414.0",
"@midwayjs/upload": "^3.9.9",
"ali-oss": "^6.17.1",
"cos-nodejs-sdk-v5": "^2.11.19",

View File

@ -21,6 +21,8 @@ import * as STS from 'qcloud-cos-sts';
import * as download from 'download';
import * as COS from 'cos-nodejs-sdk-v5';
import * as QINIU from 'qiniu';
import { S3Client, PutObjectCommand } from '@aws-sdk/client-s3';
import { createPresignedPost } from '@aws-sdk/s3-presigned-post';
/**
*
@ -34,7 +36,7 @@ export class CoolFile {
@Logger()
coreLogger: ILogger;
client: OSS & COS & QINIU.auth.digest.Mac;
client: OSS & COS & QINIU.auth.digest.Mac & S3Client;
@App()
app: IMidwayApplication;
@ -53,7 +55,7 @@ export class CoolFile {
if (config) {
this.config = config;
}
const { mode, oss, cos, qiniu } = this.config;
const { mode, oss, cos, qiniu, aws } = this.config;
if (mode == MODETYPE.CLOUD) {
if (oss) {
const { accessKeyId, accessKeySecret, bucket, endpoint } = oss;
@ -75,6 +77,13 @@ export class CoolFile {
const { accessKeyId, accessKeySecret } = qiniu;
this.client = new QINIU.auth.digest.Mac(accessKeyId, accessKeySecret);
}
if (aws) {
const { accessKeyId, secretAccessKey, region } = aws;
this.client = new S3Client({
region,
credentials: { accessKeyId, secretAccessKey },
});
}
}
}
@ -83,7 +92,7 @@ export class CoolFile {
* @returns
*/
async getMode(): Promise<Mode> {
const { mode, oss, cos, qiniu } = this.config;
const { mode, oss, cos, qiniu, aws } = this.config;
if (mode == MODETYPE.LOCAL) {
return {
mode: MODETYPE.LOCAL,
@ -108,13 +117,19 @@ export class CoolFile {
type: CLOUDTYPE.QINIU,
};
}
if (aws) {
return {
mode: MODETYPE.CLOUD,
type: CLOUDTYPE.AWS,
};
}
}
/**
*
* @returns
*/
getMetaFileObj(): OSS & COS & QINIU.auth.digest.Mac {
getMetaFileObj(): OSS & COS & QINIU.auth.digest.Mac & S3Client {
return this.client;
}
@ -124,7 +139,7 @@ export class CoolFile {
* @param fileName
*/
async downAndUpload(url: string, fileName?: string) {
const { mode, oss, cos, qiniu, domain } = this.config;
const { mode, oss, cos, qiniu, aws, domain } = this.config;
let extend = '';
if (url.includes('.')) {
const urlArr = url.split('.');
@ -164,6 +179,20 @@ export class CoolFile {
});
return cos.publicDomain + '/' + name;
}
if (aws) {
const { bucket, fields, region, publicDomain } = aws;
const uploadParams = {
Bucket: bucket,
Key: name,
Body: data,
ACL: fields ? fields.acl : 'public-read',
};
const command = new PutObjectCommand(uploadParams);
await this.client.send(command);
return publicDomain
? `${publicDomain}/${name}`
: `https://${bucket}.s3.${region}.amazonaws.com/${name}`;
}
if (qiniu) {
let uploadToken = (await this.qiniu())['token'];
const formUploader = new QINIU.form_up.FormUploader();
@ -196,12 +225,12 @@ export class CoolFile {
/**
* Key()
* @param file
* @param filePath
* @param key
*/
async uploadWithKey(file, key) {
const { mode, oss, cos, qiniu } = this.config;
const data = fs.readFileSync(file.data);
async uploadWithKey(filePath, key) {
const { mode, oss, cos, qiniu, aws } = this.config;
const data = fs.readFileSync(filePath);
if (mode == MODETYPE.LOCAL) {
fs.writeFileSync(path.join(this.app.getBaseDir(), '..', key), data);
return this.config.domain + key;
@ -242,6 +271,20 @@ export class CoolFile {
);
});
}
if (aws) {
const { bucket, fields, region, publicDomain } = aws;
const uploadParams = {
Bucket: bucket,
Key: key,
Body: data,
ACL: fields ? fields.acl : 'public-read',
};
const command = new PutObjectCommand(uploadParams);
await this.client.send(command);
return publicDomain
? `${publicDomain}/${key}`
: `https://${bucket}.s3.${region}.amazonaws.com/${key}`;
}
}
}
@ -251,7 +294,7 @@ export class CoolFile {
* @param key
*/
async upload(ctx) {
const { mode, oss, cos, qiniu } = this.config;
const { mode, oss, cos, qiniu, aws } = this.config;
if (mode == MODETYPE.LOCAL) {
return await this.local(ctx);
}
@ -265,9 +308,42 @@ export class CoolFile {
if (qiniu) {
return await this.qiniu(ctx);
}
if (aws) {
return await this.aws(ctx);
}
}
}
/**
* aws
* @param ctx
*/
private async aws(ctx) {
let {
bucket,
fields = {},
conditions = [],
expires = 3600,
} = this.config.aws;
const { key } = ctx.request.body;
if (!conditions) {
conditions = [{ acl: 'public-read' }, { bucket }];
}
if (!fields) {
fields = {
acl: 'public-read',
};
}
const result = await createPresignedPost(this.client, {
Bucket: bucket,
Key: key,
Conditions: conditions,
Fields: fields,
Expires: expires,
});
return result;
}
/**
*
* @param ctx

View File

@ -15,6 +15,8 @@ export enum CLOUDTYPE {
COS = 'cos',
// 七牛云存储
QINIU = 'qiniu',
/** AWS S3 */
AWS = 'aws',
}
/**
@ -39,6 +41,8 @@ export interface CoolFileConfig {
cos: COSConfig;
// 七牛云 配置
qiniu: QINIUConfig;
/** AWS s3 配置 */
aws: AWSConfig;
// 文件前缀
domain: string;
}
@ -87,6 +91,25 @@ export interface COSConfig {
allowActions?: string[];
}
export interface AWSConfig {
/** accessKeyId */
accessKeyId: string;
/** secretAccessKey */
secretAccessKey: string;
/** bucket */
bucket: string;
/** region */
region: string;
/** fields */
fields?: any;
/** conditions */
conditions?: any[];
/** expires */
expires?: number;
/** publicDomain */
publicDomain?: string;
}
export interface QINIUConfig {
// 七牛云accessKeyId
accessKeyId: string;

View File

@ -1,6 +1,6 @@
{
"name": "@cool-midway/file",
"version": "6.0.2",
"version": "7.0.0-beta2",
"description": "",
"main": "index.js",
"typings": "index.d.ts",
@ -47,6 +47,8 @@
"cos-nodejs-sdk-v5": "^2.11.19",
"download": "^8.0.0",
"qcloud-cos-sts": "^3.1.0",
"qiniu": "^7.8.0"
"qiniu": "^7.8.0",
"@aws-sdk/client-s3": "^3.414.0",
"@aws-sdk/s3-presigned-post": "^3.414.0"
}
}

View File

@ -1,6 +1,6 @@
{
"name": "@cool-midway/iot",
"version": "6.0.0",
"version": "7.0.0-beta1",
"description": "cool-js.com iot模块",
"main": "dist/index.js",
"typings": "index.d.ts",
@ -30,7 +30,7 @@
"index.d.ts"
],
"devDependencies": {
"@cool-midway/core": "6.0.0",
"@cool-midway/core": "7.0.0-beta3",
"@midwayjs/cli": "^2.0.9",
"@midwayjs/core": "^3.9.0",
"@midwayjs/decorator": "^3.9.0",

View File

@ -1,6 +1,6 @@
{
"name": "@cool-midway/iot",
"version": "6.0.0",
"version": "7.0.0-beta1",
"description": "cool-js.com iot模块",
"main": "index.js",
"typings": "index.d.ts",
@ -30,7 +30,7 @@
"index.d.ts"
],
"devDependencies": {
"@cool-midway/core": "^6.0.0",
"@cool-midway/core": "7.0.0-beta3",
"@midwayjs/cli": "^2.0.9",
"@midwayjs/core": "^3.9.0",
"@midwayjs/decorator": "^3.9.0",

View File

@ -1,6 +1,6 @@
{
"name": "@cool-midway/cache-manager-fs-hash",
"version": "6.0.0",
"version": "7.0.0-beta1",
"main": "index.js",
"engines": {
"node": ">=8.0.0"

View File

@ -1,6 +1,6 @@
{
"name": "@cool-midway/mqemitter-redis",
"version": "6.0.0",
"version": "7.0.0-beta1",
"description": "Redis-based MQEmitter",
"main": "mqemitter-redis.js",
"types": "types/index.d.ts",

View File

@ -1,6 +1,6 @@
{
"name": "@cool-midway/pay",
"version": "6.0.0",
"version": "7.0.0-beta1",
"description": "cool-js.com 支付 微信 支付宝",
"main": "dist/index.js",
"typings": "index.d.ts",
@ -28,7 +28,7 @@
"url": "https://cool-js.com"
},
"devDependencies": {
"@cool-midway/core": "^6.0.0",
"@cool-midway/core": "7.0.0-beta3",
"@midwayjs/cli": "^2.0.9",
"@midwayjs/core": "^3.9.0",
"@midwayjs/decorator": "^3.9.0",

View File

@ -1,6 +1,6 @@
{
"name": "@cool-midway/pay",
"version": "6.0.0",
"version": "7.0.0-beta1",
"description": "cool-js.com 支付 微信 支付宝",
"main": "index.js",
"typings": "index.d.ts",
@ -28,7 +28,7 @@
"url": "https://cool-js.com"
},
"devDependencies": {
"@cool-midway/core": "^6.0.0",
"@cool-midway/core": "7.0.0-beta3",
"@midwayjs/cli": "^2.0.9",
"@midwayjs/core": "^3.9.0",
"@midwayjs/decorator": "^3.9.0",

View File

@ -1,6 +1,6 @@
{
"name": "@cool-midway/rpc",
"version": "6.0.1",
"version": "7.0.0-beta1",
"description": "cool-js.com rpc 微服务",
"main": "dist/index.js",
"typings": "index.d.ts",
@ -23,7 +23,7 @@
},
"license": "MIT",
"devDependencies": {
"@cool-midway/core": "^6.0.0",
"@cool-midway/core": "7.0.0-beta3",
"@midwayjs/cli": "^2.0.9",
"@midwayjs/core": "^3.9.0",
"@midwayjs/decorator": "^3.9.0",

View File

@ -1,6 +1,6 @@
{
"name": "@cool-midway/rpc",
"version": "6.0.1",
"version": "7.0.0-beta1",
"description": "cool-js.com rpc 微服务",
"main": "index.js",
"typings": "index.d.ts",
@ -23,7 +23,7 @@
},
"license": "MIT",
"devDependencies": {
"@cool-midway/core": "^6.0.0",
"@cool-midway/core": "7.0.0-beta3",
"@midwayjs/cli": "^2.0.9",
"@midwayjs/core": "^3.9.0",
"@midwayjs/decorator": "^3.9.0",

View File

@ -1,6 +1,6 @@
{
"name": "@cool-midway/sms",
"version": "6.0.1",
"version": "7.0.0-beta1",
"description": "cool-js.com 短信",
"main": "dist/index.js",
"typings": "index.d.ts",
@ -28,7 +28,7 @@
"url": "https://cool-js.com"
},
"devDependencies": {
"@cool-midway/core": "^6.0.0",
"@cool-midway/core": "7.0.0-beta3",
"@midwayjs/cli": "^2.0.9",
"@midwayjs/core": "^3.9.0",
"@midwayjs/decorator": "^3.9.0",
@ -39,6 +39,7 @@
"jest": "^29.3.1",
"mwts": "^1.3.0",
"ts-jest": "^29.0.3",
"axios": "^1.5.0",
"typescript": "^4.9.4"
},
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "@cool-midway/sms",
"version": "6.0.1",
"version": "7.0.0-beta1",
"description": "cool-js.com 短信",
"main": "index.js",
"typings": "index.d.ts",
@ -28,7 +28,7 @@
"url": "https://cool-js.com"
},
"devDependencies": {
"@cool-midway/core": "^6.0.0",
"@cool-midway/core": "7.0.0-beta3",
"@midwayjs/cli": "^2.0.9",
"@midwayjs/core": "^3.9.0",
"@midwayjs/decorator": "^3.9.0",
@ -39,7 +39,8 @@
"jest": "^29.3.1",
"mwts": "^1.3.0",
"ts-jest": "^29.0.3",
"typescript": "^4.9.4"
"typescript": "^4.9.4",
"axios": "^1.5.0"
},
"dependencies": {
"@alicloud/pop-core": "^1.7.13",

View File

@ -1,6 +1,6 @@
{
"name": "@cool-midway/task",
"version": "6.0.0",
"version": "7.0.0-beta1",
"description": "cool-js.com 任务与队列",
"main": "dist/index.js",
"typings": "index.d.ts",
@ -28,7 +28,7 @@
"url": "https://cool-js.com"
},
"devDependencies": {
"@cool-midway/core": "^6.0.0",
"@cool-midway/core": "7.0.0-beta3",
"@midwayjs/cli": "^2.0.9",
"@midwayjs/core": "^3.9.0",
"@midwayjs/decorator": "^3.9.0",

View File

@ -1,6 +1,6 @@
{
"name": "@cool-midway/task",
"version": "6.0.0",
"version": "7.0.0-beta1",
"description": "cool-js.com 任务与队列",
"main": "index.js",
"typings": "index.d.ts",
@ -28,7 +28,7 @@
"url": "https://cool-js.com"
},
"devDependencies": {
"@cool-midway/core": "^6.0.0",
"@cool-midway/core": "7.0.0-beta3",
"@midwayjs/cli": "^2.0.9",
"@midwayjs/core": "^3.9.0",
"@midwayjs/decorator": "^3.9.0",