1
0
forked from noxious/server

asset downloading from server works now

This commit is contained in:
Dennis Postma 2024-06-30 02:04:02 +02:00
parent 6f6fddd861
commit d7cedac171
2 changed files with 40 additions and 2 deletions

View File

@ -0,0 +1,39 @@
import { Server } from "socket.io";
import {TSocket} from "../utilities/Types";
import fs from "fs";
import path from "path";
type Asset = {
key: string
value: string
type: 'base64' | 'link'
}
export default function (socket: TSocket, io: Server) {
socket.on('assets:download', async (data: any, callback: (response: string[]) => void) => {
listTiles().then(tiles => {
callback(tiles);
})
});
}
function listTiles(): string[] {
// get root path
const folder = path.join(process.cwd(), 'public', 'tiles');
// list the files in the folder
let tiles: string[] = [];
fs.readdir(folder, (err, files) => {
if (err) {
console.log(err);
return;
}
files.forEach(file => {
tiles.push(file);
});
});
return tiles;
}

View File

@ -2,9 +2,8 @@
class AssetService
{
static generateTileset() {
}
}
}
export default AssetService;