work on importing

pull/153/head
joneugster 1 year ago
parent 89e19cc019
commit 7ad23dab24

2
.gitignore vendored

@ -1,7 +1,7 @@
node_modules node_modules
client/dist client/dist
server/build server/build
server/tmp server/games
server/lakefile.olean server/lakefile.olean
**/lake-packages/ **/lake-packages/
**/.DS_Store **/.DS_Store

@ -78,13 +78,23 @@ async function doImport (owner, repo, id) {
.reduce((acc, cur) => acc.created_at < cur.created_at ? cur : acc) .reduce((acc, cur) => acc.created_at < cur.created_at ? cur : acc)
artifactId = artifact.id artifactId = artifact.id
const url = artifact.archive_download_url const url = artifact.archive_download_url
if (!fs.existsSync("tmp")){ if (!fs.existsSync("games")){
fs.mkdirSync("tmp"); 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` 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` 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`); // let manifest = fs.readFileSync(`tmp/artifact_${artifactId}_inner/manifest.json`);
// manifest = JSON.parse(manifest); // manifest = JSON.parse(manifest);
// if (manifest.length !== 1) { // if (manifest.length !== 1) {
@ -103,14 +113,15 @@ async function doImport (owner, repo, id) {
} catch (e) { } catch (e) {
progress[id].output += `Error: ${e.toString()}\n${e.stack}` progress[id].output += `Error: ${e.toString()}\n${e.stack}`
} finally { } finally {
if (artifactId) { // if (artifactId) {
// fs.rmSync(`tmp/artifact_${artifactId}.zip`, {force: true, recursive: true}); // // fs.rmSync(`tmp/artifact_${artifactId}.zip`, {force: true, recursive: true});
// fs.rmSync(`tmp/artifact_${artifactId}`, {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/artifact_${artifactId}_inner`, {force: true, recursive: true});
// fs.rmSync(`tmp/archive_${artifactId}.tar`, {force: true, recursive: true}); // // fs.rmSync(`tmp/archive_${artifactId}.tar`, {force: true, recursive: true});
} // }
progress[id].done = true progress[id].done = true
} }
await new Promise(resolve => setTimeout(resolve, 10000))
} }
export const importTrigger = (req, res) => { export const importTrigger = (req, res) => {

@ -86,7 +86,7 @@ function startServerProcess(owner, repo) {
let serverProcess let serverProcess
if (isDevelopment) { if (isDevelopment) {
let args = ["--server", path.join("../../../../", game_dir)] let args = ["--server", path.join('..','..','games',`${owner}`,`${repo}`)]
serverProcess = cp.spawn("./gameserver", args, serverProcess = cp.spawn("./gameserver", args,
{ cwd: path.join(__dirname, "./build/bin/") }) { cwd: path.join(__dirname, "./build/bin/") })
} else { } else {

@ -1,13 +1,19 @@
#/bin/bash #/bin/bash
ARTIFACT_ID=$1 ARTIFACT_ID=$1
OWNER=$2
REPO=$3
echo "Unpacking ZIP." echo "Unpacking ZIP."
unzip -o tmp/artifact_${ARTIFACT_ID}.zip -d tmp/artifact_${ARTIFACT_ID} # unzip -o games/tmp/${OWNER}_${REPO}_${ARTIFACT_ID}.zip -d games/tmp/${OWNER}_${REPO}_${ARTIFACT_ID}
echo "Unpacking TAR." echo "Unpacking game."
for f in tmp/artifact_${ARTIFACT_ID}/* #Should only be one file rm -rf games/${OWNER}/${REPO}
mkdir games/${OWNER}/${REPO}
for f in games/tmp/${OWNER}_${REPO}_${ARTIFACT_ID}/* #Should only be one file
do do
echo "Unpacking $f" echo "Unpacking $f"
mkdir tmp/artifact_${ARTIFACT_ID}_inner #tar -xvzf $f -C games/${OWNER}/${REPO}
tar -xvf $f -C tmp/artifact_${ARTIFACT_ID}_inner mkdir games/${OWNER}/${REPO}
unzip -o $f -d games/${OWNER}/${REPO}
done done

Loading…
Cancel
Save