Skip to content

Commit

Permalink
fix import mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
joneugster committed Nov 27, 2023
1 parent 5fcdee4 commit 427ce43
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 16 deletions.
1 change: 0 additions & 1 deletion .env

This file was deleted.

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/games
games/
server/lakefile.olean
**/lake-packages/
**/.DS_Store
26 changes: 26 additions & 0 deletions doc/publish_game.md
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 2 additions & 3 deletions server/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
build
adam
nng
build/
games/
10 changes: 5 additions & 5 deletions server/import.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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()], ".")
Expand Down
10 changes: 5 additions & 5 deletions server/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion server/unpack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ OWNER=$2
REPO=$3

echo "Creating folders"
cd ../..
cd ..
# mkdir -p games
cd games
pwd
Expand Down
3 changes: 3 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export default defineConfig({
})
],
publicDir: "client/public",
optimizeDeps: {
exclude: ['games']
},
server: {
port: 3000,
proxy: {
Expand Down

0 comments on commit 427ce43

Please sign in to comment.