Skip to content

Commit

Permalink
优化项目结构
Browse files Browse the repository at this point in the history
  • Loading branch information
SunWuyuan committed Dec 14, 2024
1 parent 1f9c071 commit bd0ccc7
Show file tree
Hide file tree
Showing 27 changed files with 56 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .bin/www
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Module dependencies.
*/

import configManager from "../routes/configManager.js";
import configManager from "../utils/configManager.js";


// 使用 getConfig 函数获取配置
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,5 @@ dist
#!.env.project
#!.env.vault

.idea
.idea
.vscode
4 changes: 2 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import "dotenv/config";
import express from "express";
import jsonwebtoken from "jsonwebtoken";

import configManager from "./routes/configManager.js";
import logger from "./routes/lib/logger.js";
import configManager from "./utils/configManager.js";
import logger from "./utils/logger.js";

import expressWinston from "express-winston";
import cors from "cors";
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import logger from "../logger.js";
import logger from "../utils/logger.js";
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
import { getProjectsAndUsersByProjectsList } from "./projects.js";
Expand Down
2 changes: 1 addition & 1 deletion routes/lib/method/projects.js → controllers/projects.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import logger from "../logger.js";
import logger from "../utils/logger.js";
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
import { createHash } from "crypto";
Expand Down
2 changes: 1 addition & 1 deletion routes/lib/method/users.js → controllers/users.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import logger from "../logger.js";
import logger from "../utils/logger.js";
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();

Expand Down
4 changes: 2 additions & 2 deletions middleware/auth.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logger from "../routes/lib/logger.js";
import configManager from "../routes/configManager.js";
import logger from "../utils/logger.js";
import configManager from "../utils/configManager.js";

