diff --git a/.gitignore b/.gitignore index 20b0c92..7f94aea 100644 --- a/.gitignore +++ b/.gitignore @@ -125,3 +125,4 @@ dist .yarn/build-state.yml .yarn/install-state.gz .pnp.* +.vercel diff --git a/app.js b/app.js index 5a415ed..33459d8 100644 --- a/app.js +++ b/app.js @@ -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"); @@ -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"); }); }); @@ -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"); @@ -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"); }); diff --git a/package.json b/package.json index 5b9b26d..a53411a 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/server/router_admin.js b/server/router_admin.js index 1890bf9..d51155c 100644 --- a/server/router_admin.js +++ b/server/router_admin.js @@ -12,12 +12,12 @@ 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; } @@ -25,11 +25,11 @@ router.all('*', function(req, res, 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'); }); @@ -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'); }) }); @@ -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封号用户 @@ -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) { @@ -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) { @@ -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) { @@ -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'); }); }); // 背景管理:数据 @@ -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'); }); }); // 造型管理:数据 @@ -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'); }); }); // 角色管理:页面数据 @@ -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) { @@ -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) { @@ -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'); }); }); // 声音管理:数据 diff --git a/server/router_ads.js b/server/router_ads.js index d9b4058..6a2c223 100644 --- a/server/router_ads.js +++ b/server/router_ads.js @@ -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'); }); // 返回一个机构的头图 diff --git a/server/router_api.js b/server/router_api.js index 8784eb0..e95b922 100644 --- a/server/router_api.js +++ b/server/router_api.js @@ -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; } @@ -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'); }); }); }); @@ -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; } @@ -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]}); diff --git a/server/router_my.js b/server/router_my.js index fbebd16..7923b9e 100644 --- a/server/router_my.js +++ b/server/router_my.js @@ -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'); }); }); @@ -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} @@ -237,7 +237,7 @@ 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; } @@ -245,7 +245,7 @@ router.get('/info', function (req, res) { res.locals['birth'] = USER[0]['birthday']; res.locals['motto'] = USER[0]['motto']; - res.render('views/my_info.ejs'); + res.render('my_info.ejs'); }); }); //修改头像 diff --git a/server/router_python.js b/server/router_python.js index 003fffe..f1f6d3a 100644 --- a/server/router_python.js +++ b/server/router_python.js @@ -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"); }); }); @@ -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'); }); //项目点赞 @@ -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) { diff --git a/server/router_scratch.js b/server/router_scratch.js index 1557968..43a5d41 100644 --- a/server/router_scratch.js +++ b/server/router_scratch.js @@ -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"); }); }); @@ -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; } @@ -123,7 +123,7 @@ 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; } @@ -131,7 +131,7 @@ router.get("/play", function (req, res) { 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"); }); }); }); @@ -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源代码 diff --git a/server/router_user.js b/server/router_user.js index f8ab112..b56c871 100644 --- a/server/router_user.js +++ b/server/router_user.js @@ -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"); }); }); }); @@ -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"); }); //登录 @@ -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(); diff --git a/views/html-footer.ejs b/views/html-footer.ejs index 32d5ec1..62fb5b0 100644 --- a/views/html-footer.ejs +++ b/views/html-footer.ejs @@ -1,5 +1,5 @@ - + diff --git a/views/html-head.ejs b/views/html-head.ejs index 904fa5f..83eeb86 100644 --- a/views/html-head.ejs +++ b/views/html-head.ejs @@ -23,50 +23,10 @@ } - - - - - - 主页 - Scratch - Python - - - - - - -
- -
- - - - + <% if (login==false) { %> 注册 登录 @@ -86,7 +46,7 @@ - + 反馈 @@ -104,7 +64,7 @@ Github 银河编程社区 - 雨云> + 雨云 关闭 @@ -112,7 +72,7 @@ - + Scratch分区 @@ -121,6 +81,27 @@ + + + + + + + + 主页 + Scratch + Python + + + + + + +
+ +
+ + ScratchPython @@ -243,6 +224,31 @@ } } + + + +
+ + +
-

\ No newline at end of file diff --git a/views/python/python_edit.ejs b/views/python/python_edit.ejs index c78d0ee..562cab9 100644 --- a/views/python/python_edit.ejs +++ b/views/python/python_edit.ejs @@ -9,7 +9,33 @@ - <% include('../linkfile.ejs') %> + + + + + + + + + + + + + + + + +