NineAI 2.4.2

This commit is contained in:
vastxie
2024-01-17 09:22:28 +08:00
commit bdc48207fc
636 changed files with 41864 additions and 0 deletions

26
dist/common/utils/base.js vendored Normal file
View File

@@ -0,0 +1,26 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.decrypt = exports.encrypt = void 0;
const crypto = require("crypto");
const encryptionKey = 'bf3c116f2470cb4che9071240917c171';
const initializationVector = '518363fh72eec1v4';
const algorithm = 'aes-256-cbc';
function encrypt(text) {
const cipher = crypto.createCipheriv(algorithm, encryptionKey, initializationVector);
let encrypted = cipher.update(text, 'utf8', 'base64');
encrypted += cipher.final('base64');
return encrypted;
}
exports.encrypt = encrypt;
function decrypt(text) {
try {
const decipher = crypto.createDecipheriv(algorithm, encryptionKey, initializationVector);
let decrypted = decipher.update(text, 'base64', 'utf8');
decrypted += decipher.final('utf8');
return decrypted;
}
catch (error) {
process.exit(1);
}
}
exports.decrypt = decrypt;

27
dist/common/utils/compileNetwork.js vendored Normal file
View File

@@ -0,0 +1,27 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.compileNetwork = void 0;
const axios_1 = require("axios");
function formatSearchData(searchData, question) {
const formatStr = searchData.map(({ title, body, href }) => `'${title}' : ${body} ;`).join('\n\n');
const instructions = 'Instructions: Reply to me in the language of my request or question above. Give a comprehensive answer to the question or request I have made above. Below are some results from a web search. Use the following results to summarize the answers \n\n';
return `${question}\n\n${instructions}\n${formatStr}`;
}
async function compileNetwork(question, limit = 7) {
let searchData = [];
try {
const responseData = await axios_1.default.get(`https://s0.awsl.app/search?q=${question}&max_results=${limit}`);
searchData = responseData.data;
}
catch (error) {
console.log('error: ', error);
searchData = [];
}
if (searchData.length === 0) {
return question;
}
else {
return formatSearchData(searchData, question);
}
}
exports.compileNetwork = compileNetwork;

8
dist/common/utils/createOrderId.js vendored Normal file
View File

@@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createOrderId = void 0;
const uuid_1 = require("uuid");
function createOrderId() {
return (0, uuid_1.v1)().toString().replace(/-/g, '');
}
exports.createOrderId = createOrderId;

9
dist/common/utils/createRandomCode.js vendored Normal file
View File

@@ -0,0 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createRandomCode = void 0;
function createRandomCode() {
const min = 100000;
const max = 999999;
return Math.floor(Math.random() * (max - min + 1) + min);
}
exports.createRandomCode = createRandomCode;

View File

@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateRandomString = void 0;
function generateRandomString() {
const length = 10;
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
let result = '';
for (let i = 0; i < length; i++) {
const randomIndex = Math.floor(Math.random() * characters.length);
result += characters.charAt(randomIndex);
}
return result;
}
exports.generateRandomString = generateRandomString;

View File

@@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createRandomNonceStr = void 0;
function createRandomNonceStr(len) {
const data = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
let str = '';
for (let i = 0; i < len; i++) {
str += data.charAt(parseInt((Math.random() * data.length).toFixed(0), 10));
}
return str;
}
exports.createRandomNonceStr = createRandomNonceStr;

9
dist/common/utils/createRandomUid.js vendored Normal file
View File

@@ -0,0 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createRandomUid = void 0;
const guid_typescript_1 = require("guid-typescript");
function createRandomUid() {
const uuid = guid_typescript_1.Guid.create();
return uuid.toString().substr(0, 10).replace('-', '');
}
exports.createRandomUid = createRandomUid;

43
dist/common/utils/date.js vendored Normal file
View File

