From 427ce43e95caa9bd77066dc09e9c643a4f243df4 Mon Sep 17 00:00:00 2001 From: joneugster Date: Mon, 27 Nov 2023 17:22:02 +0100 Subject: [PATCH] fix import mechanism --- .env | 1 - .gitignore | 2 +- doc/publish_game.md | 26 ++++++++++++++++++++++++++ server/.gitignore | 5 ++--- server/import.mjs | 10 +++++----- server/index.mjs | 10 +++++----- server/unpack.sh | 2 +- vite.config.ts | 3 +++ 8 files changed, 43 insertions(+), 16 deletions(-) delete mode 100644 .env create mode 100644 doc/publish_game.md diff --git a/.env b/.env deleted file mode 100644 index 01fee6b..0000000 --- a/.env +++ /dev/null @@ -1 +0,0 @@ -LEAN4GAME_SINGLE_GAME=false diff --git a/.gitignore b/.gitignore index e19678c..defd687 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ node_modules client/dist server/build -server/games +games/ server/lakefile.olean **/lake-packages/ **/.DS_Store diff --git a/doc/publish_game.md b/doc/publish_game.md new file mode 100644 index 0000000..d545566 --- /dev/null +++ b/doc/publish_game.md @@ -0,0 +1,26 @@ +# Importing games + +There is an mechanism to import games into your server. In order to use this mechanism, you need +to create a [Github Access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens). A fine-grained access token with only reading rights for public +repos will suffice. + +You need to set the environment variables `LEAN4GAME_GITHUB_USER` and `LEAN4GAME_GITHUB_TOKEN` +with your user name and access token. + +Then you can call: + +> https://{website}/import/trigger/{owner}/{repo} + +where you replace: +- website: The website your server runs on, e.g. `localhost:3000` +- owner, repo: The owner and repository name of the game you want to load from github. + + will trigger to download the latest version of your game from github onto your server. + Once this import reports "Done", you should be able to play your game under: + +> https://{website}/#/g/{owner}/{repo} + +## data management +Everything downloaded remains in the folder `lean4game/games`. +the subfolder `tmp` contains downloaded artifacts and can be deleted without loss. +The other folders should only contain the built lean-games, sorted by owner and repo. diff --git a/server/.gitignore b/server/.gitignore index 103f95b..5358925 100644 --- a/server/.gitignore +++ b/server/.gitignore @@ -1,3 +1,2 @@ -build -adam -nng +build/ +games/ diff --git a/server/import.mjs b/server/import.mjs index 0a39876..40b434b 100644 --- a/server/import.mjs +++ b/server/import.mjs @@ -79,14 +79,14 @@ async function doImport (owner, repo, id) { artifactId = artifact.id const url = artifact.archive_download_url // Make sure the download folder exists - if (!fs.existsSync("../../games")){ - fs.mkdirSync("../../games"); + if (!fs.existsSync("../games")){ + fs.mkdirSync("../games"); } - if (!fs.existsSync("../../games/tmp")){ - fs.mkdirSync("../../games/tmp"); + if (!fs.existsSync("../games/tmp")){ + fs.mkdirSync("../games/tmp"); } progress[id].output += `Download from ${url}\n` - await download(id, url, `../../games/tmp/${owner.toLowerCase()}_${repo.toLowerCase()}_${artifactId}.zip`) + await download(id, url, `../games/tmp/${owner.toLowerCase()}_${repo.toLowerCase()}_${artifactId}.zip`) progress[id].output += `Download finished.\n` await runProcess(id, "/bin/bash", [`${__dirname}/unpack.sh`, artifactId, owner.toLowerCase(), repo.toLowerCase()], ".") diff --git a/server/index.mjs b/server/index.mjs index 64cb83e..853a83b 100644 --- a/server/index.mjs +++ b/server/index.mjs @@ -62,11 +62,11 @@ function startServerProcess(owner, repo) { } let game_dir = (owner == 'local') ? - path.join(__dirname, '..', '..', repo) : - path.join(__dirname, '..', '..', 'games', `${owner}`, `${repo}`) + path.join(__dirname, '..', repo) : + path.join(__dirname, '..', 'games', `${owner}`, `${repo}`) - if(!fs.existsSync(path.join(__dirname, '..', '..', 'games'))) { - console.error(`Did not find the following folder: ${path.join(__dirname, '..', '..', 'games')}`) + if(!fs.existsSync(path.join(__dirname, '..', 'games'))) { + console.error(`Did not find the following folder: ${path.join(__dirname, '..', 'games')}`) console.error('Did you already import any games?') return } @@ -119,7 +119,7 @@ function fillQueue(owner, repo) { // TODO: We disabled queue for now if (!isDevelopment) { // Don't use queue in development - for (let tag in games) { + for (let tag in queueLength) { queue[tag] = [] fillQueue(tag) } diff --git a/server/unpack.sh b/server/unpack.sh index c0645ec..b719a72 100755 --- a/server/unpack.sh +++ b/server/unpack.sh @@ -5,7 +5,7 @@ OWNER=$2 REPO=$3 echo "Creating folders" -cd ../.. +cd .. # mkdir -p games cd games pwd diff --git a/vite.config.ts b/vite.config.ts index c0b536f..ab40967 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -28,6 +28,9 @@ export default defineConfig({ }) ], publicDir: "client/public", + optimizeDeps: { + exclude: ['games'] + }, server: { port: 3000, proxy: {