mirror of
https://github.com/crystelf/crystelf-core.git
synced 2025-07-04 14:49:19 +00:00
重构项目,模块化项目
This commit is contained in:
parent
20a932fd47
commit
42ee17a1ff
@ -2,11 +2,11 @@ import express from 'express';
|
|||||||
import compression from 'compression';
|
import compression from 'compression';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import logger from './utils/core/logger';
|
import logger from './utils/system/logger';
|
||||||
import paths from './utils/core/path';
|
import paths from './utils/system/path';
|
||||||
import config from './utils/core/config';
|
import config from './utils/system/config';
|
||||||
import './services/ws/wsServer';
|
import './services/ws/wsServer';
|
||||||
import System from './utils/core/system';
|
import System from './utils/system/system';
|
||||||
|
|
||||||
const apps = {
|
const apps = {
|
||||||
async createApp() {
|
async createApp() {
|
@ -1,7 +1,7 @@
|
|||||||
import Redis from 'ioredis';
|
import Redis from 'ioredis';
|
||||||
import logger from '../../utils/core/logger';
|
import logger from '../../utils/system/logger';
|
||||||
import tools from '../../utils/core/tool';
|
import tools from '../../utils/system/tool';
|
||||||
import config from '../../utils/core/config';
|
import config from '../../utils/system/config';
|
||||||
import redisTools from '../../utils/redis/redisTools';
|
import redisTools from '../../utils/redis/redisTools';
|
||||||
import Persistence from '../../utils/redis/persistence';
|
import Persistence from '../../utils/redis/persistence';
|
||||||
import IUser from '../../types/user';
|
import IUser from '../../types/user';
|
@ -1,7 +1,7 @@
|
|||||||
import { AuthenticatedSocket } from '../../types/ws';
|
import { AuthenticatedSocket } from '../../types/ws';
|
||||||
import wsTools from '../../utils/ws/wsTools';
|
import wsTools from '../../utils/ws/wsTools';
|
||||||
import { WebSocket } from 'ws';
|
import { WebSocket } from 'ws';
|
||||||
import logger from '../../utils/core/logger';
|
import logger from '../../utils/system/logger';
|
||||||
import redisService from '../redis/redis';
|
import redisService from '../redis/redis';
|
||||||
import wsClientManager from './wsClientManager';
|
import wsClientManager from './wsClientManager';
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
import WebSocket, { WebSocketServer } from 'ws';
|
import WebSocket, { WebSocketServer } from 'ws';
|
||||||
import config from '../../utils/core/config';
|
import config from '../../utils/system/config';
|
||||||
import logger from '../../utils/core/logger';
|
import logger from '../../utils/system/logger';
|
||||||
import { AuthenticatedSocket, AuthMessage, WSMessage } from '../../types/ws';
|
import { AuthenticatedSocket, AuthMessage, WSMessage } from '../../types/ws';
|
||||||
import WsTools from '../../utils/ws/wsTools';
|
import WsTools from '../../utils/ws/wsTools';
|
||||||
import wsHandler from './handler';
|
import wsHandler from './handler';
|
@ -1,6 +1,6 @@
|
|||||||
import express from 'express';
|
import express from 'express';
|
||||||
import response from '../core/response';
|
import response from '../system/response';
|
||||||
import Config from '../core/config';
|
import Config from '../system/config';
|
||||||
|
|
||||||
let tools = {
|
let tools = {
|
||||||
/**
|
/**
|
@ -1,7 +1,7 @@
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import paths from '../core/path';
|
import paths from '../system/path';
|
||||||
import fc from '../core/file';
|
import fc from '../system/file';
|
||||||
import logger from '../core/logger';
|
import logger from '../system/logger';
|
||||||
import fs from 'fs/promises';
|
import fs from 'fs/promises';
|
||||||
|
|
||||||
class Persistence {
|
class Persistence {
|
@ -1,4 +1,4 @@
|
|||||||
import logger from '../core/logger';
|
import logger from '../system/logger';
|
||||||
|
|
||||||
class redisTools {
|
class redisTools {
|
||||||
public static serialize<T>(data: T): string {
|
public static serialize<T>(data: T): string {
|
@ -1,5 +1,5 @@
|
|||||||
import WebSocket from 'ws';
|
import WebSocket from 'ws';
|
||||||
import logger from '../core/logger';
|
import logger from '../system/logger';
|
||||||
import { setInterval } from 'node:timers';
|
import { setInterval } from 'node:timers';
|
||||||
|
|
||||||
class WsTools {
|
class WsTools {
|
12
src/main.ts
12
src/main.ts
@ -1,9 +1,9 @@
|
|||||||
import apps from './app';
|
import apps from './core/app';
|
||||||
import logger from './utils/core/logger';
|
import logger from './core/utils/system/logger';
|
||||||
import config from './utils/core/config';
|
import config from './core/utils/system/config';
|
||||||
import redis from './services/redis/redis';
|
import redis from './core/services/redis/redis';
|
||||||
import autoUpdater from './utils/core/autoUpdater';
|
import autoUpdater from './core/utils/system/autoUpdater';
|
||||||
import System from './utils/core/system';
|
import System from './core/utils/system/system';
|
||||||
|
|
||||||
config.check(['PORT', 'DEBUG', 'RD_PORT', 'RD_ADD', 'WS_SECRET', 'WS_PORT']);
|
config.check(['PORT', 'DEBUG', 'RD_PORT', 'RD_ADD', 'WS_SECRET', 'WS_PORT']);
|
||||||
const PORT = config.get('PORT') || 3000;
|
const PORT = config.get('PORT') || 3000;
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import express from 'express';
|
import express from 'express';
|
||||||
import response from '../../utils/core/response';
|
import response from '../../core/utils/system/response';
|
||||||
import BotService from './bot.service';
|
import BotService from './bot.service';
|
||||||
import tools from '../../utils/modules/tools';
|
import tools from '../../core/utils/modules/tools';
|
||||||
import logger from '../../utils/core/logger';
|
import logger from '../../core/utils/system/logger';
|
||||||
import wsClientManager from '../../services/ws/wsClientManager';
|
import wsClientManager from '../../core/services/ws/wsClientManager';
|
||||||
|
|
||||||
class BotController {
|
class BotController {
|
||||||
private readonly router: express.Router;
|
private readonly router: express.Router;
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import logger from '../../utils/core/logger';
|
import logger from '../../core/utils/system/logger';
|
||||||
import paths from '../../utils/core/path';
|
import paths from '../../core/utils/system/path';
|
||||||
import fs from 'fs/promises';
|
import fs from 'fs/promises';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import redisService from '../../services/redis/redis';
|
import redisService from '../../core/services/redis/redis';
|
||||||
import wsClientManager from '../../services/ws/wsClientManager';
|
import wsClientManager from '../../core/services/ws/wsClientManager';
|
||||||
import tools from '../../utils/core/tool';
|
import tools from '../../core/utils/system/tool';
|
||||||
|
|
||||||
class BotService {
|
class BotService {
|
||||||
/**
|
/**
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import express from 'express';
|
import express from 'express';
|
||||||
import FileService from './file.service';
|
import FileService from './file.service';
|
||||||
import logger from '../../utils/core/logger';
|
import logger from '../../core/utils/system/logger';
|
||||||
import response from '../../utils/core/response';
|
import response from '../../core/utils/system/response';
|
||||||
import paths from '../../utils/core/path';
|
import paths from '../../core/utils/system/path';
|
||||||
import multer from 'multer';
|
import multer from 'multer';
|
||||||
import tools from '../../utils/modules/tools';
|
import tools from '../../core/utils/modules/tools';
|
||||||
|
|
||||||
const uploadDir = paths.get('uploads');
|
const uploadDir = paths.get('uploads');
|
||||||
const upload = multer({
|
const upload = multer({
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import fs from 'fs/promises';
|
import fs from 'fs/promises';
|
||||||
import paths from '../../utils/core/path';
|
import paths from '../../core/utils/system/path';
|
||||||
import logger from '../../utils/core/logger';
|
import logger from '../../core/utils/system/logger';
|
||||||
import { existsSync } from 'fs';
|
import { existsSync } from 'fs';
|
||||||
|
|
||||||
class FileService {
|
class FileService {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import express from 'express';
|
import express from 'express';
|
||||||
import sampleService from './sample.service';
|
import sampleService from './sample.service';
|
||||||
import response from '../../utils/core/response';
|
import response from '../../core/utils/system/response';
|
||||||
|
|
||||||
class SampleController {
|
class SampleController {
|
||||||
private readonly router: express.Router;
|
private readonly router: express.Router;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import logger from '../../utils/core/logger';
|
import logger from '../../core/utils/system/logger';
|
||||||
|
|
||||||
class SampleService {
|
class SampleService {
|
||||||
public async getHello() {
|
public async getHello() {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import express from 'express';
|
import express from 'express';
|
||||||
import tools from '../../utils/modules/tools';
|
import tools from '../../core/utils/modules/tools';
|
||||||
import response from '../../utils/core/response';
|
import response from '../../core/utils/system/response';
|
||||||
import SystemService from './system.service';
|
import SystemService from './system.service';
|
||||||
|
|
||||||
class SystemController {
|
class SystemController {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import System from '../../utils/core/system';
|
import System from '../../core/utils/system/system';
|
||||||
import fs from 'fs/promises';
|
import fs from 'fs/promises';
|
||||||
import logger from '../../utils/core/logger';
|
import logger from '../../core/utils/system/logger';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import paths from '../../utils/core/path';
|
import paths from '../../core/utils/system/path';
|
||||||
|
|
||||||
class SystemService {
|
class SystemService {
|
||||||
public async systemRestart() {
|
public async systemRestart() {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import express from 'express';
|
import express from 'express';
|
||||||
import TestService from './test.service';
|
import TestService from './test.service';
|
||||||
import response from '../../utils/core/response';
|
import response from '../../core/utils/system/response';
|
||||||
import logger from '../../utils/core/logger';
|
import logger from '../../core/utils/system/logger';
|
||||||
|
|
||||||
class TestController {
|
class TestController {
|
||||||
private readonly router: express.Router;
|
private readonly router: express.Router;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import wsClientManager from '../../services/ws/wsClientManager';
|
import wsClientManager from '../../core/services/ws/wsClientManager';
|
||||||
import logger from '../../utils/core/logger';
|
import logger from '../../core/utils/system/logger';
|
||||||
|
|
||||||
class TestService {
|
class TestService {
|
||||||
public async test() {
|
public async test() {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import express from 'express';
|
import express from 'express';
|
||||||
import WordsService from './words.service';
|
import WordsService from './words.service';
|
||||||
import response from '../../utils/core/response';
|
import response from '../../core/utils/system/response';
|
||||||
import tools from '../../utils/modules/tools';
|
import tools from '../../core/utils/modules/tools';
|
||||||
|
|
||||||
class WordsController {
|
class WordsController {
|
||||||
private readonly router: express.Router;
|
private readonly router: express.Router;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import paths from '../../utils/core/path';
|
import paths from '../../core/utils/system/path';
|
||||||
import fs from 'fs/promises';
|
import fs from 'fs/promises';
|
||||||
import logger from '../../utils/core/logger';
|
import logger from '../../core/utils/system/logger';
|
||||||
|
|
||||||
class WordsService {
|
class WordsService {
|
||||||
private wordCache: Record<string, string[]> = {}; //缓存
|
private wordCache: Record<string, string[]> = {}; //缓存
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import WebSocket from 'ws';
|
import WebSocket from 'ws';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import logger from '../utils/core/logger';
|
import logger from '../core/utils/system/logger';
|
||||||
|
|
||||||
const WS_URL = 'ws://127.0.0.1:4001';
|
const WS_URL = 'ws://127.0.0.1:4001';
|
||||||
const WS_SECRET = '114514';
|
const WS_SECRET = '114514';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user