my 13th reason

This commit is contained in:
2024-07-02 21:54:19 +02:00
parent d59608174d
commit d702612cb1
4 changed files with 10 additions and 22 deletions

View File

@ -32,7 +32,7 @@ export default function (socket: TSocket, io: Server) {
}
files.forEach(file => {
tiles.push(file);
tiles.push(file.replace('.png', ''));
});
// send over the list of tiles to the socket

View File

@ -3,6 +3,7 @@ import { TSocket } from "../../utilities/Types";
import { writeFile } from "node:fs/promises";
import path from "path";
import fs from "fs/promises";
import { randomUUID } from 'node:crypto';
interface ITileData {
[key: string]: Buffer;
@ -26,22 +27,9 @@ export default function (socket: TSocket, io: Server) {
// Ensure the folder exists
await fs.mkdir(public_folder, { recursive: true });
const files = await fs.readdir(public_folder);
let highestNumber = -1;
// Find the highest number in existing filenames
for (const file of files) {
const match = file.match(/^(\d+)\.png$/);
if (match) {
const number = parseInt(match[1], 10);
if (number > highestNumber) {
highestNumber = number;
}
}
}
const uploadPromises = Object.entries(data).map(async ([key, tileData], index) => {
const filename = `${highestNumber + index + 1}.png`;
const uploadPromises = Object.entries(data).map(async ([key, tileData]) => {
const uuid = randomUUID();
const filename = `${uuid}.png`;
const finalFilePath = path.join(public_folder, filename);
await writeFile(finalFilePath, tileData);
});