forked from noxious/server
my 13th reason
This commit is contained in:
parent
d59608174d
commit
d702612cb1
6
package-lock.json
generated
6
package-lock.json
generated
@ -2411,9 +2411,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/typescript": {
|
"node_modules/typescript": {
|
||||||
"version": "5.5.2",
|
"version": "5.5.3",
|
||||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.2.tgz",
|
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.3.tgz",
|
||||||
"integrity": "sha512-NcRtPEOsPFFWjobJEtfihkLCZCXZt/os3zf8nTxjVH3RvTSxjrCamJpbExGvYOF+tFHc3pA65qpdwPbzjohhew==",
|
"integrity": "sha512-/hreyEujaB0w76zKo6717l3L0o/qEUtRgdvUBvlkhoWeOVMjMuHNHk0BRBzikzuGDqNmPQbg5ifMEqsHLiIUcQ==",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"bin": {
|
"bin": {
|
||||||
"tsc": "bin/tsc",
|
"tsc": "bin/tsc",
|
||||||
|
@ -32,7 +32,7 @@ export default function (socket: TSocket, io: Server) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
files.forEach(file => {
|
files.forEach(file => {
|
||||||
tiles.push(file);
|
tiles.push(file.replace('.png', ''));
|
||||||
});
|
});
|
||||||
|
|
||||||
// send over the list of tiles to the socket
|
// send over the list of tiles to the socket
|
||||||
|
@ -3,6 +3,7 @@ import { TSocket } from "../../utilities/Types";
|
|||||||
import { writeFile } from "node:fs/promises";
|
import { writeFile } from "node:fs/promises";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import fs from "fs/promises";
|
import fs from "fs/promises";
|
||||||
|
import { randomUUID } from 'node:crypto';
|
||||||
|
|
||||||
interface ITileData {
|
interface ITileData {
|
||||||
[key: string]: Buffer;
|
[key: string]: Buffer;
|
||||||
@ -26,22 +27,9 @@ export default function (socket: TSocket, io: Server) {
|
|||||||
// Ensure the folder exists
|
// Ensure the folder exists
|
||||||
await fs.mkdir(public_folder, { recursive: true });
|
await fs.mkdir(public_folder, { recursive: true });
|
||||||
|
|
||||||
const files = await fs.readdir(public_folder);
|
const uploadPromises = Object.entries(data).map(async ([key, tileData]) => {
|
||||||
let highestNumber = -1;
|
const uuid = randomUUID();
|
||||||
|
const filename = `${uuid}.png`;
|
||||||
// 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 finalFilePath = path.join(public_folder, filename);
|
const finalFilePath = path.join(public_folder, filename);
|
||||||
await writeFile(finalFilePath, tileData);
|
await writeFile(finalFilePath, tileData);
|
||||||
});
|
});
|
||||||
|
@ -16,7 +16,7 @@ async function addHttpRoutes(app: Application) {
|
|||||||
let assets: TAsset[] = [];
|
let assets: TAsset[] = [];
|
||||||
const tiles = listTiles();
|
const tiles = listTiles();
|
||||||
tiles.forEach(tile => {
|
tiles.forEach(tile => {
|
||||||
assets.push({key: 'tile_' + tile, value: '/tiles/' + tile, group: 'tiles', type: 'link'});
|
assets.push({key: tile, value: '/tiles/' + tile, group: 'tiles', type: 'link'});
|
||||||
});
|
});
|
||||||
res.json(assets);
|
res.json(assets);
|
||||||
});
|
});
|
||||||
@ -95,7 +95,7 @@ function listTiles(): string[] {
|
|||||||
const files = fs.readdirSync(folder);
|
const files = fs.readdirSync(folder);
|
||||||
|
|
||||||
files.forEach(file => {
|
files.forEach(file => {
|
||||||
tiles.push(file);
|
tiles.push(file.replace('.png', ''));
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user