first commit

This commit is contained in:
编码猿
2024-09-27 02:06:13 +08:00
commit 852d94fbb9
36760 changed files with 3274413 additions and 0 deletions

View File

@@ -0,0 +1 @@
690abbe8-c996-435b-aa38-7642e18ab4e8

View File

@@ -0,0 +1 @@
174c0f33-e8e4-47e7-9485-4f3252f4ea74

View File

@@ -0,0 +1,46 @@
const crypto = require("crypto-js");
class uploadOssHelper {
constructor(options) {
this.accessKeyId = options.accessKeyId;
this.accessKeySecret = options.accessKeySecret;
// 限制参数的生效时间单位为小时默认值为1。
this.timeout = options.timeout || 1;
// 限制上传文件的大小单位为MB默认值为10。
this.maxSize = options.maxSize || 10;
}
createUploadParams() {
const policy = this.getPolicyBase64();
const signature = this.signature(policy);
return {
OSSAccessKeyId: this.accessKeyId,
policy: policy,
signature: signature,
};
}
getPolicyBase64() {
let date = new Date();
// 设置policy过期时间。
date.setHours(date.getHours() + this.timeout);
let srcT = date.toISOString();
const policyText = {
expiration: srcT,
conditions: [
// 限制上传文件大小。
["content-length-range", 0, this.maxSize * 1024 * 1024],
],
};
const buffer = new Buffer(JSON.stringify(policyText));
return buffer.toString("base64");
}
signature(policy) {
return crypto.enc.Base64.stringify(
crypto.HmacSHA1(policy, this.accessKeySecret)
);
}
}
module.exports = uploadOssHelper;

View File

@@ -0,0 +1,51 @@
var md5 = require("md5");
class Utils {
Md5Password(str) {
return md5(str);
}
uuid(prefix = "", randomLength = 6) {
// 兼容更低版本的默认值写法
prefix === undefined ? prefix = "" : prefix;
randomLength === undefined ? randomLength = 8 : randomLength;
// 设置随机用户名
// 用户名随机词典数组
let nameArr = [
[1, 2, 3, 4, 5, 6, 7, 8, 9, 0],
["a", "b", "c", "d", "e", "f", "g", "h", "i", "g", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
]
// 随机名字字符串
let name = prefix;
// 循环遍历从用户词典中随机抽出一个
for (var i = 0; i < randomLength; i++) {
// 随机生成index
let index = Math.floor(Math.random() * 2);
let zm = nameArr[index][Math.floor(Math.random() * nameArr[index].length)];
// 如果随机出的是英文字母
if (index === 1) {
// 则百分之50的概率变为大写
if (Math.floor(Math.random() * 2) === 1) {
zm = zm.toUpperCase();
}
}
// 拼接进名字变量中
name += zm;
}
// 将随机生成的名字返回
return name;
}
getTime() {
var year = new Date().getFullYear();
var month = new Date().getMonth() + 1;
var day = new Date().getDate();
var hour = new Date().getHours();
var minute = new Date().getMinutes();
return `${year}${month}${day}${hour}:${minute}`
}
}
module.exports = new Utils()