mirror of
https://github.com/Yourdaylight/CloudGame.git
synced 2026-05-25 16:00:30 +00:00
feat: can search now
This commit is contained in:
@@ -69,13 +69,6 @@ def add_game():
|
|||||||
for field in string_fields:
|
for field in string_fields:
|
||||||
if not isinstance(game_data.get(field), str):
|
if not isinstance(game_data.get(field), str):
|
||||||
return jsonify({"code": 500, "msg": f"Field:[{field}] should be a string"}), 400
|
return jsonify({"code": 500, "msg": f"Field:[{field}] should be a string"}), 400
|
||||||
|
|
||||||
# 验证列表类型的字段
|
|
||||||
# list_fields = ["Popular Tags", "Game Features", "Supported Languages"]
|
|
||||||
# for field in list_fields:
|
|
||||||
# if not isinstance(game_data.get(field), list):
|
|
||||||
# return jsonify({"code": 500, "msg": f"Field: [{field}] should be a list"}), 400
|
|
||||||
|
|
||||||
# 添加时间戳
|
# 添加时间戳
|
||||||
game_data["date_added"] = datetime.datetime.now().strftime("%Y-%m-%d")
|
game_data["date_added"] = datetime.datetime.now().strftime("%Y-%m-%d")
|
||||||
game_data["update_time"] = time.time()
|
game_data["update_time"] = time.time()
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
const { app } = require('@azure/functions');
|
const { app } = require('@azure/functions');
|
||||||
|
|
||||||
const { MongoClient } = require('mongodb');
|
const { MongoClient } = require('mongodb');
|
||||||
|
// import jwt
|
||||||
|
const jwt = require('jsonwebtoken');
|
||||||
var connectionString = "mongodb://games:oQ5bO7YMfpu99oZMpKs0fjjypybyIMwBHJh7TmK8FYj1J41StnByDp1vxZ0huSXxlYbNLiRtNdvZACDb9cByMQ%3D%3D@games.mongo.cosmos.azure.com:10255/?ssl=true&retrywrites=false&maxIdleTimeMS=120000&appName=@games@";
|
var connectionString = "mongodb://games:oQ5bO7YMfpu99oZMpKs0fjjypybyIMwBHJh7TmK8FYj1J41StnByDp1vxZ0huSXxlYbNLiRtNdvZACDb9cByMQ%3D%3D@games.mongo.cosmos.azure.com:10255/?ssl=true&retrywrites=false&maxIdleTimeMS=120000&appName=@games@";
|
||||||
const client = new MongoClient(connectionString);
|
const client = new MongoClient(connectionString);
|
||||||
|
|
||||||
@@ -12,7 +13,7 @@ app.http('register', {
|
|||||||
try {
|
try {
|
||||||
await client.connect();
|
await client.connect();
|
||||||
const db = client.db("games");
|
const db = client.db("games");
|
||||||
const { username, password } = request.body;
|
const { username, password } = await request.json();
|
||||||
const existingUser = await db.collection("user").findOne({ username });
|
const existingUser = await db.collection("user").findOne({ username });
|
||||||
|
|
||||||
if (!existingUser) {
|
if (!existingUser) {
|
||||||
@@ -49,13 +50,13 @@ app.http('login', {
|
|||||||
authLevel: 'anonymous',
|
authLevel: 'anonymous',
|
||||||
handler: async (request, context) => {
|
handler: async (request, context) => {
|
||||||
try {
|
try {
|
||||||
const { username, password } = request.body;
|
const { username, password } = await request.json();
|
||||||
await client.connect();
|
await client.connect();
|
||||||
const db = client.db("games");
|
const db = client.db("games");
|
||||||
const user = await db.collection("user").findOne({ username, password });
|
const user = await db.collection("user").findOne({ username, password });
|
||||||
|
|
||||||
if (user) {
|
if (user) {
|
||||||
const token = jwt.sign({ username }, process.env["JWT_SECRET"], { expiresIn: '1h' });
|
const token = jwt.sign({ username }, "123456" ,{ expiresIn: '1h' });
|
||||||
context.res = {
|
context.res = {
|
||||||
status: 200, // HTTP 状态码
|
status: 200, // HTTP 状态码
|
||||||
body: JSON.stringify({ code: 200, msg: "SUCCESS", data: { token } }),
|
body: JSON.stringify({ code: 200, msg: "SUCCESS", data: { token } }),
|
||||||
@@ -81,5 +82,4 @@ app.http('login', {
|
|||||||
return context.res;
|
return context.res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -164,7 +164,7 @@ export class ListComponent implements OnInit {
|
|||||||
...this.searchQueryForm.value,
|
...this.searchQueryForm.value,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.apiService.post('/game/getGames', params).subscribe(
|
this.apiService.post('/games', params).subscribe(
|
||||||
(res: any) => {
|
(res: any) => {
|
||||||
this.isLoading = false;
|
this.isLoading = false;
|
||||||
const { code, data, total } = res;
|
const { code, data, total } = res;
|
||||||
|
|||||||
Reference in New Issue
Block a user