@@ -0,0 +1,43 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isExpired = exports.formatCreateOrUpdateDate = exports.formatDate = void 0;
const dayjs = require("dayjs");
require("dayjs/locale/zh-cn");
const a = require("dayjs/plugin/utc");
const b = require("dayjs/plugin/timezone");
dayjs.locale('zh-cn');
dayjs.extend(a);
dayjs.extend(b);
dayjs.tz.setDefault('Asia/Shanghai');
function formatDate(date, format = 'YYYY-MM-DD HH:mm:ss') {
return dayjs(date).format(format);
}
exports.formatDate = formatDate;
function formatCreateOrUpdateDate(input, format = 'YYYY-MM-DD HH:mm:ss') {
if (Array.isArray(input)) {
return input.map((t) => {
t.createdAt = (t === null || t === void 0 ? void 0 : t.createdAt) ? dayjs(t.createdAt).format(format) : dayjs().format(format);
t.updatedAt = (t === null || t === void 0 ? void 0 : t.updatedAt) ? dayjs(t.updatedAt).format(format) : dayjs().format(format);
return t;
});
}
else {
let obj = {};
try {
obj = JSON.parse(JSON.stringify(input));
}
catch (error) {
}
(obj === null || obj === void 0 ? void 0 : obj.createdAt) && (obj.createdAt = dayjs(obj.createdAt).format(format));
(obj === null || obj === void 0 ? void 0 : obj.updatedAt) && (obj.updatedAt = dayjs(obj.updatedAt).format(format));
return obj;
}
}
exports.formatCreateOrUpdateDate = formatCreateOrUpdateDate;
function isExpired(createdAt, days) {
const expireDate = new Date(createdAt.getTime() + days * 24 * 60 * 60 * 1000);
const now = new Date();
return now > expireDate;
}
exports.isExpired = isExpired;
exports.default = dayjs;

14
dist/common/utils/encrypt.js vendored Normal file
View File

@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.copyRightMsg = exports.atob = void 0;
function atob(str) {
return Buffer.from(str, 'base64').toString('utf-8');
}
exports.atob = atob;
exports.copyRightMsg = [
'agxoTstMY8m+DJO89Iwy4zqcFTqlcj/Fa/erMTvn0IexetXaDttr4K/BN2+RbtfouXOeFjPDYnxOfQ+IIpuJ3PmtyHAzmlGFls/HvBDeh6EXAQ3waALbvK9Ue96soAb5/3Tv6VuZE7npISqXiYhI6Vqx4yDVYf6vUUkEO9jvVotWQkLOLkr6M/guLK6sik/ZOgHvSlDYKAv79NFJJ0Tt0WkH2SyN8l+woMiWVTOKkdE=',
'nXdXi8UU7J5av2eDOFjxQWlZDa+3bdASE4UwpqT6B11XSCweKKuzHxmFO2wx45iVlib/V0tt+NbEcOQZtzEWKqHsREkwEb5aqVCUl2Kj4nJeEFId2iyvY6MWEV1lHtCY+htpJoyqwQJc7yeNfpTl2SLBubWk77p4AHei1QFEs1rpOOwyE79lF0RqzY/Cpzhs',
'VjVCGib1VFp7hNynpKGQPUrX+ishpxi2u5a4txHXzk2nyUP1NZfIomEDmGhDTQ7VRJLox+8urtVG1CBBSct1v+4OA2ucAcDUFoy1H1Kl1z+dndVcNU6gz5YGnDppsxY8uGFAVGsWrDl2DIOKxk7kMURaRiQCXCHRF/3sLGyIEmE6KL9Q4kDInB6vuzBScxupFShMXTq2XrOhwRgn2elcig==',
'ZPcz1IaPDMGI3Yn9sm4QOT0qCZo7yZbJl4/c2RTrhUKINkjGB5yb0yN5vAnLtt/o8cmpoOoH3PUSOOWQa9aKD86NWK+1r8wBOVjwXZOpp2gbB1ZJLbWvjRbENvEJxVsLROXnpNDqUXVGxFMaIt+gmEi3Rp0thqC1soXUpvM1zqU4+LkQmunR7UytvzwXEmXBlIfPwz5hv+n/lxDsw526KWixC3jLLpeijw5433Zh7cI=',
'YPo1HNzS6p6190ku4f1PQENUBa/ip+v+6sPuQXVyAn3axo6SLKQBszNr3PAW2EzWhZLy2o+nBgr3o3IOy9OgNit1JHrCklpVp172wbGDKh8sB8HCXyJoRv3BaZVY5UhyhpV5K+4nPoM2RUwvIGONUGFPQfPQv9N8MS8UCL7UnWYcVLzxWo0ZDg+UXFRr7NhXKu7KQ7e1+Wiqm0qE+olfDVowi4pGDRGrYL154wEEJUo='
];

