Small Website to play Web-based games.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

33 rindas
853 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. }