Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
SunWuyuan committed Aug 28, 2024
1 parent bc0e2f9 commit e69cf8c
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 29 deletions.
25 changes: 5 additions & 20 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ model register {
model scratch1 {
id Int @id @default(autoincrement()) @db.UnsignedInt
type String? @default("scratch") @db.VarChar(32)
licence String? @db.VarChar(32)
license String? @db.VarChar(32)
authorid Int
state Int? @default(0) @db.UnsignedTinyInt
view_count Int? @default(0) @db.UnsignedInt
Expand Down Expand Up @@ -179,7 +179,7 @@ model wl_Users {
model ow_Projects1 {
id Int @id @default(autoincrement()) @db.UnsignedInt
type String? @default("text") @db.VarChar(32)
licence String? @db.VarChar(32)
license String? @db.VarChar(32)
authorid String @db.VarChar(32)
teacherid Int? @default(0) @db.UnsignedInt
state Int? @default(0) @db.UnsignedTinyInt
Expand All @@ -196,7 +196,7 @@ model ow_Projects1 {
model python1 {
id Int @id @default(autoincrement()) @db.UnsignedInt
type String? @default("python") @db.VarChar(32)
licence String? @db.VarChar(32)
license String? @db.VarChar(32)
authorid String @db.VarChar(32)
state Int? @default(0) @db.UnsignedTinyInt
view_count Int? @default(0) @db.UnsignedInt
Expand All @@ -212,7 +212,7 @@ model python1 {
model ow_projects {
id Int @id @default(autoincrement()) @db.UnsignedInt
type String? @default("text") @db.VarChar(32)
licence String? @db.VarChar(32)
license String? @db.VarChar(32)
authorid Int @db.UnsignedInt
state String? @default("private") @db.VarChar(32)
view_count Int? @default(0) @db.UnsignedInt
Expand Down Expand Up @@ -258,21 +258,6 @@ model ow_users {
@@id([id, username])
}

/// This model 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
model ow_project {
id Int @id @default(autoincrement()) @db.UnsignedInt
authorid Int @db.UnsignedInt
projectid Int @db.UnsignedInt
branche String? @default("main") @db.VarChar(45)
type String? @default("commit") @db.VarChar(32)
view_count Int? @default(0) @db.UnsignedInt
time DateTime @default(now()) @db.Timestamp(0)
title String? @default("ZeroCat新项目") @db.VarChar(50)
commit String? @default("commit") @db.VarChar(1000)
source String? @db.MediumText
environment Json?
}

/// This model 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
model ow_projects_history {
id Int @id @default(autoincrement()) @db.UnsignedInt
Expand All @@ -284,5 +269,5 @@ model ow_projects_history {
description String? @default("commit") @db.VarChar(1000)
source String? @db.MediumText
state String? @default("private") @db.VarChar(32)
licence String? @db.VarChar(45)
license String? @db.VarChar(45)
}
2 changes: 1 addition & 1 deletion server/router_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ router.get("/work/info", function (req, res) {
router.get("/projectinfo", function (req, res) {
SQL =
`SELECT ow_projects.id,ow_projects.authorid,ow_projects.time,ow_projects.view_count,ow_projects.like_count,ow_projects.type,` +
` ow_projects.favo_count,ow_projects.title,ow_projects.state,ow_projects.description,` +
` ow_projects.favo_count,ow_projects.title,ow_projects.state,ow_projects.description,ow_projects.license,` +
` '' AS likeid, '' AS favoid,` +
` ow_users.display_name AS author_display_name,` +
` ow_users.images AS author_images,` +
Expand Down
52 changes: 48 additions & 4 deletions server/router_project.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ router.post("/", function (req, res) {

const allowable = [
"type",
"licence",
"license",
"state",
"title",
"description",
Expand Down Expand Up @@ -68,6 +68,50 @@ router.post("/", function (req, res) {
.send({ status: "1", msg: "保存成功", message: "保存成功", id: result.id });
});
});

//fork作品
router.post("/:id/fork", function (req, res) {
if (!res.locals.login) {
res.status(404);
return;
}
try {
I.prisma.ow_projects.findFirst({
where: {
id: Number(req.params.id),
},
}).then((result) => {
if (result.state == 'public') {
I.prisma.ow_projects
.create({
data: {
authorid: res.locals.userid,
title: result.title + '改编',
description: result.description,
license: result.license,
state: 'private',
type: result.type,
source: result.source,
devsource: result.source,
},
}).catch((err) => {
console.log(err);
res.status(200).send({ status: "0", msg: "改编失败", error: err });
}).then((result) => {
res.status(200).send({ status: "1", msg: "改编成功", id: result.id });
})
} else {
res.status(200).send({ status: "0", msg: "改编失败" });
}
})
}
catch (err) {
console.log(err);
res.status(200).send({ status: "0", msg: "改编失败", error: err });
return;
}

});
// 保存
router.put("/:id/source/dev", function (req, res) {
if (!res.locals.userid) {
Expand Down Expand Up @@ -124,7 +168,7 @@ router.put("/:id", function (req, res) {

const allowable = [
"type",
"licence",
"license",
"state",
"title",
"description",
Expand Down Expand Up @@ -249,7 +293,7 @@ router.post("/:id/push", async function (req, res) {
.then(async (result) => {
res
.status(200)
.send({ status: "1", msg: "推送成功", message: "推送成功" });
.send({ status: "1", msg: "推送成功", message: "推送成功" });
if (project.history == 1) {
//console.log(project.devsource)
//console.log(result.source)
Expand All @@ -266,7 +310,7 @@ router.post("/:id/push", async function (req, res) {
title: project.title,
description: project.description,
state: project.state,
licence: project.licence,
license: project.license,
},
})
.catch((err) => {
Expand Down
4 changes: 2 additions & 2 deletions server/router_scratch.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ router.get("/play", function (req, res) {
router.get("/projectinfo", function (req, res) {
SQL =
`SELECT ow_projects.id,ow_projects.authorid,ow_projects.time,ow_projects.view_count,ow_projects.like_count,ow_projects.type,` +
` ow_projects.favo_count,ow_projects.title,ow_projects.state,ow_projects.description,` +
` ow_projects.favo_count,ow_projects.title,ow_projects.state,ow_projects.description,ow_projects.license,` +
` '' AS likeid, '' AS favoid,` +
` ow_users.display_name AS author_display_name,` +
` ow_users.images AS author_images,` +
Expand All @@ -112,7 +112,7 @@ router.get("/projectinfo", function (req, res) {
router.get("/projectinfo2", function (req, res) {
SQL =
`SELECT ow_projects.id,ow_projects.authorid,ow_projects.time,ow_projects.view_count,ow_projects.like_count,ow_projects.type,` +
` ow_projects.favo_count,ow_projects.title,ow_projects.state,ow_projects.description,` +
` ow_projects.favo_count,ow_projects.title,ow_projects.state,ow_projects.description,ow_projects.license,` +
` '' AS likeid, '' AS favoid,` +
` ow_users.display_name AS author_display_name,` +
` ow_users.images AS author_images,` +
Expand Down
4 changes: 2 additions & 2 deletions testdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ console.log({
description: 'ZeroCat',
source: '{"111":"111","title":"111"}',
state: 'private',
licence: 'MIT'
license: 'MIT'
}===
{
authorid: 1,
Expand All @@ -16,5 +16,5 @@ console.log({
description: 'ZeroCat',
source: '{"111":"111","title":"111"}',
state: 'private',
licence: 'MIT'
license: 'MIT'
})

0 comments on commit e69cf8c

Please sign in to comment.