Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
SunWuyuan committed Jan 20, 2025
1 parent b8a396f commit dc4b454
Show file tree
Hide file tree
Showing 16 changed files with 528 additions and 273 deletions.
2 changes: 1 addition & 1 deletion controllers/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ async function getProjectFile(sha256) {
*/
function handleError(res, err, msg) {
logger.error(err);
res.status(500).send({ status: "0", msg, error: err });
res.status(500).send({ status: "error", msg, error: err });
}

/**
Expand Down
2 changes: 1 addition & 1 deletion middleware/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async function needadmin(req, res, next) {
const adminEmail = await configManager.getConfig("security.adminuser");
if (res.locals.email !== adminEmail) {
logger.info(`[needadmin] - ${req.ip} - 权限不足,返回401 Unauthorized状态码`);
return res.status(401).send({ status: "0", msg: "权限不足" });
return res.status(401).send({ status: "error", message: "权限不足" });
}
next(); // 已登录,继续处理请求
}
Expand Down
4 changes: 2 additions & 2 deletions middleware/geetest.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ async function geetestMiddleware(req, res, next) {
logger.debug(`Validate fail: ${result.data.reason}`);
res.status(500).send({
code: 500,
msg: `请完成验证码/${result.data.reason}`,
status: `请完成验证码/${result.data.reason}`,
message: `请完成验证码/${result.data.reason}`,
status: "error",
});
}
} catch (error) {
Expand Down
59 changes: 12 additions & 47 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@ model ow_projects {
time DateTime? @default(now()) @db.Timestamp(0)
title String? @default("Scratch新项目") @db.VarChar(1000)
description String? @default("OurWorld上的Scratch项目") @db.VarChar(1000)
source String? @db.MediumText
history Boolean @default(true)
devenv Boolean @default(true)
devsource String @db.MediumText
tags String @default("") @db.VarChar(100)
}

Expand All @@ -77,7 +75,7 @@ model ow_users {
loginTime DateTime? @db.Timestamp(0)
regTime DateTime? @default(now()) @db.Timestamp(0)
sex Int? @default(0) @db.TinyInt
birthday DateTime? @default(dbgenerated("'2000-04-01 00:00:00'")) @db.Timestamp(0)
birthday DateTime? @default(dbgenerated("'2000-03-31 16:00:00'")) @db.Timestamp(0)
motto String? @default("OurWorld创作者") @db.VarChar(1000)
images String? @default("fcd939e653195bb6d057e8c2519f5cc7") @db.VarChar(255)
avatar String? @default("https://owcdn.190823.xyz/user/fcd939e653195bb6d057e8c2519f5cc7") @db.VarChar(255)
Expand All @@ -90,8 +88,8 @@ model ow_users {
weibo String? @db.VarChar(255)
qq String? @db.VarChar(255)
fa String? @map("2fa") @db.VarChar(255)
createdAt DateTime? @default(dbgenerated("'2000-04-01 00:00:00'")) @db.Timestamp(0)
updatedAt DateTime? @default(dbgenerated("'2000-04-01 00:00:00'")) @db.Timestamp(0)
createdAt DateTime? @default(dbgenerated("'2000-03-31 16:00:00'")) @db.Timestamp(0)
updatedAt DateTime? @default(dbgenerated("'2000-03-31 16:00:00'")) @db.Timestamp(0)
label String? @db.VarChar(255)
}

Expand Down Expand Up @@ -186,46 +184,13 @@ model ow_users_magiclink {
expiresAt DateTime @db.DateTime(0)
}

/// The underlying view does not contain a valid unique identifier and can therefore currently not be handled by Prisma Client.
/// This view or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments
view ow_projects_view {
id Int @default(0) @db.UnsignedInt
type String? @default("text") @db.VarChar(32)
licence String? @db.VarChar(32)
authorid Int
state String? @default("private") @db.VarChar(32)
view_count Int? @default(0) @db.UnsignedInt
time DateTime? @db.Timestamp(0)
title String? @default("Scratch新项目") @db.VarChar(1000)
description String? @default("OurWorld上的Scratch项目") @db.VarChar(1000)
source String? @db.MediumText
tags String @default("") @db.VarChar(100)
author_id Int @default(0)
author_display_name String @default("OurWorld创作者") @db.Char(20)
author_motto String? @default("OurWorld创作者") @db.VarChar(1000)
author_images String? @default("fcd939e653195bb6d057e8c2519f5cc7") @db.VarChar(255)
@@ignore
}

/// The underlying view does not contain a valid unique identifier and can therefore currently not be handled by Prisma Client.
/// This view or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments
view ow_public_projects_view {
id Int @default(0) @db.UnsignedInt
type String? @default("text") @db.VarChar(32)
licence String? @db.VarChar(32)
authorid Int
state String? @default("private") @db.VarChar(32)
view_count Int? @default(0) @db.UnsignedInt
time DateTime? @db.Timestamp(0)
title String? @default("Scratch新项目") @db.VarChar(1000)
description String? @default("OurWorld上的Scratch项目") @db.VarChar(1000)
source String? @db.MediumText
tags String @default("") @db.VarChar(100)
author_id Int @default(0)
author_display_name String @default("OurWorld创作者") @db.Char(20)
author_motto String? @default("OurWorld创作者") @db.VarChar(1000)
author_images String? @default("fcd939e653195bb6d057e8c2519f5cc7") @db.VarChar(255)
@@ignore
model ow_projects_commits {
id String @id @db.VarChar(256)
project_id Int
author_id Int
branch String @default("main") @db.VarChar(255)
parent_commit_id String? @db.VarChar(256)
commit_message String @db.Text
commit_date DateTime @db.DateTime(0)
commit_file String @db.VarChar(256)
}
21 changes: 0 additions & 21 deletions prisma/views/zerocat_develop/ow_projects_view.sql

This file was deleted.

23 changes: 0 additions & 23 deletions prisma/views/zerocat_develop/ow_public_projects_view.sql

This file was deleted.

12 changes: 6 additions & 6 deletions routes/router_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ router.get("/usertx", async function (req, res, next) {
},
});
if (!USER) {
res.locals.tip = { opt: "flash", msg: "用户不存在" };
res.locals.tip = { opt: "flash", message: "用户不存在" };
res.status(404).json({
status: "error",
code: "404",
Expand Down Expand Up @@ -69,15 +69,15 @@ router.get("/getuserinfo", async function (req, res, next) {
});
if (!user[0]) {
logger.debug("用户不存在");
res.locals.tip = { opt: "flash", msg: "用户不存在" };
res.locals.tip = { opt: "flash", message: "用户不存在" };
res.status(404).json({
status: "error",
code: "404",
message: "找不到页面",
});
}
res.send({
status: "ok",
status: "success",
info: { user: user[0], count: { pythoncount, scratchcount } },
});
} catch (err) {
Expand Down Expand Up @@ -128,12 +128,12 @@ router.get("/projectinfo", async function (req, res, next) {
if (!project) {
res.locals.tip = {
opt: "flash",
msg: "项目不存在或未发布",
message: "项目不存在或未发布",
};
res.send({
code: 404,
status: "404",
msg: "项目不存在或未发布",
message: "项目不存在或未发布",
});
return;
}
Expand Down Expand Up @@ -222,7 +222,7 @@ router.get("/tuxiaochao", async function (req, res) {
});

if (!USER) {
res.locals.tip = { opt: "flash", msg: "用户不存在" };
res.locals.tip = { opt: "flash", message: "用户不存在" };
res.status(404).json({
status: "error",
code: "404",
Expand Down
4 changes: 2 additions & 2 deletions routes/router_my.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ router.post("/set/avatar", geetestMiddleware, upload.single('zcfile'), async (re
where: { id: res.locals.userid },
data: { images: hashValue },
});
res.status(200).send({ status: "ok", message: "Avatar updated successfully" });
res.status(200).send({ status: "success", message: "Avatar updated successfully" });
});

chunks.on("error", (err) => {
Expand Down Expand Up @@ -114,7 +114,7 @@ router.post("/set/pw", geetestMiddleware, async (req, res) => {
where: { id: res.locals.userid },
data: { password: newPW },
});
res.status(200).send({ status: "ok", message: "密码修改成功" });
res.status(200).send({ status: "success", message: "密码修改成功" });
});

export default router;
Loading

0 comments on commit dc4b454

Please sign in to comment.