update gamehub gamepage, categories

This commit is contained in:
aaeii 2025-01-18 19:48:02 +03:00
parent 86b79a7f49
commit 909f7e4de9
3 changed files with 163 additions and 47 deletions

View File

@ -4,6 +4,10 @@ router.get("/game-page", (request, response) => {
response.send(require("./json/gamepage/success.json"));
});
router.get("/update-like", (request, response) => {
response.send(require("./json/gamepage/success.json"));
});
router.get("/categories", (request, response) => {
response.send(require("./json/categories/success.json"));
});
@ -20,4 +24,69 @@ router.get("/all-games", (request, response) => {
response.send(require("./json/home-page-data/all-games.json"));
});
// // Маршрут для обновления лайков
// router.post("/update-like", (request, response) => {
// const { username, likes } = request.body;
// // Эмулируем успешное обновление лайков
// console.log(`Лайки для пользователя ${username} обновлены до ${likes}`);
// response.status(200).json({
// success: true,
// message: `Лайки для пользователя ${username} обновлены до ${likes}`,
// });
// });
const fs = require("fs").promises;
const path = require("path");
// Path to JSON file
const commentsFilePath = path.join(__dirname, "./json/gamepage/success.json");
// Read JSON file
async function readComments() {
const data = await fs.readFile(commentsFilePath, "utf-8");
const parsedData = JSON.parse(data);
console.log("Прочитанные данные:", parsedData); // Логируем полученные данные
return parsedData;
}
// Write to JSON file
async function writeComments(data) {
await fs.writeFile(commentsFilePath, JSON.stringify(data, null, 2), "utf-8");
}
// Update likes route
router.post("/update-like", async (req, res) => {
const { username, likes } = req.body;
if (!username || likes === undefined) {
return res.status(400).json({ success: false, message: "Invalid input" });
}
try {
const data = await readComments();
const comment = data.data.comments.find((c) => c.username === username);
if (comment) {
comment.likes = likes;
await writeComments(data); // Сохраняем обновленные данные в файл
// Возвращаем актуализированные данные
res.status(200).json({
success: true,
message: "Likes updated successfully",
data: data.data, // Возвращаем актуализированные данные
});
} else {
res.status(404).json({ success: false, message: "Comment not found" });
}
} catch (error) {
console.error("Error updating likes:", error);
res.status(500).json({ success: false, message: "Server error" });
}
});
module.exports = router;

View File

@ -8,14 +8,18 @@
"price": 259,
"old_price": 500,
"image": "sales_game1",
"os": "windows"
"os": "windows",
"fav1": "star1",
"fav2": "star2"
},
{
"id": 2,
"title": "Red Solstice 2 Survivors",
"price": 561,
"image": "sales_game2",
"os": "windows"
"os": "windows",
"fav1": "star1",
"fav2": "star2"
},
{
"id": 3,
@ -23,7 +27,9 @@
"price": 820,
"old_price": 1100,
"image": "new_game2",
"os": "windows"
"os": "windows",
"fav1": "star1",
"fav2": "star2"
},
{
"id": 4,
@ -31,7 +37,9 @@
"price": 990,
"old_price": 1200,
"image": "leaders_game4",
"os": "windows"
"os": "windows",
"fav1": "star1",
"fav2": "star2"
},
{
"id": 5,
@ -39,7 +47,9 @@
"price": 1200,
"old_price": 2500,
"image": "leaders_game5",
"os": "windows"
"os": "windows",
"fav1": "star1",
"fav2": "star2"
},
{
"id": 6,
@ -47,31 +57,39 @@
"price": 600,
"old_price": 890,
"image": "leaders_game6",
"os": "windows"
"os": "windows",
"fav1": "star1",
"fav2": "star2"
}
],
"games2": [
{
"id": 1,
"id": 7,
"title": "Alpha League",
"price": 299,
"image": "new_game1",
"os": "windows"
"os": "windows",
"fav1": "star1",
"fav2": "star2"
},
{
"id": 2,
"id": 8,
"title": "Sons Of The Forests",
"price": 820,
"old_price": 1100,
"image": "new_game2",
"os": "windows"
"os": "windows",
"fav1": "star1",
"fav2": "star2"
},
{
"id": 3,
"id": 9,
"title": "Pacific Drives",
"price": 1799,
"image": "new_game3",
"os": "windows"
"os": "windows",
"fav1": "star1",
"fav2": "star2"
},
{
"id": 4,
@ -79,7 +97,9 @@
"price": 990,
"old_price": 1200,
"image": "leaders_game4",
"os": "windows"
"os": "windows",
"fav1": "star1",
"fav2": "star2"
},
{
"id": 5,
@ -87,7 +107,9 @@
"price": 1200,
"old_price": 2500,
"image": "leaders_game5",
"os": "windows"
"os": "windows",
"fav1": "star1",
"fav2": "star2"
},
{
"id": 6,
@ -95,31 +117,39 @@
"price": 600,
"old_price": 890,
"image": "leaders_game6",
"os": "windows"
"os": "windows",
"fav1": "star1",
"fav2": "star2"
}
],
"games3": [
{
"id": 1,
"id": 10,
"title": "Elden Ring",
"price": 3295,
"old_price": 3599,
"image": "leaders_game2",
"os": "windows"
"os": "windows",
"fav1": "star1",
"fav2": "star2"
},
{
"id": 2,
"id": 11,
"title": "Counter-Strike 2",
"price": 479,
"image": "leaders_game1",
"os": "windows"
"os": "windows",
"fav1": "star1",
"fav2": "star2"
},
{
"id": 3,
"id": 12,
"title": "PUBG: BATTLEGROUNDS",
"price": 199,
"image": "leaders_game3",
"os": "windows"
"os": "windows",
"fav1": "star1",
"fav2": "star2"
},
{
"id": 4,
@ -127,7 +157,9 @@
"price": 990,
"old_price": 1200,
"image": "leaders_game4",
"os": "windows"
"os": "windows",
"fav1": "star1",
"fav2": "star2"
},
{
"id": 5,
@ -135,7 +167,9 @@
"price": 1200,
"old_price": 2500,
"image": "leaders_game5",
"os": "windows"
"os": "windows",
"fav1": "star1",
"fav2": "star2"
},
{
"id": 6,
@ -143,7 +177,9 @@
"price": 600,
"old_price": 890,
"image": "leaders_game6",
"os": "windows"
"os": "windows",
"fav1": "star1",
"fav2": "star2"
}
]
}

View File

@ -4,21 +4,32 @@
"comments": [
{
"username": ользователь1",
"text": "Текст комментария 1"
"text": "Текст комментария 1",
"likes": 9,
"rating": 8,
"date": "2025-03-01T10:00:00Z"
},
{
"username": ользователь2",
"text": "Текст комментария 2"
"text": "Текст комментария 2",
"likes": 7,
"rating": 7,
"date": "2025-01-01T10:00:00Z"
},
{
"username": ользователь3",
"text": "Текст комментария 3"
"text": "Текст комментария 3",
"likes": 5,
"rating": 3,
"date": "2025-02-01T10:00:00Z"
},
{
"username": ользователь4",
"text": "Текст комментария 4"
"text": "Текст комментария 4",
"likes": 15,
"rating": 2,
"date": "2025-12-01T10:00:00Z"
}
]
}
}
}