mirror of
https://git.rezel.net/LudoTech/traque.git
synced 2026-04-11 00:30:19 +02:00
Server folders restructuration
This commit is contained in:
@@ -5,4 +5,4 @@ npm-debug.log
|
||||
README.md
|
||||
.next
|
||||
.git
|
||||
.vscode
|
||||
.vscode
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
#Make a self signed certificate for development
|
||||
keys: key.pem server.crt
|
||||
|
||||
key.pem csr.pem:
|
||||
openssl req -newkey rsa:2048 -new -nodes -keyout key.pem -out csr.pem
|
||||
|
||||
server.crt: key.pem csr.pem
|
||||
openssl x509 -req -days 365 -in csr.pem -signkey key.pem -out server.crt
|
||||
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
@@ -2,11 +2,11 @@
|
||||
"name": "traque-back",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"main": "src/index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"start": "node index.js",
|
||||
"dev": "nodemon index.js"
|
||||
"start": "node src/index.js",
|
||||
"dev": "nodemon src/index.js"
|
||||
},
|
||||
"author": "Quentin Roussel",
|
||||
"license": "ISC",
|
||||
|
||||
@@ -6,7 +6,8 @@ import multer from "multer";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import game from "./game.js";
|
||||
const UPLOAD_DIR = "uploads/"
|
||||
const UPLOAD_DIR = path.join(process.cwd(), "uploads");
|
||||
const IMAGES_DIR = path.join(process.cwd(), "assets", "images");
|
||||
const ALLOWED_MIME = [
|
||||
"image/png",
|
||||
"image/jpeg",
|
||||
@@ -60,10 +61,10 @@ export function initPhotoUpload() {
|
||||
app.get("/photo/my", (req, res) => {
|
||||
let team = game.getTeam(req.query.team);
|
||||
if (team) {
|
||||
const imagePath = path.join(process.cwd(), UPLOAD_DIR, team.id);
|
||||
const imagePath = path.join(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"));
|
||||
res.sendFile(fs.existsSync(imagePath) ? imagePath : path.join(IMAGES_DIR, "missing_image.jpg"));
|
||||
} else {
|
||||
res.status(400).send("Team not found")
|
||||
}
|
||||
@@ -72,10 +73,10 @@ export function initPhotoUpload() {
|
||||
app.get("/photo/enemy", (req, res) => {
|
||||
let team = game.getTeam(req.query.team);
|
||||
if (team) {
|
||||
const imagePath = path.join(process.cwd(), UPLOAD_DIR, team.chasing);
|
||||
const imagePath = path.join(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"));
|
||||
res.sendFile(fs.existsSync(imagePath) ? imagePath : path.join(IMAGES_DIR, "missing_image.jpg"));
|
||||
} else {
|
||||
res.status(400).send("Team not found")
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
const UPLOAD_DIR = "trajectories";
|
||||
const TRAJECTORIES_DIR = path.join(process.cwd(), "trajectories");
|
||||
const EXTENSION = "txt";
|
||||
|
||||
// Useful functions
|
||||
|
||||
function teamIDToPath(teamID) {
|
||||
return path.join(UPLOAD_DIR, teamID + "." + EXTENSION);
|
||||
return path.join(TRAJECTORIES_DIR, teamID + "." + EXTENSION);
|
||||
}
|
||||
|
||||
function dataToLine(...data) {
|
||||
@@ -44,8 +44,8 @@ function addLineToFile(teamID, line) {
|
||||
}
|
||||
|
||||
function initTrajectories() {
|
||||
const files = fs.readdirSync(UPLOAD_DIR);
|
||||
for (const file of files) fs.unlinkSync(path.join(UPLOAD_DIR, file));
|
||||
const files = fs.readdirSync(TRAJECTORIES_DIR);
|
||||
for (const file of files) fs.unlinkSync(path.join(TRAJECTORIES_DIR, file));
|
||||
}
|
||||
|
||||
// Export functions
|
||||
Reference in New Issue
Block a user