forked from noxious/server
asset loading after DL now works
This commit is contained in:
parent
d7cedac171
commit
e488318994
@ -10,10 +10,20 @@ type Asset = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function (socket: TSocket, io: Server) {
|
export default function (socket: TSocket, io: Server) {
|
||||||
socket.on('assets:download', async (data: any, callback: (response: string[]) => void) => {
|
socket.on('assets:download', async (data: any, callback: (response: Asset[]) => void) => {
|
||||||
listTiles().then(tiles => {
|
console.log('assets:download requested');
|
||||||
callback(tiles);
|
|
||||||
})
|
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
|
// list the files in the folder
|
||||||
let tiles: string[] = [];
|
let tiles: string[] = [];
|
||||||
|
|
||||||
fs.readdir(folder, (err, files) => {
|
try {
|
||||||
if (err) {
|
const files = fs.readdirSync(folder);
|
||||||
console.log(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
files.forEach(file => {
|
files.forEach(file => {
|
||||||
tiles.push(file);
|
tiles.push(file);
|
||||||
});
|
});
|
||||||
});
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(tiles);
|
||||||
|
|
||||||
return tiles;
|
return tiles;
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user