diff --git a/app.js b/app.js
index 4f55181..c1ea306 100644
--- a/app.js
+++ b/app.js
@@ -206,10 +206,6 @@ app.use("/user", router_register);
var router_admin = require("./server/router_my.js");
app.use("/my", router_admin);
-//系统平台路由
-var router_admin = require("./server/router_admin.js");
-app.use("/admin", router_admin);
-
//搜索api
var router_search = require("./server/router_search.js");
app.use("/searchapi", router_search);
@@ -232,20 +228,6 @@ app.use("/project", router_project);
//项目处理路由
var router_comment = require("./server/router_comment.js");
app.use("/comment", router_comment);
-app.get("/about", function (req, res, next) {
- res.render("about.ejs");
-});
-app.get("/share", function (req, res, next) {
- res.render("share.ejs");
-});
-
-app.get("/search", function (req, res, next) {
- res.render("search.ejs");
-});
-
-//python路由
-var router_python = require("./server/router_python.js");
-app.use("/python", router_python);
app.get("/check", function (req, res, next) {
res.status(200).json({
@@ -270,7 +252,12 @@ app.use((err, req, res, next) => {
//放在最后,友好的处理地址不存在的访问
app.all("*", function (req, res, next) {
res.locals.tipType = "访问错误";
- res.render("404.ejs");
+ res.status(404).json({
+ status: "error",
+ code: "404",
+ message: "找不到页面",
+ });
+
});
module.exports = app;
diff --git a/data/material/asset/0a5b8c55b5ef147f5fdf67ddab3bab28.svg b/data/material/asset/0a5b8c55b5ef147f5fdf67ddab3bab28.svg
deleted file mode 100644
index 62c6225..0000000
--- a/data/material/asset/0a5b8c55b5ef147f5fdf67ddab3bab28.svg
+++ /dev/null
@@ -1 +0,0 @@
-
\ No newline at end of file
diff --git a/data/material/asset/12b7c852e83a2846942cb2ceb6c549d7.png b/data/material/asset/12b7c852e83a2846942cb2ceb6c549d7.png
deleted file mode 100644
index 61a8875..0000000
Binary files a/data/material/asset/12b7c852e83a2846942cb2ceb6c549d7.png and /dev/null differ
diff --git a/data/material/asset/365a43dce18a8020c6e2ba44f4507836.svg b/data/material/asset/365a43dce18a8020c6e2ba44f4507836.svg
deleted file mode 100644
index 716826f..0000000
--- a/data/material/asset/365a43dce18a8020c6e2ba44f4507836.svg
+++ /dev/null
@@ -1 +0,0 @@
-
\ No newline at end of file
diff --git a/data/material/asset/7cb4e1f10e1b712eed814f04b40c7882.svg b/data/material/asset/7cb4e1f10e1b712eed814f04b40c7882.svg
deleted file mode 100644
index e4ad29a..0000000
--- a/data/material/asset/7cb4e1f10e1b712eed814f04b40c7882.svg
+++ /dev/null
@@ -1 +0,0 @@
-
\ No newline at end of file
diff --git a/data/material/asset/91550946e41f0cf939ea8ddbc5a35b8d.png b/data/material/asset/91550946e41f0cf939ea8ddbc5a35b8d.png
deleted file mode 100644
index e1998f6..0000000
Binary files a/data/material/asset/91550946e41f0cf939ea8ddbc5a35b8d.png and /dev/null differ
diff --git a/data/material/asset/adeaea1c79253e30052b63462c885a53.png b/data/material/asset/adeaea1c79253e30052b63462c885a53.png
deleted file mode 100644
index 87c47b7..0000000
Binary files a/data/material/asset/adeaea1c79253e30052b63462c885a53.png and /dev/null differ
diff --git a/data/material/asset/bd76d9bb4699c3e431fb43315283eb4e.png b/data/material/asset/bd76d9bb4699c3e431fb43315283eb4e.png
deleted file mode 100644
index 5d3704d..0000000
Binary files a/data/material/asset/bd76d9bb4699c3e431fb43315283eb4e.png and /dev/null differ
diff --git a/data/material/asset/d08d9631057826d5e83c0ef13c844f2c.png b/data/material/asset/d08d9631057826d5e83c0ef13c844f2c.png
deleted file mode 100644
index ae8a8bf..0000000
Binary files a/data/material/asset/d08d9631057826d5e83c0ef13c844f2c.png and /dev/null differ
diff --git a/data/material/asset/f4f02527595957f021eca4b4bcdc5b45.svg b/data/material/asset/f4f02527595957f021eca4b4bcdc5b45.svg
deleted file mode 100644
index 4069e52..0000000
--- a/data/material/asset/f4f02527595957f021eca4b4bcdc5b45.svg
+++ /dev/null
@@ -1 +0,0 @@
-
\ No newline at end of file
diff --git a/data/upload_tmp/-O_f2MCqcNuLSJ-rCl8mRwU7.webp b/data/upload_tmp/-O_f2MCqcNuLSJ-rCl8mRwU7.webp
deleted file mode 100644
index a701c19..0000000
Binary files a/data/upload_tmp/-O_f2MCqcNuLSJ-rCl8mRwU7.webp and /dev/null differ
diff --git a/data/upload_tmp/Sylosv78BeOaO5J-HwshiAKd.original b/data/upload_tmp/Sylosv78BeOaO5J-HwshiAKd.original
deleted file mode 100644
index 8132fe6..0000000
Binary files a/data/upload_tmp/Sylosv78BeOaO5J-HwshiAKd.original and /dev/null differ
diff --git a/data/upload_tmp/bPExd9Zi7VKQ5FIvSFQDKLYn b/data/upload_tmp/bPExd9Zi7VKQ5FIvSFQDKLYn
deleted file mode 100644
index 3e0b06d..0000000
Binary files a/data/upload_tmp/bPExd9Zi7VKQ5FIvSFQDKLYn and /dev/null differ
diff --git a/data/upload_tmp/gJkgHghb4BcEmrmP89tPX66l.webp b/data/upload_tmp/gJkgHghb4BcEmrmP89tPX66l.webp
deleted file mode 100644
index 34f5ba7..0000000
Binary files a/data/upload_tmp/gJkgHghb4BcEmrmP89tPX66l.webp and /dev/null differ
diff --git a/data/upload_tmp/ulFgB7e0JFp7f4T7zQfeK8ha b/data/upload_tmp/ulFgB7e0JFp7f4T7zQfeK8ha
deleted file mode 100644
index 3e0b06d..0000000
Binary files a/data/upload_tmp/ulFgB7e0JFp7f4T7zQfeK8ha and /dev/null differ
diff --git a/data/upload_tmp/vY5xvnoDu4gSPQ1EEuzq2c1n.webp b/data/upload_tmp/vY5xvnoDu4gSPQ1EEuzq2c1n.webp
deleted file mode 100644
index 34f5ba7..0000000
Binary files a/data/upload_tmp/vY5xvnoDu4gSPQ1EEuzq2c1n.webp and /dev/null differ
diff --git a/data/upload_tmp/zEv8nHojae-h0eweDNxjNvuq.webp b/data/upload_tmp/zEv8nHojae-h0eweDNxjNvuq.webp
deleted file mode 100644
index 34f5ba7..0000000
Binary files a/data/upload_tmp/zEv8nHojae-h0eweDNxjNvuq.webp and /dev/null differ
diff --git a/data/user/1 b/data/user/1
deleted file mode 100644
index 3e0b06d..0000000
Binary files a/data/user/1 and /dev/null differ
diff --git a/server/router_account.js b/server/router_account.js
index 347de14..335d70b 100644
--- a/server/router_account.js
+++ b/server/router_account.js
@@ -33,26 +33,9 @@ router.all("*", function (req, res, next) {
}
})();
*/
-const request = require("request");
-router.get("/", function (req, res) {
- res.render("user.ejs");
-});
-router.get("/login", function (req, res, next) {
- var SQL = `SELECT id FROM sys_ini WHERE iniKey='regist' AND iniValue=1 LIMIT 1`;
- DB.query(SQL, function (err, Regist) {
- if (err || Regist.length == 0) {
- res.locals.reg = 0;
- } else {
- res.locals.reg = 1;
- }
- res.render("login_or_register.ejs");
- });
-});
-router.get("/repw", function (req, res) {
- res.render("repw.ejs");
-});
+
const geetest = require("./lib/captcha/geetest.js");
//geetest,
router.post("/login", async function (req, res, next) {
diff --git a/server/router_admin.js b/server/router_admin.js
deleted file mode 100644
index 51fa0e1..0000000
--- a/server/router_admin.js
+++ /dev/null
@@ -1,1913 +0,0 @@
-const configManager = require("./configManager");
-
-var express = require("express");
-var router = express.Router();
-var fs = require("fs");
-
-//功能函数集
-var I = require("./lib/global.js");
-
-//数据库
-var DB = require("./lib/database.js");
-
-router.all("*", function (req, res, next) {
- if (!res.locals.login) {
- res.render("404.ejs");
- return;
- }
-
- if (res.locals["is_admin"] != 1) {
- res.render("404.ejs");
- return;
- }
-
- next();
-});
-//平台首页
-router.get("/", function (req, res, next) {
- try {
- res.render("admin/admin_index.ejs");
- } catch (err) {
- next(err);
- }
-});
-//平台默认首页
-router.get("/default", function (req, res, next) {
- try {
- res.render("admin/admin_default.ejs");
- } catch (err) {
- next(err);
- }
-});
-
-//平台概况
-router.get("/info", function (req, res, next) {
- try {
- var SQL =
- `SELECT ` +
- ` (SELECT count(id) FROM ow_users ) AS user_count, ` +
- ` (SELECT count(id) FROM ow_projects WHERE type='scratch') AS scratch_count, ` +
- ` (SELECT count(id) FROM ow_projects WHILE type='python) AS python_count, ` +
- ` (SELECT count(id) FROM material_backdrop) AS backdrop_count, ` +
- ` (SELECT count(id) FROM material_sprite) AS sprite_count `;
- DB.query(SQL, function (err, d) {
- if (err || d.length == 0) {
- res.locals["user_count"] = 0;
- res.locals["scratch_count"] = 0;
- res.locals["python_count"] = 0;
- res.locals["backdrop_count"] = 0;
- res.locals["sprite_count"] = 0;
- } else {
- res.locals["user_count"] = d[0].user_count;
- res.locals["scratch_count"] = d[0].scratch_count;
- res.locals["python_count"] = d[0].python_count;
- res.locals["backdrop_count"] = d[0].backdrop_count;
- res.locals["sprite_count"] = d[0].sprite_count;
- }
-
- res.render("admin/admin_info.ejs");
- });
- } catch (err) {
- next(err);
- }
-});
-
-//用户管理
-router.get("/user", function (req, res, next) {
- try {
- var SQL = `SELECT id FROM sys_ini WHERE iniKey='regist' AND iniValue=1 LIMIT 1`;
- DB.query(SQL, function (err, data) {
- if (err || data.length == 0) {
- res.locals.regist = 0;
- } else {
- res.locals.regist = 1;
- }
- res.render("admin/admin_user.ejs");
- });
- } catch (err) {
- next(err);
- }
-});
-//用户管理:数据。0正常用户,2封号用户
-router.get("/user/data", function (req, res, next) {
- try {
- var state = parseInt(req.query["s"]);
- if (state == 9) {
- //0:正常用户,2:封号用户,9:查找用户
- var SQL = `SELECT count(id) AS c FROM ow_users WHERE email LIKE '%${req.query.t}%'`;
- } else {
- var SQL = `SELECT count(id) AS c FROM ow_users WHERE state=${state}`;
- }
- DB.query(SQL, function (err, count) {
- if (err || count.length == 0 || count[0]["c"] == 0) {
- res.status(200).send({ count: 0, data: [] });
- return;
- }
- //获取当前数据集合
- var page = parseInt(req.query["page"]);
- var limit = parseInt(req.query["limit"]);
-
- if (state == 9) {
- //0:正常用户,2:封号用户,9:查找用户
- SQL = `SELECT id,email,display_name,state,regTime FROM ow_users WHERE email LIKE '%${
- req.query.t
- }%' LIMIT ${(page - 1) * limit}, ${limit}`;
- } else {
- SQL = `SELECT id,email,display_name,state,regTime FROM ow_users WHERE state=${state} LIMIT ${
- (page - 1) * limit
- }, ${limit}`;
- }
- DB.query(SQL, function (err, data) {
- if (err) {
- res.status(200).send({ count: 0, data: [] });
- } else {
- res.status(200).send({ count: count[0]["c"], data: data });
- }
- });
- });
- } catch (err) {
- next(err);
- }
-});
-//管理员重置用户密码
-router.post("/user_setpassword", function (req, res, next) {
- try {
- if (!req.body.pw || !req.body.un || !I.userpwTest(req.body.pw)) {
- res.status(200).send({ status: "failed", msg: "再试一次" });
- return;
- }
-
- //对密码进行加密
- let pw = I.hash(req.body.pw);
- var UPDATE = `UPDATE ow_users SET password='${pw}' WHERE email='${req.body["un"]}' LIMIT 1`;
- DB.query(UPDATE, function (err, d) {
- if (err) {
- res.status(200).send({ status: "failed", msg: "再试一次" });
- } else {
- res.status(200).send({ status: "success", msg: "密码重置成功" });
- }
- });
- } catch (err) {
- next(err);
- }
-});
-//用户管理:功能.0解封 2封号
-router.post("/user_setstate", function (req, res, next) {
- try {
- var state = 0;
- if (req.body["s"] == undefined || req.body["s"] != 0) {
- state = 2; //未知时,都当作封号处理
- }
- //var state = parseInt(req.body['s']);
- var UPDATE = `UPDATE ow_users SET state=${state} WHERE id=${req.body.id} LIMIT 1`;
- DB.query(UPDATE, function (err, d) {
- if (err) {
- res.status(200).send({ status: "failed", msg: "再试一次" });
- } else {
- res.status(200).send({ status: "success", msg: "操作成功" });
- }
- });
- } catch (err) {
- next(err);
- }
-});
-//用户管理:创建新用户,功能
-router.post("/user_new", function (req, res, next) {
- try {
- if (!req.body.un || !I.emailTest(req.body.un)) {
- res.status(200).send({ status: "failed", msg: "再试一次" });
- return;
- }
- //检查账户是否已存在
- var SQL = `SELECT id FROM ow_users WHERE email='${req.body.un}' LIMIT 1`;
- DB.query(SQL, function (err, User) {
- if (err) {
- res.status(200).send(msg_fail);
- return;
- }
- if (User.length != 0) {
- res.status(200).send({ status: "fail", msg: "该账户已存在" });
- return;
- }
-
- //对密码进行加密:默认密码为用户手机号后8位
- var nn = req.body.un.substring(req.body.un.length - 6); //昵称
- var pw = nn; //req.body.un.substring(req.body.un.length-6);//初始密码
- pw = I.hash(pw);
- SQL = `INSERT INTO ow_users (email,password,display_name) VALUES ('${req.body.un}','${pw}','${nn}')`;
- DB.query(SQL, function (err, newUser) {
- if (err) {
- res.status(200).send({ status: "fail", msg: "再试一次" });
- return;
- }
-
- oldpath = "./build/img/user_default_icon.png";
- newpath = "./data/user/" + newUser.insertId + ".png";
- let oldFile = fs["createReadStream"](oldpath);
- let newFile = fs["createWriteStream"](newpath);
- oldFile["pipe"](newFile);
-
- res.status(200).send({ status: "success", msg: "操作成功" });
- });
- });
- } catch (err) {
- next(err);
- }
-});
-//用户管理:批量创建新用户,功能
-router.post("/user_new100", function (req, res, next) {
- try {
- const qz = req.body.qz;
- const sl = req.body.sl;
- var reg = /^(?:\d+|[a-zA-Z]+){4,8}$/;
- if (!reg["test"](qz)) {
- res.status(200).send({ status: "x", msg: "前缀格式不正确" });
- return;
- }
-
- reg = /^([0-9]+){1,3}$/;
- if (!reg["test"](sl)) {
- res.status(200).send({ status: "x", msg: "数量不正确:1~100" });
- return;
- }
-
- if (sl == 0 || sl > 100) {
- res.status(200).send({ status: "x", msg: "数量不正确:1~100" });
- return;
- }
-
- // 生成账户
-
- for (var i = 0; i < sl; i++) {
- if (i < 10) {
- un = qz + "0" + i;
- } else {
- un = qz + i;
- }
-
- var pw = un.substring(un.length - 6); //初始密码
- pw = I.hash(pw);
- SQL = `INSERT INTO ow_users (email, password, display_name) VALUES ('${un}','${pw}','${un}')`;
- DB.query(SQL, function (err, newUser) {
- if (err) {
- return;
- }
- });
- }
-
- res.status(200).send({ status: "ok", msg: "操作成功" });
- } catch (err) {
- next(err);
- }
-});
-
-//用户管理:开启、关闭用户注册通道
-router.post("/user/setRegist", function (req, res, next) {
- try {
- let v = 1;
- if (req.body.v != 1) {
- v = 0;
- }
-
- var SQL = `UPDATE sys_ini SET iniValue=${v} WHERE iniKey='regist' LIMIT 1`;
- DB.query(SQL, function (err, User) {
- if (err) {
- res.status(200).send({ status: "x", msg: "数据错误" });
- return;
- }
-
- res.status(200).send({ status: "ok", msg: "操作成功" });
- });
- } catch (err) {
- next(err);
- }
-});
-
-//作品管理:Scratch页面
-router.get("/works/scratch", function (req, res, next) {
- try {
- res.render("admin/admin_works_scratch.ejs");
- } catch (err) {
- next(err);
- }
-});
-//作品管理:Scratch数据
-router.get("/works/scratch/data", function (req, res, next) {
- try {
- WHERE = "";
- NICKNAME = ""; //根据昵称查找
- if (req.query.w == "search_state0") {
- WHERE = ` WHERE scratch.state='private' `;
- } else if (req.query.w == "search_state1") {
- WHERE = ` WHERE scratch.state='public' `;
- } else if (req.query.w == "search_state2") {
- WHERE = ` WHERE scratch.state='public' `;
- } else if (req.query.w == "search_workname") {
- WHERE = ` WHERE scratch.title LIKE '%${req.query.v}%' `;
- } else if (req.query.w == "search_display_name") {
- NICKNAME = ` AND ow_users.display_name LIKE '%${req.query.v}%' `;
- }
-
- if (NICKNAME == "") {
- var SQL = `SELECT count(id) AS c FROM scratch ${WHERE}`;
- } else {
- var SQL =
- `SELECT count(scratch.id) AS c FROM scratch ` +
- ` INNER JOIN ow_users ON (ow_users.id=scratch.authorid ${NICKNAME}) `;
- }
- DB.query(SQL, function (err, count) {
- if (err || count[0]["c"] == 0) {
- res.status(200).send({ count: 0, data: [] });
- return;
- }
- //获取当前数据集合
- var page = parseInt(req.query["page"]);
- var limit = parseInt(req.query["limit"]);
- SQL =
- `SELECT scratch.id, scratch.state, scratch.title, scratch.time, ow_users.email, ow_users.display_name FROM scratch ` +
- ` INNER JOIN ow_users ON (ow_users.id=scratch.authorid ${NICKNAME}) ` +
- ` ${WHERE} ORDER BY scratch.time DESC LIMIT ${
- (page - 1) * limit
- },${limit}`;
-
- DB.query(SQL, function (err, data) {
- if (err) {
- res.status(200).send({ count: 0, data: [] });
- } else {
- res.status(200).send({ count: count[0]["c"], data: data });
- }
- });
- });
- } catch (err) {
- next(err);
- }
-});
-//作品管理:设置作品的标题
-router.post("/works/scratch/changeTitle", function (req, res, next) {
- try {
- var UPDATE = `UPDATE scratch SET title=? WHERE id=${req.body.id} LIMIT 1`;
- var SET = [`${req.body.t}`];
- DB.qww(UPDATE, SET, function (err, d) {
- if (err) {
- res.status(200).send({ status: "failed", msg: "再试一次" });
- } else {
- res.status(200).send({ status: "success", msg: "操作成功" });
- }
- });
- } catch (err) {
- next(err);
- }
-});
-//作品管理:设置作品的发布状态
-router.post("/works/scratch/setState", function (req, res, next) {
- try {
- if (req.body.s == undefined || req.body.s < 0 || 2 < req.body.s) {
- s = 0; //未知时,都当作取消推荐处理
- } else {
- s = req.body.s;
- }
-
- var UPDATE = `UPDATE scratch SET state=${s} WHERE id=${req.body.id} LIMIT 1`;
- DB.query(UPDATE, function (err, d) {
- if (err) {
- res.status(200).send({ status: "failed", msg: "再试一次" });
- } else {
- res.status(200).send({ status: "success", msg: "操作成功" });
- }
- });
- } catch (err) {
- next(err);
- }
-});
-//作品管理:复制作品为默认作品
-router.post("/works/scratch/setDefaultWork", function (req, res, next) {
- try {
- if (!req.body.id || req.body.id == 1) {
- // 客服端传参数问题
- res.status(200).send({ status: "ok", msg: "操作成功" });
- return;
- }
-
- const SELECT = `SELECT title, src FROM scratch WHERE id=${req.body.id}`;
- DB.query(SELECT, function (err, d) {
- if (err || d.length == 0) {
- res.status(200).send({ status: "x", msg: "再试一次" });
- return;
- }
-
- const UPDATE = `UPDATE scratch SET title=?, src=? WHERE id=1`;
- const VAL = [d[0].title, d[0].src];
- DB.qww(UPDATE, VAL, function (err, d) {
- if (err) {
- res.status(200).send({ status: "x", msg: "再试一次" });
- } else {
- res.status(200).send({ status: "ok", msg: "操作成功" });
- }
- });
- });
- } catch (err) {
- next(err);
- }
-});
-
-//作品管理:Python页面
-router.get("/works/python", function (req, res, next) {
- try {
- res.render("admin/admin_works_python.ejs");
- } catch (err) {
- next(err);
- }
-});
-//作品管理:Python数据
-router.get("/works/python/data", function (req, res, next) {
- try {
- WHERE = "";
- NICKNAME = ""; //根据昵称查找
- if (req.query.w == "search_state0") {
- WHERE = ` WHERE python.state='private' `;
- } else if (req.query.w == "search_state1") {
- WHERE = ` WHERE python.state='public' `;
- } else if (req.query.w == "search_state2") {
- WHERE = ` WHERE python.state='public' `;
- } else if (req.query.w == "search_workname") {
- WHERE = ` WHERE python.title LIKE '%${req.query.v}%' `;
- } else if (req.query.w == "search_display_name") {
- NICKNAME = ` AND ow_users.display_name LIKE '%${req.query.v}%' `;
- }
-
- if (NICKNAME == "") {
- var SQL = `SELECT count(id) AS c FROM python ${WHERE}`;
- } else {
- var SQL =
- `SELECT count(python.id) AS c FROM python ` +
- ` INNER JOIN ow_users ON (ow_users.id=python.authorid ${NICKNAME}) `;
- }
- DB.query(SQL, function (err, count) {
- if (err || count[0]["c"] == 0) {
- res.status(200).send({ count: 0, data: [] });
- return;
- }
- //获取当前数据集合
- var page = parseInt(req.query["page"]);
- var limit = parseInt(req.query["limit"]);
- SQL =
- `SELECT python.id, python.state, python.title, python.time, ow_users.email, ow_users.display_name FROM python ` +
- ` INNER JOIN ow_users ON (ow_users.id=python.authorid ${NICKNAME}) ` +
- ` ${WHERE} ORDER BY python.time DESC LIMIT ${
- (page - 1) * limit
- },${limit}`;
-
- DB.query(SQL, function (err, data) {
- if (err) {
- res.status(200).send({ count: 0, data: [] });
- } else {
- res.status(200).send({ count: count[0]["c"], data: data });
- }
- });
- });
- } catch (err) {
- next(err);
- }
-});
-//作品管理:Python 设置作品的标题
-router.post("/works/python/changeTitle", function (req, res, next) {
- try {
- var UPDATE = `UPDATE python SET title=? WHERE id=${req.body.id} LIMIT 1`;
- var SET = [`${req.body.t}`];
- DB.qww(UPDATE, SET, function (err, d) {
- if (err) {
- res.status(200).send({ status: "x", msg: "再试一次" });
- } else {
- res.status(200).send({ status: "ok", msg: "操作成功" });
- }
- });
- } catch (err) {
- next(err);
- }
-});
-//作品管理:Python设置作品的发布状态
-router.post("/works/python/setState", function (req, res, next) {
- try {
- if (req.body.s == undefined || req.body.s < 0 || 2 < req.body.s) {
- s = 0; //未知时,都当作取消推荐处理
- } else {
- s = req.body.s;
- }
-
- var UPDATE = `UPDATE python SET state=${s} WHERE id=${req.body.id} LIMIT 1`;
- DB.query(UPDATE, function (err, d) {
- if (err) {
- res.status(200).send({ status: "x", msg: "再试一次" });
- } else {
- res.status(200).send({ status: "ok", msg: "操作成功" });
- }
- });
- } catch (err) {
- next(err);
- }
-});
-//作品管理:Python复制作品为默认作品
-router.post("/works/python/setDefaultWork", function (req, res, next) {
- try {
- if (!req.body.id || req.body.id == 1) {
- // 客服端传参数问题
- res.status(200).send({ status: "ok", msg: "操作成功" });
- return;
- }
-
- const SELECT = `SELECT title, src FROM python WHERE id=${req.body.id}`;
- DB.query(SELECT, function (err, d) {
- if (err || d.length == 0) {
- res.status(200).send({ status: "x", msg: "再试一次" });
- return;
- }
-
- const UPDATE = `UPDATE python SET title=?, src=? WHERE id=1`;
- const VAL = [d[0].title, d[0].src];
- DB.qww(UPDATE, VAL, function (err, d) {
- if (err) {
- res.status(200).send({ status: "x", msg: "再试一次" });
- } else {
- res.status(200).send({ status: "ok", msg: "操作成功" });
- }
- });
- });
- } catch (err) {
- next(err);
- }
-});
-
-// 素材分类管理:数据
-router.get("/material/tag", function (req, res, next) {
- try {
- res.render("admin/admin_tag.ejs");
- } catch (err) {
- next(err);
- }
-});
-// 素材分类管理:数据
-router.get("/material/tag/data", function (req, res, next) {
- try {
- var type = parseInt(req.query["t"]);
- if (!type || type < 1 || 4 < type) {
- // 1背景、2角色、3造型、4声音
- res.status(200).send({ status: "x", msg: "素材类型参数错误" });
- return;
- }
-
- var SQL = `SELECT id, tag FROM material_tags WHERE type=${type} ORDER BY id DESC`;
- DB.query(SQL, function (err, tags) {
- if (err) {
- res.status(200).send({ status: "x", msg: "服务器错误" });
- return;
- }
-
- res.status(200).send({ status: "ok", data: tags });
- });
- } catch (err) {
- next(err);
- }
-});
-// 素材分类管理:添加
-router.post("/material/tag/add", function (req, res, next) {
- try {
- var type = parseInt(req.body.t);
- if (!type || type < 1 || 4 < type) {
- // 1背景、2角色、3造型、4声音
- res.status(200).send({ status: "x", msg: "素材类型参数错误" });
- return;
- }
-
- if (!req.body.v || req.body.v == "") {
- res.status(200).send({ status: "x", msg: "标签名错误" });
- return;
- }
-
- SQL = `INSERT INTO material_tags (type, tag) VALUES ('${type}', '${req.body.v}')`;
- DB.query(SQL, function (err, newTag) {
- if (err) {
- res.status(200).send({ status: "x", msg: "保存数据错误,请再试一次" });
- return;
- }
-
- res
- .status(200)
- .send({ status: "ok", msg: "操作成功", newTagId: newTag.insertId });
- });
- } catch (err) {
- next(err);
- }
-});
-// 素材分类管理:修改
-router.post("/material/tag/mod", function (req, res, next) {
- try {
- if (!req.body.v || req.body.v == "") {
- res.status(200).send({ status: "x", msg: "标签名错误" });
- return;
- }
-
- SQL = `UPDATE material_tags SET tag=? WHERE id=?`;
- var VAL = [`${req.body.v}`, req.body.id];
- DB.qww(SQL, VAL, function (err, TAG) {
- if (err) {
- res.status(200).send({ status: "x", msg: "保存数据错误,请再试一次" });
- return;
- }
-
- res.status(200).send({ status: "ok", msg: "操作成功" });
- });
- } catch (err) {
- next(err);
- }
-});
-// 素材分类管理:删除
-router.post("/material/tag/del", function (req, res, next) {
- try {
- // 判断此标签下是否有素材:只能删除空标签
- var type = parseInt(req.body.t);
- var tabelname = ""; // 1背景、2角色、3造型、4声音
- if (type == 1) {
- tabelname = "material_backdrop";
- } else if (type == 2) {
- tabelname = "material_sprite";
- } else if (type == 3) {
- tabelname = "material_costume";
- } else if (type == 4) {
- tabelname = "material_sound";
- } else {
- res.status(200).send({ status: "x", msg: "素材类型参数错误" });
- return;
- }
-
- var VAL = [req.body.id];
- var SQL = `SELECT id FROM ${tabelname} WHERE tagId=? LIMIT 1`;
- DB.qww(SQL, VAL, function (err, MATE) {
- if (err) {
- res.status(200).send({ status: "x", msg: "保存数据错误,请再试一次" });
- return;
- }
-
- if (MATE.length != 0) {
- res.status(200).send({ status: "x", msg: "只能删除空标签" });
- return;
- }
-
- SQL = `DELETE FROM material_tags WHERE id=?`;
- DB.qww(SQL, VAL, function (err, TAG) {
- if (err) {
- res
- .status(200)
- .send({ status: "x", msg: "保存数据错误,请再试一次" });
- return;
- }
-
- res.status(200).send({ status: "ok", msg: "操作成功" });
- });
- });
- } catch (err) {
- next(err);
- }
-});
-
-/*生成32位随机流水号*/
-const random_32ID_With_Time_Tag = function () {
- var chars = "ABCDEFabcdef0123456789"; // 角色文件必须是:^[a-fA-F0-9]{32}$
- var maxPos = chars.length;
- var randomID =
- "B100" +
- parseInt(new Date().getTime() / 1000)
- .toString(16)
- .toUpperCase();
- for (i = 0; i < 20; i++) {
- randomID += chars.charAt(Math.floor(Math.random() * maxPos));
- }
- return randomID;
-};
-
-// 背景管理:页面
-router.get("/material/backdrop", function (req, res, next) {
- try {
- var SQL = `SELECT id, tag FROM material_tags WHERE type=1 ORDER BY id DESC`;
- DB.query(SQL, function (err, tags) {
- if (err) {
- res.locals["tags"] = [];
- } else {
- res.locals["tags"] = tags;
- }
-
- res.render("admin/admin_material_backdrop.ejs");
- });
- } catch (err) {
- next(err);
- }
-});
-// 背景管理:数据
-router.get("/material/backdrop/data", function (req, res, next) {
- try {
- var VAL = [req.query.tagId];
- var SQL = `SELECT count(id) AS c FROM material_backdrop WHERE tagId=?`;
- DB.qww(SQL, VAL, function (err, count) {
- if (err || count[0]["c"] == 0) {
- res.status(200).send({ count: 0, data: [] });
- return;
- }
-
- //获取当前数据集合
- var page = parseInt(req.query["page"]);
- var limit = parseInt(req.query["limit"]);
- SQL = `SELECT * FROM material_backdrop WHERE tagId=? ORDER BY id DESC LIMIT ${
- (page - 1) * limit
- },${limit}`;
- DB.qww(SQL, VAL, function (err, data) {
- if (err) {
- res.status(200).send({ count: 0, data: [] });
- } else {
- res.status(200).send({ count: count[0]["c"], data: data });
- }
- });
- });
- } catch (err) {
- next(err);
- }
-});
-// 背景管理:添加
-router.post("/material/backdrop/add", function (req, res, next) {
- try {
- var newFileName = random_32ID_With_Time_Tag();
- const SQL = `INSERT INTO material_backdrop (tagId, md5) VALUES ('${req.body.tagId}', '${newFileName}.png')`;
- DB.query(SQL, function (err, newTag) {
- if (err) {
- res.status(200).send({ status: "x", msg: "保存数据错误,请再试一次" });
- return;
- }
-
- //保存文件到正确位置
- exampleFile = `./data/material/backdrop_example.png`;
- md5File = `./data/material/asset/${newFileName}.png`;
- fs.copyFile(exampleFile, md5File, function (err) {
- if (err) {
- }
- });
-
- res.status(200).send({ status: "ok", msg: "操作成功" });
- });
- } catch (err) {
- next(err);
- }
-});
-// 背景管理:修改素材
-router.post("/material/backdrop/modImage", function (req, res, next) {
- try {
- if (!req["files"]["file"]) {
- res.status(200).send({ status: "x", msg: "文件上传失败,请再试一次" });
- return;
- }
-
- //保存文件到正确位置
- const tmppath = req["files"]["file"]["path"];
- arr = tmppath.split(".");
- let newExt = arr[arr.length - 1]; //取上传文件的扩展名jpg|png|gif|svg|bmp
- if (
- newExt != "jpg" &&
- newExt != "png" &&
- newExt != "gif" &&
- newExt != "svg" &&
- newExt != "bmp"
- ) {
- res.status(200).send({ status: "x", msg: "文件类型错误,请再试一次" });
- return;
- }
-
- let md5 = req.body.md5;
- const oldExt = md5.substring(md5.length - 3);
- if (oldExt == newExt) {
- // 后缀未变,直接替换
- const newpath = `./data/material/asset/${md5}`;
- fs.rename(tmppath, newpath, function (err) {
- if (err) {
- }
- });
-
- res.status(200).send({ status: "ok", msg: "修改成功", imgFile: md5 });
- } else {
- // 删除原图片文件
- fs.unlink(`./data/material/asset/${md5}`, function (err) {
- if (err) {
- console.log(err);
- }
- });
-
- md5 = md5.substring(0, md5.length - 3) + newExt; // 组合新文件名
- const newpath = `./data/material/asset/${md5}`;
- fs.rename(tmppath, newpath, function (err) {
- if (err) {
- }
- });
-
- SQL = `UPDATE material_backdrop SET md5=? WHERE id=${req.body.id}`;
- VAL = [md5];
- DB.qww(SQL, VAL, function (err, R) {
- if (err) {
- res.status(200).send({ status: "x", msg: "保存数据错误,请再试一次" });
- return;
- }
-
- res.status(200).send({ status: "ok", msg: "修改成功", imgFile: md5 });
- });
- }
- } catch (err) {
- next(err);
- }
-});
-// 背景管理:修改名称
-router.post("/material/backdrop/modName", function (req, res, next) {
- try {
- if (!req.body.v || req.body.v == "") {
- res.status(200).send({ status: "x", msg: "名称错误" });
- return;
- }
-
- var SQL = `UPDATE material_backdrop SET name=? WHERE id=?`;
- var VAL = [req.body.v, req.body.id];
- DB.qww(SQL, VAL, function (err, Mate) {
- if (err) {
- res.status(200).send({ status: "x", msg: "保存数据错误,请再试一次" });
- return;
- }
-
- res.status(200).send({ status: "ok", msg: "操作成功" });
- });
- } catch (err) {
- next(err);
- }
-});
-// 背景管理:修改尺寸
-router.post("/material/backdrop/modMateSize", function (req, res, next) {
- try {
- let infoValue = parseInt(req.body.v);
- if (req.body.t == "info0" || req.body.t == "info1") {
- if (!infoValue || infoValue < 1 || 9999 < infoValue) {
- res
- .status(200)
- .send({ status: "x", msg: "参数错误:宽、高只能在 1~9999 之间" });
- return;
- }
- } else if (req.body.t == "info2") {
- if (!infoValue || infoValue < 1 || 2 < infoValue) {
- res
- .status(200)
- .send({
- status: "x",
- msg: "参数错误!显示方式:1=铺开显示;2=原图显示",
- });
- return;
- }
- } else {
- res.status(200).send({ status: "x", msg: "参数错误" });
- return;
- }
-
- const SQL = `UPDATE material_backdrop SET ${req.body.t}=${infoValue} WHERE id=?`;
- var VAL = [req.body.id];
- DB.qww(SQL, VAL, function (err, Mate) {
- if (err) {
- res.status(200).send({ status: "x", msg: "保存数据错误,请再试一次" });
- return;
- }
-
- res.status(200).send({ status: "ok", msg: "操作成功" });
- });
- } catch (err) {
- next(err);
- }
-});
-// 背景管理:删除:未删除其文件,仅仅删除数据库记录
-router.post("/material/backdrop/del", function (req, res, next) {
- try {
- var VAL = [req.body.id];
- var SQL = `DELETE FROM material_backdrop WHERE id=?`;
- DB.qww(SQL, VAL, function (err, TAG) {
- if (err) {
- res.status(200).send({ status: "x", msg: "保存数据错误,请再试一次" });
- return;
- }
-
- res.status(200).send({ status: "ok", msg: "操作成功" });
- });
- } catch (err) {
- next(err);
- }
-});
-// 背景管理:状态管理
-router.post("/material/backdrop/setState", function (req, res, next) {
- try {
- let v = 0; //默认都当作 停用 处理
- if (req.body.v && req.body.v == 1) {
- v = 1;
- }
-
- var UPDATE = `UPDATE material_backdrop SET state=${v} WHERE id=${req.body.id} LIMIT 1`;
- DB.query(UPDATE, function (err, d) {
- if (err) {
- res.status(200).send({ status: "x", msg: "再试一次" });
- } else {
- res.status(200).send({ status: "ok", msg: "操作成功" });
- }
- });
- } catch (err) {
- next(err);
- }
-});
-
-// 造型管理:页面
-router.get("/material/costume", function (req, res, next) {
- try {
- var SQL = `SELECT id, tag FROM material_tags WHERE type=3 ORDER BY id DESC`;
- DB.query(SQL, function (err, tags) {
- if (err) {
- res.locals["tags"] = [];
- } else {
- res.locals["tags"] = tags;
- }
-
- res.render("admin/admin_material_costume.ejs");
- });
- } catch (err) {
- next(err);
- }
-});
-// 造型管理:数据
-router.get("/material/costume/data", function (req, res, next) {
- try {
- var VAL = [req.query.tagId];
- var SQL = `SELECT count(id) AS c FROM material_costume WHERE tagId=?`;
- DB.qww(SQL, VAL, function (err, count) {
- if (err || count[0]["c"] == 0) {
- res.status(200).send({ count: 0, data: [] });
- return;
- }
-
- //获取当前数据集合
- var page = parseInt(req.query["page"]);
- var limit = parseInt(req.query["limit"]);
- SQL = `SELECT * FROM material_costume WHERE tagId=? ORDER BY id DESC LIMIT ${
- (page - 1) * limit
- },${limit}`;
- DB.qww(SQL, VAL, function (err, data) {
- if (err) {
- res.status(200).send({ count: 0, data: [] });
- } else {
- res.status(200).send({ count: count[0]["c"], data: data });
- }
- });
- });
- } catch (err) {
- next(err);
- }
-});
-// 造型管理:添加
-router.post("/material/costume/add", function (req, res, next) {
- try {
- var newFileName = random_32ID_With_Time_Tag();
- const SQL = `INSERT INTO material_costume (tagId, md5) VALUES ('${req.body.tagId}', '${newFileName}.png')`;
- DB.query(SQL, function (err, newTag) {
- if (err) {
- res.status(200).send({ status: "x", msg: "保存数据错误,请再试一次" });
- return;
- }
-
- //保存文件到正确位置
- exampleFile = `./data/material/backdrop_example.png`;
- md5File = `./data/material/asset/${newFileName}.png`;
- fs.copyFile(exampleFile, md5File, function (err) {
- if (err) {
- }
- });
-
- res.status(200).send({ status: "ok", msg: "操作成功" });
- });
- } catch (err) {
- next(err);
- }
-});
-// 造型管理:修改素材文件
-router.post("/material/costume/modImage", function (req, res, next) {
- try {
- if (!req["files"]["file"]) {
- res.status(200).send({ status: "x", msg: "文件上传失败,请再试一次" });
- return;
- }
-
- //保存文件到正确位置
- const tmppath = req["files"]["file"]["path"];
- arr = tmppath.split(".");
- let newExt = arr[arr.length - 1]; //取上传文件的扩展名jpg|png|gif|svg|bmp
- if (
- newExt != "jpg" &&
- newExt != "png" &&
- newExt != "gif" &&
- newExt != "svg" &&
- newExt != "bmp"
- ) {
- res.status(200).send({ status: "x", msg: "文件类型错误,请再试一次" });
- return;
- }
-
- let md5 = req.body.md5;
- const oldExt = md5.substring(md5.length - 3);
- if (oldExt == newExt) {
- // 后缀未变,直接替换
- const newpath = `./data/material/asset/${md5}`;
- fs.rename(tmppath, newpath, function (err) {
- if (err) {
- }
- });
-
- res.status(200).send({ status: "ok", msg: "修改成功", imgFile: md5 });
- } else {
- // 删除原图片文件
- fs.unlink(`./data/material/asset/${md5}`, function (err) {
- if (err) {
- console.log(err);
- }
- });
-
- md5 = md5.substring(0, md5.length - 3) + newExt; // 组合新文件名
- const newpath = `./data/material/asset/${md5}`;
- fs.rename(tmppath, newpath, function (err) {
- if (err) {
- }
- });
-
- SQL = `UPDATE material_costume SET md5=? WHERE id=${req.body.id}`;
- VAL = [md5];
- DB.qww(SQL, VAL, function (err, R) {
- if (err) {
- res.status(200).send({ status: "x", msg: "保存数据错误,请再试一次" });
- return;
- }
-
- res.status(200).send({ status: "ok", msg: "修改成功", imgFile: md5 });
- });
- }
- } catch (err) {
- next(err);
- }
-});
-// 造型管理:修改名称
-router.post("/material/costume/modName", function (req, res, next) {
- try {
- if (!req.body.v || req.body.v == "") {
- res.status(200).send({ status: "x", msg: "名称错误" });
- return;
- }
-
- var SQL = `UPDATE material_costume SET name=? WHERE id=?`;
- var VAL = [req.body.v, req.body.id];
- DB.qww(SQL, VAL, function (err, Mate) {
- if (err) {
- res.status(200).send({ status: "x", msg: "保存数据错误,请再试一次" });
- return;
- }
-
- res.status(200).send({ status: "ok", msg: "操作成功" });
- });
- } catch (err) {
- next(err);
- }
-});
-// 造型管理:修改素材属性:尺寸
-router.post("/material/costume/modMateSize", function (req, res, next) {
- try {
- let infoValue = parseInt(req.body.v);
- if (req.body.t == "info0" || req.body.t == "info1") {
- if (!infoValue || infoValue < 1 || 9999 < infoValue) {
- res
- .status(200)
- .send({ status: "x", msg: "参数错误:宽、高只能在 1~9999 之间" });
- return;
- }
- } else if (req.body.t == "info2") {
- if (!infoValue || infoValue < 1 || 2 < infoValue) {
- res
- .status(200)
- .send({
- status: "x",
- msg: "参数错误!显示方式:1=铺开显示;2=原图显示",
- });
- return;
- }
- } else {
- res.status(200).send({ status: "x", msg: "参数错误" });
- return;
- }
-
- const SQL = `UPDATE material_costume SET ${req.body.t}=${infoValue} WHERE id=?`;
- var VAL = [req.body.id];
- DB.qww(SQL, VAL, function (err, Mate) {
- if (err) {
- res.status(200).send({ status: "x", msg: "保存数据错误,请再试一次" });
- return;
- }
-
- res.status(200).send({ status: "ok", msg: "操作成功" });
- });
- } catch (err) {
- next(err);
- }
-});
-// 造型管理:删除素材,未删除其文件,仅仅删除数据库记录
-router.post("/material/costume/del", function (req, res, next) {
- try {
- // 需要判断是否在角色中有被使用到,有被角色使用到时,不能删除
- var VAL = [req.body.id];
- var SQL = `DELETE FROM material_costume WHERE id=?`;
- DB.qww(SQL, VAL, function (err, TAG) {
- if (err) {
- res.status(200).send({ status: "x", msg: "保存数据错误,请再试一次" });
- return;
- }
-
- res.status(200).send({ status: "ok", msg: "操作成功" });
- });
- } catch (err) {
- next(err);
- }
-});
-// 造型管理:素材状态管理
-router.post("/material/costume/setState", function (req, res, next) {
- try {
- let v = 0; //默认都当作 停用 处理
- if (req.body.v && req.body.v == 1) {
- v = 1;
- }
-
- var UPDATE = `UPDATE material_costume SET state=${v} WHERE id=${req.body.id} LIMIT 1`;
- DB.query(UPDATE, function (err, d) {
- if (err) {
- res.status(200).send({ status: "x", msg: "再试一次" });
- } else {
- res.status(200).send({ status: "ok", msg: "操作成功" });
- }
- });
- } catch (err) {
- next(err);
- }
-});
-
-// 角色管理:页面
-router.get("/material/sprite", function (req, res, next) {
- try {
- var SQL = `SELECT id, tag FROM material_tags WHERE type=2 ORDER BY id DESC`;
- DB.query(SQL, function (err, tags) {
- if (err) {
- res.locals["tags"] = [];
- } else {
- res.locals["tags"] = tags;
- }
-
- res.render("admin/admin_material_sprite.ejs");
- });
- } catch (err) {
- next(err);
- }
-});
-// 角色管理:页面数据
-router.get("/material/sprite/data", function (req, res, next) {
- try {
- var VAL = [req.query.tagId];
- var SQL = `SELECT count(id) AS c FROM material_sprite WHERE tagId=?`;
- DB.qww(SQL, VAL, function (err, count) {
- if (err || count[0]["c"] == 0) {
- res.status(200).send({ count: 0, data: [] });
- return;
- }
-
- //获取当前数据集合
- var page = parseInt(req.query["page"]);
- var limit = parseInt(req.query["limit"]);
- SQL = `SELECT * FROM material_sprite WHERE tagId=? ORDER BY id DESC LIMIT ${
- (page - 1) * limit
- },${limit}`;
- DB.qww(SQL, VAL, function (err, data) {
- if (err) {
- res.status(200).send({ count: 0, data: [] });
- } else {
- res.status(200).send({ count: count[0]["c"], data: data });
- }
- });
- });
- } catch (err) {
- next(err);
- }
-});
-// 角色管理:添加
-router.post("/material/sprite/add", function (req, res, next) {
- try {
- const sprite = require("./lib/scratch_default_sprite.js"); // 默认角色
- const SQL = `INSERT INTO material_sprite (tagId, json) VALUES (?, ?)`;
- const VAL = [req.body.tagId, sprite];
- DB.qww(SQL, VAL, function (err, R) {
- if (err) {
- res.status(200).send({ status: "x", msg: "保存数据错误,请再试一次" });
- return;
- }
-
- res.status(200).send({ status: "ok", msg: "操作成功" });
- });
- } catch (err) {
- next(err);
- }
-});
-// 角色管理:删除素材,未删除其文件,仅仅删除数据库记录
-router.post("/material/sprite/del", function (req, res, next) {
- try {
- // 需要判断是否在角色中有被使用到,有被角色使用到时,不能删除
- var VAL = [req.body.id];
- var SQL = `DELETE FROM material_sprite WHERE id=?`;
- DB.qww(SQL, VAL, function (err, TAG) {
- if (err) {
- res.status(200).send({ status: "x", msg: "保存数据错误,请再试一次" });
- return;
- }
-
- res.status(200).send({ status: "ok", msg: "操作成功" });
- });
- } catch (err) {
- next(err);
- }
-});
-// 角色管理:导入角色:作品数据
-router.get("/material/sprite/worklist", function (req, res, next) {
- try {
- var _title = "";
- if (req.query["t"] != undefined && req.query["t"] != "") {
- _title = ` AND title LIKE '%${req.query["t"]}%' `;
- }
-
- var SQL = `SELECT count(id) AS c FROM scratch WHERE authorid=${res.locals.userid} ${_title}`;
- DB.query(SQL, function (err, count) {
- if (err || count.length == 0 || count[0].c == 0) {
- res.status(200).send({ count: 0, data: [] });
- return;
- }
-
- //获取当前数据集合
- var page = parseInt(req.query["page"]);
- var limit = parseInt(req.query["limit"]);
- var SQL = `SELECT id,title FROM scratch WHERE authorid=${
- res.locals.userid
- } ${_title} ORDER BY time DESC LIMIT ${(page - 1) * limit}, ${limit}`;
- DB.query(SQL, function (err, data) {
- if (err) {
- res.status(200).send({ count: 0, data: [] });
- } else {
- res.status(200).send({ count: count[0].c, data: data });
- }
- });
- });
- } catch (err) {
- next(err);
- }
-});
-// 角色管理:导入角色:导入{tagid: _tagId, workid:select_data.id}
-router.post("/material/sprite/import", function (req, res, next) {
- try {
- // 1、获取作品src
- var SELECT = `SELECT src FROM scratch WHERE id=${req.body.workid} LIMIT 1`;
- DB.query(SELECT, function (err, SRC) {
- if (err || SRC.length == 0) {
- res.status(200).send({ status: "x", msg: "再试一次" });
- return;
- }
-
- // 组合角色数据 values="(),(),()"
- let spriteCount = 0;
- let values = "";
- let targets = JSON.parse(SRC[0].src).targets;
- for (var i = 0; i < targets.length; i++) {
- if (!targets[i].isStage) {
- let json = {};
- json["costumes"] = targets[i]["costumes"];
- json["sounds"] = targets[i]["sounds"];
-
- if (values != "") {
- values += ",";
- }
-
- values += `(${req.body.tagid}, '${targets[i].name}', '${JSON.stringify(
- json
- ).replace(/'/g, "’")}')`;
-
- spriteCount++;
- }
- }
-
- if (spriteCount == 0) {
- res.status(200).send({ status: "ok", msg: "作品中无角色数据" });
- }
-
- var SQL = `INSERT INTO material_sprite(tagId, name, json) VALUES ${values}`;
- DB.query(SQL, function (err, D) {
- if (err) {
- res.status(200).send({ status: "x", msg: "操作失败,请再试一次" });
- return;
- }
-
- res
- .status(200)
- .send({ status: "ok", msg: `操作成功,导入角色数:${spriteCount}` });
- });
- });
- } catch (err) {
- next(err);
- }
-});
-// 角色管理:修改名称
-router.post("/material/sprite/modName", function (req, res, next) {
- try {
- if (!req.body.v || req.body.v == "") {
- res.status(200).send({ status: "x", msg: "名称错误" });
- return;
- }
-
- var SQL = `UPDATE material_sprite SET name=? WHERE id=?`;
- var VAL = [req.body.v, req.body.id];
- DB.qww(SQL, VAL, function (err, Mate) {
- if (err) {
- res.status(200).send({ status: "x", msg: "保存数据错误,请再试一次" });
- return;
- }
-
- res.status(200).send({ status: "ok", msg: "操作成功" });
- });
- } catch (err) {
- next(err);
- }
-});
-// 角色管理:素材状态管理
-router.post("/material/sprite/setState", function (req, res, next) {
- try {
- let v = 0; //默认都当作 停用 处理
- if (req.body.v && req.body.v == 1) {
- v = 1;
- }
-
- var UPDATE = `UPDATE material_sprite SET state=${v} WHERE id=${req.body.id} LIMIT 1`;
- DB.query(UPDATE, function (err, d) {
- if (err) {
- res.status(200).send({ status: "x", msg: "再试一次" });
- } else {
- res.status(200).send({ status: "ok", msg: "操作成功" });
- }
- });
- } catch (err) {
- next(err);
- }
-});
-
-// 角色管理:造型管理 页面
-router.get("/material/sprite/setCostume", function (req, res, next) {
- try {
- res.locals._id = req.query["id"];
- res.render("admin/admin_material_sprite_costume.ejs");
- } catch (err) {
- next(err);
- }
-});
-// 角色管理:造型管理 页面数据
-router.get("/material/sprite/setCostume/data", function (req, res, next) {
- try {
- var SQL = `SELECT json FROM material_sprite WHERE id=${req.query["id"]} LIMIT 1`;
- DB.query(SQL, function (err, D) {
- if (err || D.length == 0) {
- res.status(200).send({ status: "x", data: "" });
- return;
- }
-
- res.status(200).send({ status: "ok", data: D[0].json });
- });
- } catch (err) {
- next(err);
- }
-});
-// 角色管理:造型管理:删除素材,未删除其文件,仅仅删除数据库记录
-// 参数:{id: _id, index: obj.data.index, md5: obj.data.md5ext}
-router.post("/material/sprite/setCostume/del", function (req, res, next) {
- try {
- // 需要判断是否在角色中有被使用到,有被角色使用到时,不能删除
- var SQL = `SELECT json FROM material_sprite WHERE id=?`;
- var VAL = [req.body.id];
- DB.qww(SQL, VAL, function (err, D) {
- if (err || D.length == 0) {
- res.status(200).send({ status: "x", msg: "数据错误,请再试一次" });
- return;
- }
-
- let json = JSON.parse(D[0].json); // json 包含了造型与声音
- if (json.costumes.length < 2) {
- // 角色的造型,必须最少有一个造型
- res.status(200).send({ status: "x", msg: "角色最少有一个造型" });
- return;
- }
-
- // 判断要移除的造型是否存在
- var costume = json.costumes[req.body.index];
- if (!costume || costume.md5ext != req.body.md5) {
- res.status(200).send({ status: "x", msg: "数据错误,请再试一次" });
- return;
- }
-
- // 移除造型 并 保存
- json.costumes.splice(req.body.index, 1);
- SQL = `UPDATE material_sprite SET json='${JSON.stringify(json)}' WHERE id=${
- req.body.id
- }`;
- DB.query(SQL, function (err, D1) {
- if (err) {
- res.status(200).send({ status: "x", msg: "数据错误,请再试一次" });
- return;
- }
-
- res.status(200).send({ status: "ok", msg: "操作成功" });
- });
- });
- } catch (err) {
- next(err);
- }
-});
-// 角色管理:造型管理:添加造型时,可选择造型 数据
-// {text: 搜索文本,默认为空:''}
-router.get("/material/sprite/setCostume/select", function (req, res, next) {
- try {
- var SQL = `SELECT count(id) AS c FROM material_costume WHERE name LIKE '%${req.query.text}%'`;
- DB.query(SQL, function (err, count) {
- if (err || count[0]["c"] == 0) {
- res.status(200).send({ count: 0, data: [] });
- return;
- }
-
- //获取当前数据集合
- var page = parseInt(req.query["page"]);
- var limit = parseInt(req.query["limit"]);
- SQL =
- `SELECT c.id, c.name, t.tag FROM material_costume c ` +
- ` LEFT JOIN material_tags t ON (c.tagId = t.id) ` +
- ` WHERE c.name LIKE '%${req.query.text}%' LIMIT ${
- (page - 1) * limit
- },${limit}`;
- DB.query(SQL, function (err, data) {
- if (err) {
- res.status(200).send({ count: 0, data: [] });
- } else {
- res.status(200).send({ count: count[0]["c"], data: data });
- }
- });
- });
- } catch (err) {
- next(err);
- }
-});
-// 角色管理:造型管理:添加
-// {sid: 角色ID, cid: 将被添加的造型ID}
-router.post("/material/sprite/setCostume/add", function (req, res, next) {
- try {
- // 取造型数据
- let SQL =
- `SELECT c.name, c.md5, c.info0, c.info1, c.info2, s.json FROM material_costume c` +
- ` LEFT JOIN material_sprite s ON (s.id=?) ` +
- ` WHERE c.id=?`;
- let VAL = [req.body.sid, req.body.cid];
- DB.qww(SQL, VAL, function (err, D) {
- if (err || D.length == 0) {
- res.status(200).send({ status: "x", msg: "数据错误,请再试一次" });
- return;
- }
-
- // 组合数据
- const md5 = D[0].md5.split(".");
- let newCostume = {
- name: D[0].name, // 名称
- assetId: md5[0] ? md5[0] : "error", // md5ext前部分
- dataFormat: md5[1] ? md5[1] : "error", // md5ext 后部分
- md5ext: D[0].md5,
- rotationCenterX: D[0].info0, // info0
- rotationCenterY: D[0].info1, // info1
- bitmapResolution: D[0].info2, // info2
- };
-
- let json = JSON.parse(D[0].json);
- json.costumes.push(newCostume);
-
- SQL = `UPDATE material_sprite SET json='${JSON.stringify(json)}' WHERE id=${
- req.body.sid
- }`;
- DB.query(SQL, function (err, D) {
- if (err) {
- res.status(200).send({ status: "x", msg: "数据错误,请再试一次" });
- return;
- }
-
- res.status(200).send({ status: "ok", msg: "操作成功" });
- });
- });
- } catch (err) {
- next(err);
- }
-});
-
-// 角色管理:声音管理 页面
-router.get("/material/sprite/setSound", function (req, res, next) {
- try {
- res.locals._id = req.query["id"];
- res.render("admin/admin_material_sprite_sound.ejs");
- } catch (err) {
- next(err);
- }
-});
-// 角色管理:声音管理 页面 数据
-router.get("/material/sprite/setSound/data", function (req, res, next) {
- try {
- var SQL = `SELECT json FROM material_sprite WHERE id=${req.query["id"]} LIMIT 1`;
- DB.query(SQL, function (err, D) {
- if (err || D.length == 0) {
- res.status(200).send({ status: "x", data: "" });
- return;
- }
-
- res.status(200).send({ status: "ok", data: D[0].json });
- });
- } catch (err) {
- next(err);
- }
-});
-// 角色管理:声音管理:删除素材,未删除其文件,仅仅删除数据库记录
-// 参数:{id: _id, index: obj.data.index, md5: obj.data.md5ext}
-router.post("/material/sprite/setSound/del", function (req, res, next) {
- try {
- // 需要判断是否在角色中有被使用到,有被角色使用到时,不能删除
- var SQL = `SELECT json FROM material_sprite WHERE id=?`;
- var VAL = [req.body.id];
- DB.qww(SQL, VAL, function (err, D) {
- if (err || D.length == 0) {
- res.status(200).send({ status: "x", msg: "数据错误,请再试一次" });
- return;
- }
-
- let json = JSON.parse(D[0].json); // json 包含了造型与声音
- if (json.sounds.length < 2) {
- // 角色的声音,必须最少有一个声音
- res.status(200).send({ status: "x", msg: "角色最少有一个声音" });
- return;
- }
-
- // 判断要移除的声音是否存在
- var sound = json.sounds[req.body.index];
- if (!sound || sound.md5ext != req.body.md5) {
- res.status(200).send({ status: "x", msg: "数据错误,请再试一次" });
- return;
- }
-
- // 移除 并 保存
- json.sounds.splice(req.body.index, 1);
- SQL = `UPDATE material_sprite SET json='${JSON.stringify(json)}' WHERE id=${
- req.body.id
- }`;
- DB.query(SQL, function (err, D1) {
- if (err) {
- res.status(200).send({ status: "x", msg: "数据错误,请再试一次" });
- return;
- }
-
- res.status(200).send({ status: "ok", msg: "操作成功" });
- });
- });
- } catch (err) {
- next(err);
- }
-});
-// 角色管理:声音管理:添加声音时,可选择声音 数据
-// {text: 搜索文本,默认为空:''}
-router.get("/material/sprite/setSound/select", function (req, res, next) {
- try {
- var SQL = `SELECT count(id) AS c FROM material_sound WHERE name LIKE '%${req.query.text}%'`;
- DB.query(SQL, function (err, count) {
- if (err || count[0]["c"] == 0) {
- res.status(200).send({ count: 0, data: [] });
- return;
- }
-
- //获取当前数据集合
- var page = parseInt(req.query["page"]);
- var limit = parseInt(req.query["limit"]);
- SQL =
- `SELECT c.id, c.name, t.tag FROM material_sound c ` +
- ` LEFT JOIN material_tags t ON (c.tagId = t.id) ` +
- ` WHERE c.name LIKE '%${req.query.text}%' LIMIT ${
- (page - 1) * limit
- },${limit}`;
- DB.query(SQL, function (err, data) {
- if (err) {
- res.status(200).send({ count: 0, data: [] });
- } else {
- res.status(200).send({ count: count[0]["c"], data: data });
- }
- });
- });
- } catch (err) {
- next(err);
- }
-});
-// 角色管理:声音管理:添加
-// {sid: 角色ID, cid: 将被添加的声音ID}
-router.post("/material/sprite/setSound/add", function (req, res, next) {
- try {
- // 取声音数据
- let SQL =
- `SELECT c.name, c.md5, c.format, c.rate, c.sampleCount, s.json FROM material_sound c` +
- ` LEFT JOIN material_sprite s ON (s.id=?) ` +
- ` WHERE c.id=?`;
- let VAL = [req.body.sid, req.body.cid];
- DB.qww(SQL, VAL, function (err, D) {
- if (err || D.length == 0) {
- res.status(200).send({ status: "x", msg: "数据错误,请再试一次" });
- return;
- }
-
- // 组合数据
- const md5 = D[0].md5.split(".");
- let newSound = {
- name: D[0].name, // 名称
- assetId: md5[0] ? md5[0] : "error", // md5ext前部分
- dataFormat: md5[1] ? md5[1] : "error", // md5ext 后部分
- md5ext: D[0].md5,
- format: D[0].format, // format
- rate: D[0].rate, // rate
- sampleCount: D[0].sampleCount, // sampleCount
- };
-
- let json = JSON.parse(D[0].json);
- json.sounds.push(newSound);
-
- SQL = `UPDATE material_sprite SET json='${JSON.stringify(json)}' WHERE id=${
- req.body.sid
- }`;
- DB.query(SQL, function (err, D) {
- if (err) {
- res.status(200).send({ status: "x", msg: "数据错误,请再试一次" });
- return;
- }
-
- res.status(200).send({ status: "ok", msg: "操作成功" });
- });
- });
- } catch (err) {
- next(err);
- }
-});
-
-// 声音管理:页面
-router.get("/material/sound", function (req, res, next) {
- try {
- var SQL = `SELECT id, tag FROM material_tags WHERE type=4 ORDER BY id DESC`;
- DB.query(SQL, function (err, tags) {
- if (err) {
- res.locals["tags"] = [];
- } else {
- res.locals["tags"] = tags;
- }
-
- res.render("admin/admin_material_sound.ejs");
- });
- } catch (err) {
- next(err);
- }
-});
-// 声音管理:数据
-router.get("/material/sound/data", function (req, res, next) {
- try {
- var VAL = [req.query.tagId];
- var SQL = `SELECT count(id) AS c FROM material_sound WHERE tagId=?`;
- DB.qww(SQL, VAL, function (err, count) {
- if (err || count[0]["c"] == 0) {
- res.status(200).send({ count: 0, data: [] });
- return;
- }
-
- //获取当前数据集合
- var page = parseInt(req.query["page"]);
- var limit = parseInt(req.query["limit"]);
- SQL = `SELECT * FROM material_sound WHERE tagId=? ORDER BY id DESC LIMIT ${
- (page - 1) * limit
- },${limit}`;
- DB.qww(SQL, VAL, function (err, data) {
- if (err) {
- res.status(200).send({ count: 0, data: [] });
- } else {
- res.status(200).send({ count: count[0]["c"], data: data });
- }
- });
- });
- } catch (err) {
- next(err);
- }
-});
-// 声音管理:添加
-router.post("/material/sound/add", function (req, res, next) {
- try {
- // 仅仅支持wav格式的声音素材
- var newFileName = random_32ID_With_Time_Tag() + ".wav";
- const SQL = `INSERT INTO material_sound (tagId, md5) VALUES ('${req.body.tagId}', '${newFileName}')`;
- DB.query(SQL, function (err, newTag) {
- if (err) {
- res.status(200).send({ status: "x", msg: "保存数据错误,请再试一次" });
- return;
- }
-
- //保存文件到正确位置
- exampleFile = `./data/material/sound_example.wav`;
- md5File = `./data/material/asset/${newFileName}`;
- fs.copyFile(exampleFile, md5File, function (err) {
- if (err) {
- }
- });
-
- res.status(200).send({ status: "ok", msg: "操作成功" });
- });
- } catch (err) {
- next(err);
- }
-});
-// 声音管理:修改素材文件
-router.post("/material/sound/modWav", function (req, res, next) {
- try {
- if (!req["files"]["file"]) {
- res.status(200).send({ status: "x", msg: "文件上传失败,请再试一次" });
- return;
- }
-
- const tmppath = req["files"]["file"]["path"];
- arr = tmppath.split(".");
- let newExt = arr[arr.length - 1]; //取上传文件的扩展名wav
- if (newExt != "wav") {
- res.status(200).send({ status: "x", msg: "文件类型错误,请再试一次" });
- return;
- }
-
- const SQL = `SELECT md5 FROM material_sound WHERE id=?`;
- const VAL = [req.body.id];
- DB.qww(SQL, VAL, function (err, DATA) {
- if (err || DATA.length == 0) {
- res.status(200).send({ status: "x", msg: "保存数据错误,请再试一次" });
- return;
- }
-
- //保存文件
- const newpath = `./data/material/asset/${DATA[0].md5}`;
- fs.rename(tmppath, newpath, function (err) {
- if (err) {
- }
- });
-
- res.status(200).send({ status: "ok", msg: "修改成功" });
- });
- } catch (err) {
- next(err);
- }
-});
-// 声音管理:修改名称
-router.post("/material/sound/modName", function (req, res, next) {
- try {
- if (!req.body.v || req.body.v == "") {
- res.status(200).send({ status: "x", msg: "名称错误" });
- return;
- }
-
- var SQL = `UPDATE material_sound SET name=? WHERE id=?`;
- var VAL = [req.body.v, req.body.id];
- DB.qww(SQL, VAL, function (err, Mate) {
- if (err) {
- res.status(200).send({ status: "x", msg: "保存数据错误,请再试一次" });
- return;
- }
-
- res.status(200).send({ status: "ok", msg: "操作成功" });
- });
- } catch (err) {
- next(err);
- }
-});
-// 声音管理:修改素材属性:rate/sampleCount
-router.post("/material/sound/modMateAttr", function (req, res, next) {
- try {
- if (req.body.t != "sampleCount") {
- res.status(200).send({ status: "x", msg: "参数错误" });
- return;
- }
-
- let infoValue = parseInt(req.body.v);
- if (!infoValue || infoValue < 0 || 10000000 < infoValue) {
- res
- .status(200)
- .send({ status: "x", msg: "参数错误:只能在 0~1000,0000 之间" });
- return;
- }
-
- const SQL = `UPDATE material_sound SET sampleCount=${infoValue} WHERE id=?`;
- var VAL = [req.body.id];
- DB.qww(SQL, VAL, function (err, Mate) {
- if (err) {
- res.status(200).send({ status: "x", msg: "保存数据错误,请再试一次" });
- return;
- }
-
- res.status(200).send({ status: "ok", msg: "操作成功" });
- });
- } catch (err) {
- next(err);
- }
-});
-// 声音管理:删除素材,未删除其文件,仅仅删除数据库记录
-router.post("/material/sound/del", function (req, res, next) {
- try {
- // 需要判断是否在角色中有被使用到,有被角色使用到时,不能删除
- var VAL = [req.body.id];
- var SQL = `DELETE FROM material_sound WHERE id=?`;
- DB.qww(SQL, VAL, function (err, TAG) {
- if (err) {
- res.status(200).send({ status: "x", msg: "保存数据错误,请再试一次" });
- return;
- }
-
- res.status(200).send({ status: "ok", msg: "操作成功" });
- });
- } catch (err) {
- next(err);
- }
-});
-// 声音管理:素材状态管理
-router.post("/material/sound/setState", function (req, res, next) {
- try {
- let v = 0; //默认都当作 停用 处理
- if (req.body.v && req.body.v == 1) {
- v = 1;
- }
-
- var UPDATE = `UPDATE material_sound SET state=${v} WHERE id=${req.body.id} LIMIT 1`;
- DB.query(UPDATE, function (err, d) {
- if (err) {
- res.status(200).send({ status: "x", msg: "再试一次" });
- } else {
- res.status(200).send({ status: "ok", msg: "操作成功" });
- }
- });
- } catch (err) {
- next(err);
- }
-});
-
-// 清理scratch缩略图
-router.get("/clear_scratch_slt", function (req, res, next) {
- try {
- var SQL = "SELECT id FROM scratch";
- DB.query(SQL, function (err, data) {
- if (err) {
- res.status(200).send("清理scratch缩略图数据库查询出错!");
- return;
- }
-
- // 把缩略图目录
- var slt_path = "./data/scratch_slt";
- var backup_time = new Date().getTime().toString(16);
- var backup_path = `./data/scratch_slt_backup_${backup_time}`;
- try {
- fs.renameSync(slt_path, backup_path);
- } catch (e) {
- res.status(200).send("备份缩略图文件夹出错!");
- return;
- }
- try {
- fs.mkdirSync(slt_path);
- } catch (e) {
- res.status(200).send("创建缩略图文件夹出错!");
- return;
- }
-
- for (var i = data.length - 1; i >= 0; i--) {
- let slt_old = `${backup_path}/${data[i].id}`;
- let slt = `${slt_path}/${data[i].id}`;
-
- fs.copyFile(slt_old, slt, function (err) {
- if (err) {
- }
- });
- }
-
- res.status(200).send("OK!");
- });
- } catch (err) {
- next(err);
- }
-});
-
-module.exports = router;
diff --git a/server/router_api.js b/server/router_api.js
index da33876..c284652 100644
--- a/server/router_api.js
+++ b/server/router_api.js
@@ -85,7 +85,11 @@ router.get("/usertx", async function (req, res, next) {
DB.query(SQL, async function (err, USER) {
if (err || USER.length == 0) {
res.locals.tip = { opt: "flash", msg: "用户不存在" };
- res.render("404.ejs");
+ res.status(404).json({
+ status: "error",
+ code: "404",
+ message: "找不到页面",
+ });
return;
}
res.redirect(302, await configManager.getConfig('s3.staticurl') + "/user/" + USER[0].images);
@@ -127,7 +131,11 @@ router.get("/getuserinfo", async function (req, res, next) {
if (!user[0]) {
console.log("用户不存在");
res.locals.tip = { opt: "flash", msg: "用户不存在" };
- res.render("404.ejs");
+ res.status(404).json({
+ status: "error",
+ code: "404",
+ message: "找不到页面",
+ });
}
res.send({
status: "ok",
diff --git a/server/router_my.js b/server/router_my.js
index 70056f4..cfbb3a0 100644
--- a/server/router_my.js
+++ b/server/router_my.js
@@ -32,51 +32,6 @@ router.get("/project", function (req, res) {
res.redirect("/my/scratch");
});
-//作品
-router.get("/scratch", function (req, res) {
- var SQL =
- `SELECT ` +
- ` count(case when state='private' then 1 end) AS state0_count, ` +
- ` count(case when state='public' then 1 end) AS state1_count, ` +
- ` '' AS state2_count ` +
- ` FROM scratch WHERE authorid=${res.locals["userid"]}`;
-
- DB.query(SQL, function (err, data) {
- if (err) {
- res.locals.state0_count = 0;
- res.locals.state1_count = 0;
- res.locals.state2_count = 0;
- } else {
- res.locals.state0_count = data[0].state0_count;
- res.locals.state1_count = data[0].state1_count;
- res.locals.state2_count = data[0].state2_count;
- }
- res.render("scratch/my_scratch_projects.ejs");
- });
-});
-
-//作品
-router.get("/python", function (req, res) {
- var SQL =
- `SELECT ` +
- ` count(case when state='private' then 1 end) AS state0_count, ` +
- ` count(case when state='public' then 1 end) AS state1_count, ` +
- ` '' AS state2_count ` +
- ` FROM python WHERE authorid=${res.locals.userid}`;
-
- DB.query(SQL, function (err, data) {
- if (err) {
- res.locals.state0_count = 0;
- res.locals.state1_count = 0;
- res.locals.state2_count = 0;
- } else {
- res.locals.state0_count = data[0].state0_count;
- res.locals.state1_count = data[0].state1_count;
- res.locals.state2_count = data[0].state2_count;
- }
- res.render("python/my_python_projects.ejs");
- });
-});
//显示Scratch项目列表:数据,{curr:obj.curr, limit:obj.limit,state:state}
router.get("/getScratchProjects", function (req, res) {
var curr = parseInt(req.query.curr); //当前要显示的页码
@@ -293,10 +248,6 @@ router.post("/project/del", function (req, res) {
res.status(200).send({ status: "success", msg: "删除成功" });
});
});
-//个人设置
-router.get("/info", function (req, res) {
- res.render("my_info.ejs");
-});
//修改头像
router.post("/set/avatar", geetest, function (req, res) {
//保存文件到正确位置
diff --git a/server/router_python.js b/server/router_python.js
deleted file mode 100644
index ba24ad2..0000000
--- a/server/router_python.js
+++ /dev/null
@@ -1,324 +0,0 @@
-const configManager = require("./configManager");
-
-var express = require("express");
-var router = express.Router();
-
-var DB = require("./lib/database.js"); // 数据库
-
-router.all("*", function (req, res, next) {
- next();
-});
-//router.get('/', function (req, res) {})
-
-//首页
-router.get("/", function (req, res, next) {
- try {
- res.render("python/python_projects.ejs");
- } catch (err) {
- next(err);
- }
-});
-//首页
-router.get("/next", function (req, res, next) {
- try {
- res.render("python/next_python_play.ejs");
- } catch (err) {
- next(err);
- }
-});
-router.get("/pythoncount", function (req, res, next) {
- try {
- //获取已分享的作品总数:1:普通作品,2:推荐的优秀作品
- var SQL =
- `SELECT ` +
- ` (SELECT count(id) FROM ow_projects WHERE state='public' ) AS python_count `;
- DB.query(SQL, function (err, data) {
- if (err) {
- // console.error('数据库操作出错:');
- res.locals.python_count = 0;
- } else {
- res.locals.python_count = data[0].python_count;
- }
- res.status(200).send(data[0]);
- });
- } catch (err) {
- next(err);
- }
-});
-//翻页:Python作品列表:数据
-router.get("/view/getPythonProjects", function (req, res, next) {
- try {
- var curr = parseInt(req.query.curr); //当前要显示的页码
- var limit = parseInt(req.query.limit); //每页显示的作品数
- var type = "view_count";
- if (req.query.type == "new") {
- type = "time";
- }
-
- var SQL = `SELECT ow_projects.id, ow_projects.title, ow_projects.state,ow_projects.authorid, ow_projects.description,ow_projects.view_count,ow_users.display_name,ow_users.motto FROM ow_projects JOIN ow_users ON ow_projects.authorid = ow_users.id WHERE ow_projects.state='public' AND ow_projects.type='python' ORDER BY ow_projects.${type} DESC LIMIT ${
- (curr - 1) * limit
- }, ${limit}`;
- DB.query(SQL, function (err, data) {
- if (err) {
- res.status(200).send([]);
- } else {
- res.status(200).send(data);
- }
- });
- } catch (err) {
- next(err);
- }
-});
-
-//搜索:Scratch项目列表:数据//只搜索标题
-router.get("/view/seachPythonProjects", function (req, res, next) {
- try {
- if (!req.query.txt) {
- res.status(200).send([]);
- return;
- }
- var tabelName = "python";
- var searchinfo = "title";
- if (req.query.searchall == "true") {
- searchinfo = "source";
- }
- //var SQL = `SELECT id, title FROM ow_projects WHERE state='public' AND (${searchinfo} LIKE ?) LIMIT 12`;
- var SQL = `SELECT ow_projects.id, ow_projects.title, ow_projects.state,ow_projects.authorid,ow_projects.description,ow_projects.view_count, ow_users.display_name,ow_users.motto FROM ow_projects JOIN ow_users ON ow_projects.authorid = ow_users.id WHERE ow_projects.state='public' AND (${searchinfo} LIKE ?) AND ow_projects.type='${tabelName}'`;
- var WHERE = [`%${req.query.txt}%`];
- DB.qww(SQL, WHERE, function (err, data) {
- if (err) {
- res.status(200).send([]);
- } else {
- res.status(200).send(data);
- }
- });
- } catch (err) {
- next(err);
- }
-});
-
-//python项目展示界面
-router.get("/play", function (req, res, next) {
- try {
- res.render("python/python_play.ejs");
- } catch (err) {
- next(err);
- }
-});
-
-//python项目编辑界面:获取项目源代码
-router.get("/edit", function (req, res, next) {
- try {
- res.render("python/python_edit.ejs");
- } catch (err) {
- next(err);
- }
-});
-
-// 从数据库获取作品
-router.post("/getWork", function (req, res, next) {
- try {
- var projectid = 0;
- if (req.body.id && req.body.id > 1) {
- projectid = req.body.id;
- }
-
- if (projectid == 0 || projectid == 1) {
- // 默认作品
- //***当把该块注释后,则从数据库加载默认作品***
- //从指定文件加载默认作品:BEGIN==========================================
- var DefaultPython = {
- id: 0,
- title: "Python新项目",
- state: 0,
- source: `import turtle\n\nt = turtle.Turtle()\nt.forward(100)\n\nprint ("Welcome to ZeroCat!")`,
- };
- if (projectid == 1) {
- res.status(200).send({ status: "ok", work: DefaultPython });
- return;
- }
- //从指定文件加载默认作品:END============================================
- //*/
- SQL = `SELECT * FROM ow_projects WHERE id=1`; //默认作品为1号作品
- } else {
- if (!res.locals.login) {
- //未登录时,只能打开已发布的作品
- SQL = `SELECT * FROM ow_projects WHERE id=${projectid} AND state='public'`;
- } else {
- //作品编辑:能够打开一个作品的几种权限:
- //1、自己的作品;
- //2、开源的作品;
- SQL = `SELECT * FROM ow_projects WHERE id=${projectid} AND (authorid=${res.locals.userid} OR state='public')`;
- }
- }
-
- DB.query(SQL, function (err, WORK) {
- if (err || WORK.length == 0) {
- res.status(200).send({ status: "x", msg: "作品不存在或无权打开" }); //需要前端内部处理
- } else {
- var UPDATE = `UPDATE ow_projects SET view_count=view_count+1 WHERE id=${projectid} LIMIT 1`;
- DB.query(UPDATE, function (err, s) {
- if (err) {
- }
- });
-
- if (WORK[0].id == 1) {
- WORK[0].id = 0; // 通知浏览器作品ID为0
- }
- res.status(200).send({ status: "ok", work: WORK[0] });
- }
- });
- } catch (err) {
- next(err);
- }
-});
-
-// python 保存
-router.post("/save", function (req, res, next) {
- try {
- if (!res.locals.userid) {
- res.status(200).send({ status: "0", msg: "请先登录" });
- return;
- }
-
- // 新作品
- if (req.body.id == "0") {
- var INSERT = `INSERT INTO ow_projects (authorid, title,source) VALUES (${res.locals.userid}, ?, ?)`;
- var SET = [req.body.title, req.body.data];
- DB.qww(INSERT, SET, function (err, newPython) {
- if (err || newPython.affectedRows == 0) {
- res.status(200).send({ status: "0", msg: "保存失败" });
- return;
- }
-
- res
- .status(200)
- .send({ status: "ok", msg: "保存成功", newid: newPython["insertId"] });
- });
-
- return;
- }
-
- // 旧作品
- var UPDATE = `UPDATE ow_projects SET ? WHERE id=${req.body.id} AND authorid=${res.locals.userid} LIMIT 1`;
- var SET = {
- title: req.body.title,
- source: req.body.data,
- description: req.body.description,
- };
- DB.qww(UPDATE, SET, function (err, u) {
- if (err) {
- res.status(200).send({ status: "0", msg: "保存失败" });
- return;
- }
-
- res.status(200).send({ status: "ok", msg: "保存成功" });
- });
- } catch (err) {
- next(err);
- }
-});
-
-router.post("/publish", function (req, res, next) {
- try {
- if (!res.locals.userid) {
- res.status(200).send({ status: "0", msg: "请先登录" });
- return;
- }
-
- var state = req.body.s == "0" ? 1 : 0;
- var UPDATE = `UPDATE ow_projects SET state=${state} WHERE id=${req.body.id} AND authorid=${res.locals.userid} LIMIT 1`;
- DB.query(UPDATE, function (err, u) {
- if (err) {
- res.status(200).send({ status: "0", msg: "操作失败!" });
- return;
- }
-
- res.status(200).send({ status: "ok", msg: "操作成功" });
- });
- } catch (err) {
- next(err);
- }
-});
-
-// python 优秀作品
-router.post("/YxLibrary_count", function (req, res, next) {
- try {
- var SQL = `SELECT count(id) AS c FROM ow_projects WHERE state='public'`;
- DB.query(SQL, function (err, COUNT) {
- if (err) {
- res.status(200).send({ status: "ok", total: 0 });
- } else {
- res.status(200).send({ status: "ok", total: COUNT[0].c });
- }
- });
- } catch (err) {
- next(err);
- }
-});
-//显示Python项目列表:数据,流加载模式
-router.post("/YxLibrary_data", function (req, res, next) {
- try {
- //获取当前数据集合:以被浏览次数降序排列,每次取16个
- var page = parseInt(req.body.page);
- SQL =
- `SELECT ow_projects.id, ow_projects.authorid, ow_projects.view_count, ow_projects.time, ow_projects.title, ow_projects.description, ow_users.display_name AS author_display_name FROM ow_projects ` +
- ` LEFT JOIN ow_users ON ow_users.id=ow_projects.authorid ` +
- ` WHERE ow_projects.state='public' ORDER BY ow_projects.view_count DESC LIMIT ${
- (page - 1) * 16
- },${16}`;
- DB.query(SQL, function (err, data) {
- if (err) {
- res.status(200).send({ status: "ok", data: [] });
- } else {
- res.status(200).send({ status: "ok", data: data });
- }
- });
- } catch (err) {
- next(err);
- }
-});
-
-router.all("*", function (req, res, next) {
- if (!res.locals.userid) {
- res.status(200).send({ status: "0", msg: "请先登录" });
- return;
- }
-
- next();
-});
-
-router.post("/MyLibrary_count", function (req, res, next) {
- try {
- var SQL = `SELECT count(id) AS c FROM ow_projects WHERE authorid=${res.locals.userid}`;
- DB.query(SQL, function (err, COUNT) {
- if (err) {
- res.status(200).send({ status: "ok", total: 0 });
- } else {
- res.status(200).send({ status: "ok", total: COUNT[0].c });
- }
- });
- } catch (err) {
- next(err);
- }
-});
-router.post("/MyLibrary_data", function (req, res, next) {
- try {
- //获取当前数据集合:以被浏览次数降序排列,每次取16个
- var page = parseInt(req.body.page);
- SQL = `SELECT id, state, time, title FROM ow_projects WHERE authorid=${
- res.locals.userid
- } ORDER BY time DESC LIMIT ${(page - 1) * 16},${16}`;
- DB.query(SQL, function (err, data) {
- if (err) {
- res.status(200).send({ status: "ok", data: [] });
- } else {
- res.status(200).send({ status: "ok", data: data });
- }
- });
- } catch (err) {
- next(err);
- }
-});
-
-module.exports = router;
diff --git a/server/router_scratch.js b/server/router_scratch.js
index 67b91c1..9177198 100644
--- a/server/router_scratch.js
+++ b/server/router_scratch.js
@@ -12,14 +12,6 @@ router.all("*", function (req, res, next) {
next();
});
-//首页
-router.get("/", function (req, res, next) {
- try {
- res.render("scratch/scratch_projects.ejs");
- } catch (err) {
- next(err);
- }
-});
router.get("/scratchcount", function (req, res, next) {
try {
@@ -97,13 +89,6 @@ router.get("/view/seachScratchProjects", function (req, res, next) {
//1:已发布;
//2:已开源;(开源的必须发布)
//Scratch项目展示
-router.get("/play", function (req, res, next) {
- try {
- res.render("scratch/scratch_play.ejs");
- } catch (err) {
- next(err);
- }
-});
router.get("/projectinfo", function (req, res, next) {
try {
@@ -271,13 +256,14 @@ router.get("/play/project/:id", function (req, res, next) {
DB.query(SQL, function (err, U) {
if (err || U.affectedRows == 0) {
res.locals.tip = { opt: "flash", msg: "项目不存在或未发布" };
- res.render("404.ejs");
+ res.status(404).json({
+ status: "error",
+ code: "404",
+ message: "找不到页面",
+ });
return;
}
- //res.render("scratch/scratch_play.ejs");
-
- ////console.log(SCRATCH[0]);
});
});
} catch (err) {
@@ -321,21 +307,6 @@ router.post("/play/openSrc", function (req, res, next) {
}
});
-//Scratch编程界面
-router.get("/edit", function (req, res, next) {
- try {
- res.render("scratch/scratch_edit.ejs");
- } catch (err) {
- next(err);
- }
-});
-router.get("/editnew", function (req, res, next) {
- try {
- res.render("scratch/scratch_edit_next.ejs");
- } catch (err) {
- next(err);
- }
-});
//Scratch内部调用一:获取作品数据:JSON源代码
//支持两种方案加载默认作品
//1、从指定文件加载
diff --git a/server/router_user.js b/server/router_user.js
index 098e276..d4e7108 100644
--- a/server/router_user.js
+++ b/server/router_user.js
@@ -15,26 +15,6 @@ router.all("*", function (req, res, next) {
const request = require("request");
-router.get("/", function (req, res) {
- res.render("user.ejs");
-});
-
-router.get("/login", function (req, res) {
- var SQL = `SELECT id FROM sys_ini WHERE iniKey='regist' AND iniValue=1 LIMIT 1`;
- DB.query(SQL, function (err, Regist) {
- if (err || Regist.length == 0) {
- res.locals.reg = 0;
- } else {
- res.locals.reg = 1;
- }
-
- res.render("login_or_register.ejs");
- });
-});
-
-router.get("/repw", function (req, res) {
- res.render("repw.ejs");
-});
router.get("/logout", function (req, res) {
logout(req, res);
@@ -63,7 +43,11 @@ router.get("/tuxiaochao", async function (req, res) {
DB.query(SQL, async function (err, USER) {
if (err || USER.length == 0) {
res.locals.tip = { opt: "flash", msg: "用户不存在" };
- res.render("404.ejs");
+ res.status(404).json({
+ status: "error",
+ code: "404",
+ message: "找不到页面",
+ });
return;
}
uid = res.locals["userid"].toString();
diff --git a/server/router_webhost.js b/server/router_webhost.js
index dab4b36..7b1b341 100644
--- a/server/router_webhost.js
+++ b/server/router_webhost.js
@@ -19,12 +19,20 @@ router.get("/:id/*", function (req, res) {
DB.query(SQL, function (err, PROJECT) {
if (err) {
res.locals.tip = { opt: "flash", msg: "项目不存在或未发布" };
- res.render("404.ejs");
+ res.status(404).json({
+ status: "error",
+ code: "404",
+ message: "找不到页面",
+ });
return;
}
if (PROJECT.length == 0) {
res.locals.tip = { opt: "flash", msg: "项目不存在或未发布" };
- res.render("404.ejs");
+ res.status(404).json({
+ status: "error",
+ code: "404",
+ message: "找不到页面",
+ });
return;
}
function getValue(arr, obj) {
@@ -62,7 +70,11 @@ router.get("/:id/*", function (req, res) {
DB.query(SQL, function (err, U) {
if (err || U.affectedRows == 0) {
res.locals.tip = { opt: "flash", msg: "项目不存在或未发布" };
- res.render("404.ejs");
+ res.status(404).json({
+ status: "error",
+ code: "404",
+ message: "找不到页面",
+ });
return;
}
});
diff --git a/totp.js b/tools/totp.js
similarity index 100%
rename from totp.js
rename to tools/totp.js
diff --git a/views/404.ejs b/views/404.ejs
deleted file mode 100644
index 0efcbc9..0000000
--- a/views/404.ejs
+++ /dev/null
@@ -1,11 +0,0 @@
-<%- include('./html-head.ejs', {pageTitle: '首页'}); %>
-
<%= user_count %>
-<%= scratch_count %>
-<%= python_count %>
-<%= backdrop_count %>
-<%= sprite_count %>
-添加背景的两种模式:
-1、背景的真实宽高:960*720,三个参数分别为:480、360、2
-2、背景的真实宽高:480*360,三个参数分别为:240、180、1
-