Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
SunWuyuan committed Dec 22, 2024
1 parent e56a3c7 commit d345a5b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
12 changes: 1 addition & 11 deletions controllers/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ const prisma = new PrismaClient();
import { createHash } from "crypto";
import { getUsersByList } from "./users.js";

/**
* Get projects by list of IDs
* @param {Array<number>} list - List of project IDs
* @param {number} userid - User ID
* @returns {Promise<Array<Project>>}
*/

async function getProjectsByList(list, userid) {
const select = projectSelectionFields();
const projectIds = list.map(Number);
Expand All @@ -29,11 +24,6 @@ async function getProjectsAndUsersByProjectsList(list, userid) {
return { projects, users };
}

/**
* Extract project data from body
* @param {Object} body - Request body
* @returns {Object} - Extracted project data
*/
function extractProjectData(body) {
const fields = [
"type",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@
},
"devDependencies": {
"prisma": "^6.1.0"
}
}
}
12 changes: 12 additions & 0 deletions routes/router_project.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import DB from "../utils/database.js";
import { prisma } from "../utils/global.js";
import default_project from "../config/default_project.js";
import { extractProjectData, setProjectFile, getProjectFile, projectSelectionFields, authorSelectionFields, handleTagsChange } from "../controllers/projects.js";
import {getProjectStars } from "../controllers/projectlist.js";

import { Logger } from "winston";
// 中间件,确保所有请求均经过该处理
router.all("*", (req, res, next) => next());
Expand Down Expand Up @@ -215,6 +217,16 @@ router.get("/:id", async (req, res, next) => {
}
});

// 获取项目信息
router.get("/community/:id", async (req, res, next) => {
try {
var stars = await getProjectStars(req.params.id);
res.status(200).send({ status: "1", msg: "获取成功", data: {stars: stars} });
} catch (err) {
logger.error("Error fetching project information:", err);
next(err);
}
});
// 获取源代码
router.get("/:id/source/:env?", async (req, res, next) => {
try {
Expand Down

0 comments on commit d345a5b

Please sign in to comment.