1
0
forked from noxious/server

asset loading after DL now works

This commit is contained in:
Dennis Postma 2024-06-30 16:16:29 +02:00
parent d7cedac171
commit e488318994

View File

@ -10,10 +10,20 @@ type Asset = {
}
export default function (socket: TSocket, io: Server) {
socket.on('assets:download', async (data: any, callback: (response: string[]) => void) => {
listTiles().then(tiles => {
callback(tiles);
})
socket.on('assets:download', async (data: any, callback: (response: Asset[]) => void) => {
console.log('assets:download requested');
let assets: Asset[] = [];
const tiles = listTiles();
tiles.forEach(tile => {
assets.push({key: tile, value: '/tiles/' + tile, type: 'link'});
});
console.log('assets:download response', assets)
// return the list of assets to the socket
callback(assets);
});
}
@ -24,16 +34,17 @@ function listTiles(): string[] {
// list the files in the folder
let tiles: string[] = [];
fs.readdir(folder, (err, files) => {
if (err) {
console.log(err);
return;
}
try {
const files = fs.readdirSync(folder);
files.forEach(file => {
tiles.push(file);
});
});
} catch (err) {
console.log(err);
}
console.log(tiles);
return tiles;
}