9
dist/common/utils/generateCrami.js vendored Normal file
View File

@@ -0,0 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateCramiCode = void 0;
const uuid_1 = require("uuid");
function generateCramiCode() {
const code = (0, uuid_1.v4)().replace(/-/g, '').slice(0, 16);
return code;
}
exports.generateCramiCode = generateCramiCode;

43
dist/common/utils/getClientIp.js vendored Normal file
View File

@@ -0,0 +1,43 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getClientIp = void 0;
function getClientIp(request) {
let ipAddress = '';
const headerList = [
'X-Client-IP',
'X-Real-IP',
'X-Forwarded-For',
'CF-Connecting-IP',
'True-Client-IP',
'X-Cluster-Client-IP',
'Proxy-Client-IP',
'WL-Proxy-Client-IP',
'HTTP_CLIENT_IP',
'HTTP_X_FORWARDED_FOR',
];
for (const header of headerList) {
const value = request.headers[header];
if (value && typeof value === 'string') {
const ips = value.split(',');
ipAddress = ips[0].trim();
break;
}
}
if (!ipAddress) {
ipAddress = request.connection.remoteAddress || '';
}
if (ipAddress && ipAddress.includes('::')) {
const isLocal = /^(::1|fe80(:1)?::1(%.*)?)$/i.test(ipAddress);
if (isLocal) {
ipAddress = '';
}
else if (ipAddress.includes('::ffff:')) {
ipAddress = ipAddress.split(':').pop() || '';
}
}
if (!ipAddress || !/\d+\.\d+\.\d+\.\d+/.test(ipAddress)) {
ipAddress = '';
}
return ipAddress;
}
exports.getClientIp = getClientIp;

15
dist/common/utils/getDiffArray.js vendored Normal file
View File

@@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDiffArray = void 0;
function getDiffArray(aLength, bLength, str) {
const a = Array.from({ length: aLength }, (_, i) => i + 1);
const b = Array.from({ length: bLength }, (_, i) => i + 1);
const diffArray = [];
for (let i = 0; i < a.length; i++) {
if (!b.includes(a[i])) {
diffArray.push(`${str}${a[i]}`);
}
}
return diffArray;
}
exports.getDiffArray = getDiffArray;

8
dist/common/utils/getRandomItem.js vendored Normal file
View File

@@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getRandomItem = void 0;
function getRandomItem(array) {
const randomIndex = Math.floor(Math.random() * array.length);
return array[randomIndex];
}
exports.getRandomItem = getRandomItem;

View File

@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getRandomItemFromArray = void 0;
function getRandomItemFromArray(array) {
if (array.length === 0) {
return null;
}
const randomIndex = Math.floor(Math.random() * array.length);
return array[randomIndex];
}
exports.getRandomItemFromArray = getRandomItemFromArray;

14
dist/common/utils/hideString.js vendored Normal file
View File

@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.hideString = void 0;
function hideString(input, str) {
const length = input.length;
const start = input.slice(0, (length - 10) / 2);
const end = input.slice((length + 10) / 2, length);
const hidden = '*'.repeat(10);
if (str) {
return `**********${str}**********`;
}
return `${start}${hidden}${end}`;
}
exports.hideString = hideString;

38
dist/common/utils/index.js vendored Normal file
View File