async function needlogin(req, res, next) {
if (!res.locals.login) {
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions routes/lib/captcha/geetest.js → middleware/geetest.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logger from "../logger.js";
import configManager from "../../configManager.js";
import logger from "../utils/logger.js";
import configManager from "../utils/configManager.js";

import express from "express";
import { parse } from "querystring";
Expand Down
9 changes: 0 additions & 9 deletions routes/lib/scratch_default_project.js

This file was deleted.

4 changes: 0 additions & 4 deletions routes/lib/scratch_default_sprite.js

This file was deleted.

16 changes: 8 additions & 8 deletions routes/router_account.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import logger from "./lib/logger.js";
import configManager from "./configManager.js";
import logger from "../utils/logger.js";
import configManager from "../utils/configManager.js";

import { Router } from "express";
var router = Router();
import jsonwebtoken from "jsonwebtoken";
import { qww, query } from "./lib/database.js";
import { userpwTest, emailTest, hash, checkhash, generateJwt, randomPassword, prisma } from "./lib/global.js";
import { sendEmail } from "./services/emailService.js";
import { registrationTemplate, passwordResetTemplate } from "./services/emailTemplates.js";
import { qww, query } from "../utils/database.js";
import { userpwTest, emailTest, hash, checkhash, generateJwt, randomPassword, prisma } from "../utils/global.js";
import { sendEmail } from "../utils/email/emailService.js";
import { registrationTemplate, passwordResetTemplate } from "../utils/email/emailTemplates.js";
import {needlogin} from "../middleware/auth.js";

import totpUtils from "./lib/totpUtils.js";
import totpUtils from "../utils/totp.js";
// { isTotpTokenValid, createTotpTokenForUser, enableTotpToken, removeTotpToken, validateTotpToken }
const { isTotpTokenValid, createTotpTokenForUser, enableTotpToken, removeTotpToken, validateTotpToken } = totpUtils;
router.all("*", function (req, res, next) {
next();
});


import geetest from "./lib/captcha/geetest.js";
import geetest from "../middleware/geetest.js";
router.post("/login", async function (req, res, next) {
try {
if (
Expand Down
8 changes: 4 additions & 4 deletions routes/router_api.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import logger from "./lib/logger.js";
import configManager from "./configManager.js";
import logger from "../utils/logger.js";
import configManager from "../utils/configManager.js";

import { Router } from "express";
var router = Router();
import fs from "fs";

import { prisma as _prisma } from "./lib/global.js";
import { query } from "./lib/database.js";
import { prisma as _prisma } from "../utils/global.js";
import { query } from "../utils/database.js";
import { needadmin } from "../middleware/auth.js";
router.get("/usertx", async function (req, res, next) {
try {
Expand Down
8 changes: 4 additions & 4 deletions routes/router_comment.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import logger from "./lib/logger.js";
import configManager from "./configManager.js";
import logger from "../utils/logger.js";
import configManager from "../utils/configManager.js";

import { Router } from "express";
const router = Router();
import { prisma } from "./lib/global.js";
import { getUsersByList } from "./lib/method/users.js";
import { prisma } from "../utils/global.js";
import { getUsersByList } from "../controllers/users.js";
// 中间件,确保所有请求均经过该处理
router.all("*", (req, res, next) => next());

Expand Down
10 changes: 5 additions & 5 deletions routes/router_my.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import logger from "./lib/logger.js";
import configManager from "./configManager.js";
import logger from "../utils/logger.js";
import configManager from "../utils/configManager.js";

//个人中心
import { Router } from "express";
var router = Router();
import { rename, createReadStream } from "fs";
import { createHash } from "crypto";
//功能函数集
import { msg_fail, S3update, checkhash, hash as _hash,prisma } from "./lib/global.js";
import { msg_fail, S3update, checkhash, hash as _hash,prisma } from "../utils/global.js";
//数据库
import { query, qww } from "./lib/database.js";
import geetest from "./lib/captcha/geetest.js";
import { query, qww } from "../utils/database.js";
import geetest from "../middleware/geetest.js";

router.all("*", function (req, res, next) {
//限定访问该模块的权限:必须已登录
Expand Down
12 changes: 6 additions & 6 deletions routes/router_project.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import logger from "./lib/logger.js";
import configManager from "./configManager.js";
import logger from "../utils/logger.js";
import configManager from "../utils/configManager.js";
import { Router } from "express";
const router = Router();
import DB from "./lib/database.js";
import { prisma } from "./lib/global.js";
import default_project from "./lib/default_project.js";
import { extractProjectData, setProjectFile, getProjectFile, projectSelectionFields, authorSelectionFields, handleTagsChange } from "./lib/method/projects.js";
import DB from "../utils/database.js";
import { prisma } from "../utils/global.js";
import default_project from "../config/default_project.js";
import { extractProjectData, setProjectFile, getProjectFile, projectSelectionFields, authorSelectionFields, handleTagsChange } from "../controllers/projects.js";
import { Logger } from "winston";
// 中间件,确保所有请求均经过该处理
router.all("*", (req, res, next) => next());
Expand Down
6 changes: 3 additions & 3 deletions routes/router_projectlist.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import logger from "./lib/logger.js";
import configManager from "./configManager.js";
import logger from "../utils/logger.js";
import configManager from "../utils/configManager.js";

import { Router } from "express";
const router = Router();
import { needlogin } from "../middleware/auth.js";

import { addProjectToUserProjectlist, getProjectlist, deleteProjectlist, updateProjectlist, createProjectlist, getUserProjectlist, checkProjectlistWithUser, removeProjectFromUserProjectlist } from "./lib/method/projectlist.js";
import { addProjectToUserProjectlist, getProjectlist, deleteProjectlist, updateProjectlist, createProjectlist, getUserProjectlist, checkProjectlistWithUser, removeProjectFromUserProjectlist } from "../controllers/projectlist.js";

// 中间件,确保所有请求均经过该处理
router.all("*", (req, res, next) => next());
Expand Down
10 changes: 5 additions & 5 deletions routes/router_scratch.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import logger from "./lib/logger.js";
import configManager from "./configManager.js";
import logger from "../utils/logger.js";
import configManager from "../utils/configManager.js";
import jsonwebtoken from "jsonwebtoken";

import { Router } from "express";
var router = Router();
import { writeFile, exists } from "fs";
import { query } from "./lib/database.js"; // 数据库
import { query } from "../utils/database.js"; // 数据库

//功能函数集
import { prisma, S3update } from "./lib/global.js";
import { prisma, S3update } from "../utils/global.js";
import { needlogin } from "../middleware/auth.js";
import { getProjectFile } from "./lib/method/projects.js";
import { getProjectFile } from "../controllers/projects.js";
router.all("*", function (req, res, next) {
next();
});
Expand Down
10 changes: 5 additions & 5 deletions routes/router_search.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import logger from "./lib/logger.js";
import configManager from "./configManager.js";
import logger from "../utils/logger.js";
import configManager from "../utils/configManager.js";

import { Router } from "express";
const router = Router();
import { prisma } from "./lib/global.js"; // 功能函数集
import { qww } from "./lib/database.js"; // 数据库
import { getUsersByList } from "./lib/method/projects.js";
import { prisma } from "../utils/global.js"; // 功能函数集
import { qww } from "../utils/database.js"; // 数据库
import { getUsersByList } from "../controllers/projects.js";
// 搜索:Scratch项目列表:数据(只搜索标题)
router.get("/", async (req, res, next) => {
try {
Expand Down
2 changes: 1 addition & 1 deletion routes/configManager.js → utils/configManager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import logger from "./lib/logger.js";
import logger from "./logger.js";
import { PrismaClient } from "@prisma/client";

class ConfigManager {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import logger from "../lib/logger.js";
import logger from "../logger.js";
import configManager from "../configManager.js";

import { createTransport } from "nodemailer";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import logger from "../lib/logger.js";
import logger from "../logger.js";
const registrationTemplate = async (email, password) => `
<div class="page flex-col">
<div class="box_3 flex-col"
Expand Down
2 changes: 1 addition & 1 deletion routes/lib/global.js → utils/global.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import configManager from "../configManager.js";
import configManager from "./configManager.js";
import logger from "./logger.js";
import crypto from "crypto";
import jwt from "jsonwebtoken";
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit bd0ccc7

Please sign in to comment.