asset downloading from server works now
This commit is contained in:
parent
6f6fddd861
commit
d7cedac171
39
src/app/events/AssetsDownload.ts
Normal file
39
src/app/events/AssetsDownload.ts
Normal 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;
|
||||||
|
}
|
@ -4,7 +4,6 @@ class AssetService
|
|||||||
static generateTileset() {
|
static generateTileset() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default AssetService;
|
export default AssetService;
|
Loading…
x
Reference in New Issue
Block a user