Small Website to play Web-based games.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

33 lines
852 B

  1. import {readdir, readFile, stat} from 'fs/promises';
  2. import {join} from 'path';
  3. const BASE_PATH = 'public/games';
  4. export type Game = {
  5. id: string,
  6. name: string,
  7. main: string,
  8. thumbnail: string,
  9. data: {
  10. aspectRatio: number,
  11. },
  12. }
  13. export const getAvailableGames = async (): Promise<Game[]> => {
  14. const dirs = await readdir(BASE_PATH);
  15. const dirStat = await Promise.all(dirs.map(async (d) => ({
  16. id: d,
  17. stat: await stat(join(BASE_PATH, d)),
  18. })));
  19. const gameStat = dirStat.filter((d) => d.stat.isDirectory());
  20. return Promise.all(gameStat.map(async (g) => {
  21. const manifestBuffer = await readFile(join(BASE_PATH, g.id, 'manifest.json'));
  22. const manifestString = manifestBuffer.toString('utf-8');
  23. const manifestJson = JSON.parse(manifestString);
  24. return {
  25. ...manifestJson,
  26. id: g.id,
  27. };
  28. }));
  29. }