Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
SunWuyuan committed Feb 25, 2024
1 parent 69b7997 commit 8afd55f
Show file tree
Hide file tree
Showing 13 changed files with 131 additions and 96 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,4 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
.vercel
18 changes: 10 additions & 8 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ app.use(multipart({ uploadDir: "./data/upload_tmp" }));
var compress = require("compression");
app.use(compress());

app.set("views", __dirname + "/");
app.set("view engine", "views");
app.set("env", __dirname + "/.env");
app.set("data", __dirname + "/data");
app.set("views", __dirname + "/views");
app.set("view engine", "ejs");

//数据库
var DB = require("./server/lib/database.js");
Expand Down Expand Up @@ -206,7 +208,7 @@ app.get("/", function (req, res) {
// res.locals["ads"] = encodeURIComponent(JSON.stringify(ADS));

//});
res.render("views/index.ejs");
res.render("index.ejs");
});
});

Expand All @@ -231,18 +233,18 @@ var apiserver = require("./server/router_api.js");
app.use("/api", apiserver);

app.get("/about", function (req, res, next) {
res.render("views/about.ejs");
res.render("about.ejs");
});
app.get("/share", function (req, res, next) {
res.render("views/share.ejs");
res.render("share.ejs");
});

//工具
app.get("/tools/comparer", function (req, res, next) {
res.render("views/tools/comparer.ejs");
res.render("tools/comparer.ejs");
});
app.get("/tools/asdm", function (req, res, next) {
res.render("views/tools/asdm.ejs");
res.render("tools/asdm.ejs");
});
//python路由
var router_python = require("./server/router_python.js");
Expand All @@ -259,5 +261,5 @@ process.on("uncaughtException", function (err) {
//放在最后,友好的处理地址不存在的访问
app.all("*", function (req, res, next) {
res.locals.tipType = "访问错误";
res.render("views/404.ejs");
res.render("404.ejs");
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"private": true,
"type": "commonjs",
"scripts": {
"build": "npm i -g @vercel/ncc && ncc build app.js",
"build": "npm i -g @vercel/ncc && ncc build app.js && mkdir dist/api && cp dist/index.js dist/api/index.js",
"test": "echo \"No test specified\" && exit 0",
"start": "node app"
},
Expand Down
30 changes: 15 additions & 15 deletions server/router_admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@ var DB = require("./lib/database.js");

router.all('*', function(req, res, next) {
if (!res.locals.login){
res.render('views/404.ejs');
res.render('404.ejs');
return;
}

if ( res.locals['is_admin'] != 1) {
res.render('views/404.ejs');
res.render('404.ejs');
return;
}

next();
});
//平台首页
router.get('/', function (req, res) {
res.render('views/admin/admin_index.ejs');
res.render('admin/admin_index.ejs');
});
//平台默认首页
router.get('/default', function (req, res) {
res.render('views/admin/admin_default.ejs');
res.render('admin/admin_default.ejs');

});

Expand Down Expand Up @@ -57,7 +57,7 @@ router.get('/info', function (req, res) {
res.locals['sprite_count'] = d[0].sprite_count;
}

res.render('views/admin/admin_info.ejs');
res.render('admin/admin_info.ejs');
})
});

Expand All @@ -71,7 +71,7 @@ router.get('/user', function (req, res) {
} else {
res.locals.regist = 1
}
res.render('views/admin/admin_user.ejs');
res.render('admin/admin_user.ejs');
});
});
//用户管理:数据。0正常用户,2封号用户
Expand Down Expand Up @@ -240,7 +240,7 @@ router.post('/user/setRegist',function(req,res){

//作品管理:Scratch页面
router.get('/works/scratch', function (req, res) {
res.render('views/admin/admin_works_scratch.ejs');
res.render('admin/admin_works_scratch.ejs');
});
//作品管理:Scratch数据
router.get('/works/scratch/data', function(req, res) {
Expand Down Expand Up @@ -346,7 +346,7 @@ router.post('/works/scratch/setDefaultWork',function(req,res){

//作品管理:Python页面
router.get('/works/python', function (req, res) {
res.render('views/admin/admin_works_python.ejs');
res.render('admin/admin_works_python.ejs');
});
//作品管理:Python数据
router.get('/works/python/data', function(req, res) {
Expand Down Expand Up @@ -460,7 +460,7 @@ router.post('/works/python/setDefaultWork',function(req,res){

// 素材分类管理:数据
router.get('/material/tag', function(req, res) {
res.render('views/admin/admin_tag.ejs');
res.render('admin/admin_tag.ejs');
});
// 素材分类管理:数据
router.get('/material/tag/data', function(req, res) {
Expand Down Expand Up @@ -584,7 +584,7 @@ router.get('/material/backdrop', function (req, res) {
res.locals['tags'] = tags;
}

res.render('views/admin/admin_material_backdrop.ejs');
res.render('admin/admin_material_backdrop.ejs');
});
});
// 背景管理:数据
Expand Down Expand Up @@ -761,7 +761,7 @@ router.get('/material/costume', function (req, res) {
res.locals['tags'] = tags;
}

res.render('views/admin/admin_material_costume.ejs');
res.render('admin/admin_material_costume.ejs');
});
});
// 造型管理:数据
Expand Down Expand Up @@ -940,7 +940,7 @@ router.get('/material/sprite', function (req, res) {
res.locals['tags'] = tags;
}

res.render('views/admin/admin_material_sprite.ejs');
res.render('admin/admin_material_sprite.ejs');
});
});
// 角色管理:页面数据
Expand Down Expand Up @@ -1106,7 +1106,7 @@ router.post('/material/sprite/setState',function(req,res){
// 角色管理:造型管理 页面
router.get('/material/sprite/setCostume', function (req, res) {
res.locals._id = req.query['id'];
res.render('views/admin/admin_material_sprite_costume.ejs');
res.render('admin/admin_material_sprite_costume.ejs');
});
// 角色管理:造型管理 页面数据
router.get('/material/sprite/setCostume/data', function(req, res) {
Expand Down Expand Up @@ -1229,7 +1229,7 @@ router.post('/material/sprite/setCostume/add', function (req, res) {
// 角色管理:声音管理 页面
router.get('/material/sprite/setSound', function (req, res) {
res.locals._id = req.query['id'];
res.render('views/admin/admin_material_sprite_sound.ejs');
res.render('admin/admin_material_sprite_sound.ejs');
});
// 角色管理:声音管理 页面 数据
router.get('/material/sprite/setSound/data', function(req, res) {
Expand Down Expand Up @@ -1358,7 +1358,7 @@ router.get('/material/sound', function (req, res) {
res.locals['tags'] = tags;
}

res.render('views/admin/admin_material_sound.ejs');
res.render('admin/admin_material_sound.ejs');
});
});
// 声音管理:数据
Expand Down
2 changes: 1 addition & 1 deletion server/router_ads.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ router.all('*', function(req, res, next) {
});

router.get('/', function (req, res) {
res.render('views/ads/index.ejs');
res.render('ads/index.ejs');
});

// 返回一个机构的头图
Expand Down
10 changes: 5 additions & 5 deletions server/router_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ router.get('/play', function (req, res) {
DB.query(SQL, function(err,U){
if (err|| U.affectedRows==0) {
res.locals.tip = {'opt': 'flash', 'msg':'项目不存在或未发布'};
res.render('views/404.ejs');
res.render('404.ejs');
return;
}

Expand All @@ -103,13 +103,13 @@ router.get('/play', function (req, res) {
DB.query(SQL, function (err, SCRATCH) {
if (err|| SCRATCH.length==0) {
res.locals.tip = {'opt': 'flash', 'msg':'项目不存在或未发布'};
res.render('views/404.ejs');
res.render('404.ejs');
return;
}

res.locals['is_author'] = (SCRATCH[0].authorid==res.locals.userid)?true:false;
res.locals['project'] = SCRATCH[0];
res.render('views/scratch/scratch_play.ejs');
res.render('scratch/scratch_play.ejs');
});
});
});
Expand All @@ -122,7 +122,7 @@ router.get('/usertx', function (req, res) {
DB.query(SQL, function (err, USER) {
if (err || USER.length == 0) {
res.locals.tip = { opt: "flash", msg: "用户不存在" };
res.render("views/404.ejs");
res.render("404.ejs");
return;
}

Expand All @@ -139,7 +139,7 @@ router.post("/getuserinfo", function (req, res) {
DB.query(SQL, function (err, USER) {
if (err || USER.length == 0) {
res.locals.tip = { opt: "flash", msg: "用户不存在" };
res.render("views/404.ejs");
res.render("404.ejs");
return;
}
res.status(200).send({status: 'ok',info:USER[0]});
Expand Down
8 changes: 4 additions & 4 deletions server/router_my.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ router.get('/scratch', function (req, res) {
res.locals.state1_count = data[0].state1_count;
res.locals.state2_count = data[0].state2_count;
}
res.render('views/scratch/my_scratch_projects.ejs');
res.render('scratch/my_scratch_projects.ejs');
});
});

Expand All @@ -68,7 +68,7 @@ router.get('/python', function (req, res) {
res.locals.state1_count = data[0].state1_count;
res.locals.state2_count = data[0].state2_count;
}
res.render('views/python/my_python_projects.ejs');
res.render('python/my_python_projects.ejs');
});
});
//显示Scratch项目列表:数据,{curr:obj.curr, limit:obj.limit,state:state}
Expand Down Expand Up @@ -237,15 +237,15 @@ router.get('/info', function (req, res) {
var SQL = `SELECT * FROM user WHERE id=${res.locals.userid} LIMIT 1`;
DB.query(SQL, function (err, USER) {
if (err || USER.length == 0) {
res.render('views/404.ejs');
res.render('404.ejs');
return;
}

res.locals['sex'] = USER[0]['sex'];
res.locals['birth'] = USER[0]['birthday'];
res.locals['motto'] = USER[0]['motto'];

res.render('views/my_info.ejs');
res.render('my_info.ejs');
});
});
//修改头像
Expand Down
8 changes: 4 additions & 4 deletions server/router_python.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ router.get("/", function (req, res) {
res.locals.python_count = data[0].python_count;
}

res.render("views/python/python_projects.ejs");
res.render("python/python_projects.ejs");

});
});
Expand Down Expand Up @@ -75,7 +75,7 @@ router.post("/view/seachPythonProjects", function (req, res) {
//python项目展示界面
router.get('/play', function (req, res) {

res.render('views/python/python_play.ejs');
res.render('python/python_play.ejs');
});

//项目点赞
Expand Down Expand Up @@ -195,11 +195,11 @@ router.post('/play/favo', function (req, res) {

//python项目编辑界面:获取项目源代码
router.get('/edit', function (req, res) {
res.render('views/python/python_edit.ejs');
res.render('python/python_edit.ejs');
})
//python兼容编辑器
router.get('/old', function (req, res) {
res.render('views/python/python_edit_old.ejs');
res.render('python/python_edit_old.ejs');
})
// 从数据库获取作品
router.post('/getWork', function (req, res) {
Expand Down
10 changes: 5 additions & 5 deletions server/router_scratch.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ router.get("/", function (req, res) {
res.locals.scratch_count = data[0].scratch_count;
}

res.render("views/scratch/scratch_projects.ejs");
res.render("scratch/scratch_projects.ejs");

});
});
Expand Down Expand Up @@ -90,7 +90,7 @@ router.get("/play", function (req, res) {
DB.query(SQL, function (err, U) {
if (err || U.affectedRows == 0) {
res.locals.tip = { opt: "flash", msg: "项目不存在或未发布" };
res.render("views/404.ejs");
res.render("404.ejs");
return;
}

Expand Down Expand Up @@ -123,15 +123,15 @@ router.get("/play", function (req, res) {
DB.query(SQL, function (err, SCRATCH) {
if (err || SCRATCH.length == 0) {
res.locals.tip = { opt: "flash", msg: "项目不存在或未发布" };
res.render("views/404.ejs");
res.render("404.ejs");
return;
}

res.locals["is_author"] =
SCRATCH[0].authorid == res.locals.userid ? true : false;
res.locals["project"] = SCRATCH[0];
////console.log(SCRATCH[0]);
res.render("views/scratch/scratch_play.ejs");
res.render("scratch/scratch_play.ejs");
});
});
});
Expand Down Expand Up @@ -263,7 +263,7 @@ router.post("/play/openSrc", function (req, res) {

//Scratch编程界面
router.get("/edit", function (req, res) {
res.render("views/scratch/scratch_edit.ejs");
res.render("scratch/scratch_edit.ejs");
});

//Scratch内部调用一:获取作品数据:JSON源代码
Expand Down
10 changes: 5 additions & 5 deletions server/router_user.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ router.get("/", function (req, res) {
DB.query(SQL, function (err, USER) {
if (err || USER.length == 0) {
res.locals.tip = { opt: "flash", msg: "用户不存在" };
res.render("views/404.ejs");
res.render("404.ejs");
return;
}
res.locals["user"] = USER[0];
//console.log(USER);
res.render("views/user.ejs");
res.render("user.ejs");
});
});
});
Expand All @@ -52,13 +52,13 @@ router.get("/login", function (req, res) {
res.locals.reg = 1;
}

res.render("views/login_or_register.ejs");
res.render("login_or_register.ejs");
});
});

//登录、注册、找回密码三合一界面
router.get("/repw", function (req, res) {
res.render("views/repw.ejs");
res.render("repw.ejs");
});

//登录
Expand Down Expand Up @@ -516,7 +516,7 @@ router.get("/tuxiaochao", function (req, res) {
DB.query(SQL, function (err, USER) {
if (err || USER.length == 0) {
res.locals.tip = { opt: "flash", msg: "用户不存在" };
res.render("views/404.ejs");
res.render("404.ejs");
return;
}
uid = res.locals["userid"].toString();
Expand Down
Loading

0 comments on commit 8afd55f

Please sign in to comment.