From 7ad23dab242dc48ea90af2a58b274590d8fa2781 Mon Sep 17 00:00:00 2001 From: joneugster Date: Wed, 22 Nov 2023 15:54:45 +0100 Subject: [PATCH] work on importing --- .gitignore | 2 +- server/import.mjs | 31 +++++++++++++++++++++---------- server/index.mjs | 2 +- server/unpack.sh | 16 +++++++++++----- 4 files changed, 34 insertions(+), 17 deletions(-) mode change 100644 => 100755 server/unpack.sh diff --git a/.gitignore b/.gitignore index a3629ab5..e19678c9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ node_modules client/dist server/build -server/tmp +server/games server/lakefile.olean **/lake-packages/ **/.DS_Store diff --git a/server/import.mjs b/server/import.mjs index 0ac479ea..e507442b 100644 --- a/server/import.mjs +++ b/server/import.mjs @@ -78,13 +78,23 @@ async function doImport (owner, repo, id) { .reduce((acc, cur) => acc.created_at < cur.created_at ? cur : acc) artifactId = artifact.id const url = artifact.archive_download_url - if (!fs.existsSync("tmp")){ - fs.mkdirSync("tmp"); + if (!fs.existsSync("games")){ + fs.mkdirSync("games"); + } + if (!fs.existsSync("games/tmp")){ + fs.mkdirSync("games/tmp"); + } + if (!fs.existsSync(`games/${owner}`)){ + fs.mkdirSync(`games/${owner}`); } progress[id].output += `Download from ${url}\n` - await download(id, url, `tmp/artifact_${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],".") + + // BUG: it doesn't wait for this to finish + await runProcess(id, "/bin/bash", [`${__dirname}/unpack.sh`, artifactId, owner.toLowerCase(), repo.toLowerCase()], ".") + + // let manifest = fs.readFileSync(`tmp/artifact_${artifactId}_inner/manifest.json`); // manifest = JSON.parse(manifest); // if (manifest.length !== 1) { @@ -103,14 +113,15 @@ async function doImport (owner, repo, id) { } catch (e) { progress[id].output += `Error: ${e.toString()}\n${e.stack}` } finally { - if (artifactId) { - // fs.rmSync(`tmp/artifact_${artifactId}.zip`, {force: true, recursive: true}); - // fs.rmSync(`tmp/artifact_${artifactId}`, {force: true, recursive: true}); - // fs.rmSync(`tmp/artifact_${artifactId}_inner`, {force: true, recursive: true}); - // fs.rmSync(`tmp/archive_${artifactId}.tar`, {force: true, recursive: true}); - } + // if (artifactId) { + // // fs.rmSync(`tmp/artifact_${artifactId}.zip`, {force: true, recursive: true}); + // // fs.rmSync(`tmp/artifact_${artifactId}`, {force: true, recursive: true}); + // // fs.rmSync(`tmp/artifact_${artifactId}_inner`, {force: true, recursive: true}); + // // fs.rmSync(`tmp/archive_${artifactId}.tar`, {force: true, recursive: true}); + // } progress[id].done = true } + await new Promise(resolve => setTimeout(resolve, 10000)) } export const importTrigger = (req, res) => { diff --git a/server/index.mjs b/server/index.mjs index 2caca9cc..1ef893b4 100644 --- a/server/index.mjs +++ b/server/index.mjs @@ -86,7 +86,7 @@ function startServerProcess(owner, repo) { let serverProcess if (isDevelopment) { - let args = ["--server", path.join("../../../../", game_dir)] + let args = ["--server", path.join('..','..','games',`${owner}`,`${repo}`)] serverProcess = cp.spawn("./gameserver", args, { cwd: path.join(__dirname, "./build/bin/") }) } else { diff --git a/server/unpack.sh b/server/unpack.sh old mode 100644 new mode 100755 index 5a765db3..88acf952 --- a/server/unpack.sh +++ b/server/unpack.sh @@ -1,13 +1,19 @@ #/bin/bash ARTIFACT_ID=$1 +OWNER=$2 +REPO=$3 echo "Unpacking ZIP." -unzip -o tmp/artifact_${ARTIFACT_ID}.zip -d tmp/artifact_${ARTIFACT_ID} -echo "Unpacking TAR." -for f in tmp/artifact_${ARTIFACT_ID}/* #Should only be one file +# unzip -o games/tmp/${OWNER}_${REPO}_${ARTIFACT_ID}.zip -d games/tmp/${OWNER}_${REPO}_${ARTIFACT_ID} +echo "Unpacking game." +rm -rf games/${OWNER}/${REPO} +mkdir games/${OWNER}/${REPO} + +for f in games/tmp/${OWNER}_${REPO}_${ARTIFACT_ID}/* #Should only be one file do echo "Unpacking $f" - mkdir tmp/artifact_${ARTIFACT_ID}_inner - tar -xvf $f -C tmp/artifact_${ARTIFACT_ID}_inner + #tar -xvzf $f -C games/${OWNER}/${REPO} + mkdir games/${OWNER}/${REPO} + unzip -o $f -d games/${OWNER}/${REPO} done