@@ -0,0 +1,38 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./date"), exports);
__exportStar(require("./createRandomCode"), exports);
__exportStar(require("./tools"), exports);
__exportStar(require("./createRandomInviteCode"), exports);
__exportStar(require("./maskEmail"), exports);
__exportStar(require("./createRandomUid"), exports);
__exportStar(require("./generateCrami"), exports);
__exportStar(require("./base"), exports);
__exportStar(require("./hideString"), exports);
__exportStar(require("./getDiffArray"), exports);
__exportStar(require("./getRandomItem"), exports);
__exportStar(require("./getClientIp"), exports);
__exportStar(require("./maskIpAddress"), exports);
__exportStar(require("./maskCrami"), exports);
__exportStar(require("./selectKeyWithWeight"), exports);
__exportStar(require("./createOrderId"), exports);
__exportStar(require("./createRandomNonceStr"), exports);
__exportStar(require("./utcformatTime"), exports);
__exportStar(require("./removeSpecialCharacters"), exports);
__exportStar(require("./encrypt"), exports);
__exportStar(require("./compileNetwork"), exports);
__exportStar(require("./getRandomItemFromArray"), exports);

11
dist/common/utils/maskCrami.js vendored Normal file
View File

@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.maskCrami = void 0;
function maskCrami(str) {
if (str.length !== 16) {
throw new Error('Invalid input');
}
const masked = str.substring(0, 6) + '****' + str.substring(10);
return masked;
}
exports.maskCrami = maskCrami;

16
dist/common/utils/maskEmail.js vendored Normal file
View File

@@ -0,0 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.maskEmail = void 0;
function maskEmail(email) {
if (!email)
return '';
const atIndex = email.indexOf('@');
if (atIndex <= 1) {
return email;
}
const firstPart = email.substring(0, atIndex - 1);
const lastPart = email.substring(atIndex);
const maskedPart = '*'.repeat(firstPart.length - 1);
return `${firstPart.charAt(0)}${maskedPart}${email.charAt(atIndex - 1)}${lastPart}`;
}
exports.maskEmail = maskEmail;

11
dist/common/utils/maskIpAddress.js vendored Normal file
View File

@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.maskIpAddress = void 0;
function maskIpAddress(ipAddress) {
if (!ipAddress)
return '';
const ipArray = ipAddress.split('.');
ipArray[2] = '***';
return ipArray.join('.');
}
exports.maskIpAddress = maskIpAddress;

View File

@@ -0,0 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.removeSpecialCharacters = void 0;
function removeSpecialCharacters(inputString) {
return inputString.replace(/[^\w\s-]/g, '');
}
exports.removeSpecialCharacters = removeSpecialCharacters;

View File

@@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.selectKeyWithWeight = void 0;
function selectKeyWithWeight(data) {
if (data.length === 0)
return undefined;
const totalWeight = data.reduce((sum, item) => sum + item.weight, 0);
let randomWeight = Math.random() * totalWeight;
for (const item of data) {
randomWeight -= item.weight;
if (randomWeight < 0) {
return item;
}
}
return data[data.length - 1];
}
exports.selectKeyWithWeight = selectKeyWithWeight;

8
dist/common/utils/tools.js vendored Normal file
View File

@@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.importDynamic = exports.isNotEmptyString = void 0;
function isNotEmptyString(value) {
return typeof value === 'string' && value.length > 0;
}
exports.isNotEmptyString = isNotEmptyString;
exports.importDynamic = new Function('modulePath', 'return import(modulePath)');

16
dist/common/utils/utcformatTime.js vendored Normal file
View File

@@ -0,0 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.utcToShanghaiTime = void 0;
function utcToShanghaiTime(utcTime, format = 'YYYY/MM/DD hh:mm:ss') {
const date = new Date(utcTime);
const shanghaiTime = date.getTime() + 8 * 60 * 60 * 1000;
const shanghaiDate = new Date(shanghaiTime);
let result = format.replace('YYYY', shanghaiDate.getFullYear().toString());
result = result.replace('MM', `0${shanghaiDate.getMonth() + 1}`.slice(-2));
result = result.replace('DD', `0${shanghaiDate.getDate()}`.slice(-2));
result = result.replace('hh', `0${shanghaiDate.getHours()}`.slice(-2));
result = result.replace('mm', `0${shanghaiDate.getMinutes()}`.slice(-2));
result = result.replace('ss', `0${shanghaiDate.getSeconds()}`.slice(-2));
return result;
}
exports.utcToShanghaiTime = utcToShanghaiTime;