Fix photos + API hooks + cleaning

This commit is contained in:
Sebastien Riviere
2026-02-17 14:32:37 +01:00
parent e0aaeb63f7
commit 05a60612c6
24 changed files with 341 additions and 231 deletions

View File

@@ -56,7 +56,7 @@ export default {
getNewTeamId() {
let id = randint(1_000_000);
while (this.teams.find(t => t.id === id)) id = randint(1_000_000);
return id;
return id.toString().padStart(6, '0');
},
checkEndGame() {

View File

@@ -31,7 +31,7 @@ const upload = multer({
fileFilter: function (req, file, callback) {
if (ALLOWED_MIME.indexOf(file.mimetype) == -1) {
callback(null, false);
} else if (!game.getTeam(Number(req.query.team))) {
} else if (!game.getTeam(req.query.team)) {
callback(null, false);
} else {
callback(null, true);
@@ -58,9 +58,9 @@ export function initPhotoUpload() {
})
//App handler for serving the photo of a team given its secret ID
app.get("/photo/my", (req, res) => {
let team = game.getTeam(Number(req.query.team));
let team = game.getTeam(req.query.team);
if (team) {
const imagePath = path.join(process.cwd(), UPLOAD_DIR, team.id.toString());
const imagePath = path.join(process.cwd(), UPLOAD_DIR, team.id);
res.set("Content-Type", "image/png")
res.set("Access-Control-Allow-Origin", "*");
res.sendFile(fs.existsSync(imagePath) ? imagePath : path.join(process.cwd(), "images", "missing_image.jpg"));
@@ -70,9 +70,9 @@ export function initPhotoUpload() {
})
//App handler for serving the photo of the team chased by the team given by its secret ID
app.get("/photo/enemy", (req, res) => {
let team = game.getTeam(Number(req.query.team));
let team = game.getTeam(req.query.team);
if (team) {
const imagePath = path.join(process.cwd(), UPLOAD_DIR, team.chasing.toString());
const imagePath = path.join(process.cwd(), UPLOAD_DIR, team.chasing);
res.set("Content-Type", "image/png")
res.set("Access-Control-Allow-Origin", "*");
res.sendFile(fs.existsSync(imagePath) ? imagePath : path.join(process.cwd(), "images", "missing_image.jpg"));