From e488318994f56105320d64322fbe16e1db56631c Mon Sep 17 00:00:00 2001 From: Dennis Postma Date: Sun, 30 Jun 2024 16:16:29 +0200 Subject: [PATCH] asset loading after DL now works --- src/app/events/AssetsDownload.ts | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/app/events/AssetsDownload.ts b/src/app/events/AssetsDownload.ts index 67cd10a..5b28beb 100644 --- a/src/app/events/AssetsDownload.ts +++ b/src/app/events/AssetsDownload.ts @@ -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; } \ No newline at end of file