Skip to content

Commit

Permalink
work on importing
Browse files Browse the repository at this point in the history
  • Loading branch information
joneugster committed Nov 22, 2023
1 parent 89e19cc commit 7ad23da
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
node_modules
client/dist
server/build
server/tmp
server/games
server/lakefile.olean
**/lake-packages/
**/.DS_Store
31 changes: 21 additions & 10 deletions server/import.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion server/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 11 additions & 5 deletions server/unpack.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7ad23da

Please sign in to comment.