This commit is contained in:
Thomas Forgione 2019-03-22 10:56:49 +01:00
parent 7f926fd15e
commit 5fb61b9956
No known key found for this signature in database
GPG Key ID: 203DAEA747F48F41
9 changed files with 432 additions and 25 deletions

304
package-lock.json generated
View File

@ -91,6 +91,20 @@
"resolved": "https://registry.npmjs.org/babylon/-/babylon-6.18.0.tgz",
"integrity": "sha512-q/UEjfGJ2Cm3oKV71DJz9d25TPnq5rhBVL2Q4fA5wcC3jcrdn7+SssEybFIxwAvvP+YCsCYNKughoF33GxgycQ=="
},
"balanced-match": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c="
},
"binary": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/binary/-/binary-0.3.0.tgz",
"integrity": "sha1-n2BVO8XOjDOG87VTz/R0Yq3sqnk=",
"requires": {
"buffers": "~0.1.1",
"chainsaw": "~0.1.0"
}
},
"body-parser": {
"version": "1.18.3",
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.18.3.tgz",
@ -108,6 +122,29 @@
"type-is": "~1.6.16"
}
},
"brace-expansion": {
"version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
}
},
"buffers": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/buffers/-/buffers-0.1.1.tgz",
"integrity": "sha1-skV5w77U1tOWru5tmorn9Ugqt7s="
},
"busboy": {
"version": "0.2.14",
"resolved": "https://registry.npmjs.org/busboy/-/busboy-0.2.14.tgz",
"integrity": "sha1-bCpiLvz0fFe7vh4qnDetNseSVFM=",
"requires": {
"dicer": "0.2.5",
"readable-stream": "1.1.x"
}
},
"bytes": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz",
@ -127,6 +164,14 @@
"lazy-cache": "^1.0.3"
}
},
"chainsaw": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/chainsaw/-/chainsaw-0.1.0.tgz",
"integrity": "sha1-XqtQsor+WAdNDVgpE4iCi15fvJg=",
"requires": {
"traverse": ">=0.3.0 <0.4"
}
},
"character-parser": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/character-parser/-/character-parser-2.2.0.tgz",
@ -153,6 +198,11 @@
"wordwrap": "0.0.2"
}
},
"concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
},
"constantinople": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/constantinople/-/constantinople-3.1.2.tgz",
@ -189,6 +239,11 @@
"resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.5.tgz",
"integrity": "sha512-klh/kDpwX8hryYL14M9w/xei6vrv6sE8gTHDG7/T/+SEovB/G4ejwcfE/CBzO6Edsu+OETZMZ3wcX/EjUkrl5A=="
},
"core-util-is": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
"integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac="
},
"debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
@ -212,6 +267,15 @@
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz",
"integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA="
},
"dicer": {
"version": "0.2.5",
"resolved": "https://registry.npmjs.org/dicer/-/dicer-0.2.5.tgz",
"integrity": "sha1-WZbAhrszIYyBLAkL3cCc0S+stw8=",
"requires": {
"readable-stream": "1.1.x",
"streamsearch": "0.1.2"
}
},
"doctypes": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/doctypes/-/doctypes-1.1.0.tgz",
@ -279,6 +343,14 @@
"vary": "~1.1.2"
}
},
"express-fileupload": {
"version": "1.1.3-alpha.1",
"resolved": "https://registry.npmjs.org/express-fileupload/-/express-fileupload-1.1.3-alpha.1.tgz",
"integrity": "sha512-u87l4778UiOKAPWL+SOw+hIRV6CMPgz96H39AAsXGJar6ke7LNbdOZCkG9aXxJHDC0cmX/cHfgilXee0MHDgDQ==",
"requires": {
"busboy": "^0.2.14"
}
},
"finalhandler": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.1.tgz",
@ -303,11 +375,48 @@
"resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
"integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac="
},
"fs.realpath": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8="
},
"fstream": {
"version": "0.1.31",
"resolved": "https://registry.npmjs.org/fstream/-/fstream-0.1.31.tgz",
"integrity": "sha1-czfwWPu7vvqMn1YaKMqwhJICyYg=",
"requires": {
"graceful-fs": "~3.0.2",
"inherits": "~2.0.0",
"mkdirp": "0.5",
"rimraf": "2"
}
},
"function-bind": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
"integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A=="
},
"glob": {
"version": "7.1.3",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz",
"integrity": "sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==",
"requires": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^3.0.4",
"once": "^1.3.0",
"path-is-absolute": "^1.0.0"
}
},
"graceful-fs": {
"version": "3.0.11",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-3.0.11.tgz",
"integrity": "sha1-dhPHeKGv6mLyXGMKCG1/Osu92Bg=",
"requires": {
"natives": "^1.1.0"
}
},
"has": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz",
@ -335,6 +444,15 @@
"safer-buffer": ">= 2.1.2 < 3"
}
},
"inflight": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
"integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
"requires": {
"once": "^1.3.0",
"wrappy": "1"
}
},
"inherits": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
@ -379,6 +497,11 @@
"has": "^1.0.1"
}
},
"isarray": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
"integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8="
},
"js-stringify": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/js-stringify/-/js-stringify-1.0.2.tgz",
@ -416,6 +539,28 @@
"resolved": "https://registry.npmjs.org/longest/-/longest-1.0.1.tgz",
"integrity": "sha1-MKCy2jj3N3DoKUoNIuZiXtd9AJc="
},
"match-stream": {
"version": "0.0.2",
"resolved": "https://registry.npmjs.org/match-stream/-/match-stream-0.0.2.tgz",
"integrity": "sha1-mesFAJOzTf+t5CG5rAtBCpz6F88=",
"requires": {
"buffers": "~0.1.1",
"readable-stream": "~1.0.0"
},
"dependencies": {
"readable-stream": {
"version": "1.0.34",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.34.tgz",
"integrity": "sha1-Elgg40vIQtLyqq+v5MKRbuMsFXw=",
"requires": {
"core-util-is": "~1.0.0",
"inherits": "~2.0.1",
"isarray": "0.0.1",
"string_decoder": "~0.10.x"
}
}
}
},
"media-typer": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
@ -449,11 +594,37 @@
"mime-db": "~1.38.0"
}
},
"minimatch": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
"requires": {
"brace-expansion": "^1.1.7"
}
},
"minimist": {
"version": "0.0.8",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0="
},
"mkdirp": {
"version": "0.5.1",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
"requires": {
"minimist": "0.0.8"
}
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
},
"natives": {
"version": "1.1.6",
"resolved": "https://registry.npmjs.org/natives/-/natives-1.1.6.tgz",
"integrity": "sha512-6+TDFewD4yxY14ptjKaS63GVdtKiES1pTPyxn9Jb0rBqPMZ7VcCiooEhPNsr+mqHtMGxa/5c/HhcC4uPEUw/nA=="
},
"negotiator": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz",
@ -472,11 +643,29 @@
"ee-first": "1.1.1"
}
},
"once": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
"requires": {
"wrappy": "1"
}
},
"over": {
"version": "0.0.5",
"resolved": "https://registry.npmjs.org/over/-/over-0.0.5.tgz",
"integrity": "sha1-8phS5w/X4l82DgE6jsRMgq7bVwg="
},
"parseurl": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.2.tgz",
"integrity": "sha1-/CidTtiZMRlGDBViUyYs3I3mW/M="
},
"path-is-absolute": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18="
},
"path-parse": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz",
@ -618,6 +807,30 @@
"resolved": "https://registry.npmjs.org/pug-walk/-/pug-walk-1.1.7.tgz",
"integrity": "sha1-wA1cUSi6xYBr7BXSt+fNq+QlMfM="
},
"pullstream": {
"version": "0.4.1",
"resolved": "https://registry.npmjs.org/pullstream/-/pullstream-0.4.1.tgz",
"integrity": "sha1-1vs79a7Wl+gxFQ6xACwlo/iuExQ=",
"requires": {
"over": ">= 0.0.5 < 1",
"readable-stream": "~1.0.31",
"setimmediate": ">= 1.0.2 < 2",
"slice-stream": ">= 1.0.0 < 2"
},
"dependencies": {
"readable-stream": {
"version": "1.0.34",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.34.tgz",
"integrity": "sha1-Elgg40vIQtLyqq+v5MKRbuMsFXw=",
"requires": {
"core-util-is": "~1.0.0",
"inherits": "~2.0.1",
"isarray": "0.0.1",
"string_decoder": "~0.10.x"
}
}
}
},
"qs": {
"version": "6.5.2",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz",
@ -639,6 +852,17 @@
"unpipe": "1.0.0"
}
},
"readable-stream": {
"version": "1.1.14",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz",
"integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=",
"requires": {
"core-util-is": "~1.0.0",
"inherits": "~2.0.1",
"isarray": "0.0.1",
"string_decoder": "~0.10.x"
}
},
"regenerator-runtime": {
"version": "0.11.1",
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz",
@ -665,6 +889,14 @@
"align-text": "^0.1.1"
}
},
"rimraf": {
"version": "2.6.3",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz",
"integrity": "sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==",
"requires": {
"glob": "^7.1.3"
}
},
"safe-buffer": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
@ -706,11 +938,37 @@
"send": "0.16.2"
}
},
"setimmediate": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz",
"integrity": "sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU="
},
"setprototypeof": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.0.tgz",
"integrity": "sha512-BvE/TwpZX4FXExxOxZyRGQQv651MSwmWKZGqvmPcRIjDqWub67kTKuIMx43cZZrS/cBBzwBcNDWoFxt2XEFIpQ=="
},
"slice-stream": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/slice-stream/-/slice-stream-1.0.0.tgz",
"integrity": "sha1-WzO9ZvATsaf4ZGCwPUY97DmtPqA=",
"requires": {
"readable-stream": "~1.0.31"
},
"dependencies": {
"readable-stream": {
"version": "1.0.34",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.34.tgz",
"integrity": "sha1-Elgg40vIQtLyqq+v5MKRbuMsFXw=",
"requires": {
"core-util-is": "~1.0.0",
"inherits": "~2.0.1",
"isarray": "0.0.1",
"string_decoder": "~0.10.x"
}
}
}
},
"source-map": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
@ -721,6 +979,16 @@
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.4.0.tgz",
"integrity": "sha512-zhSCtt8v2NDrRlPQpCNtw/heZLtfUDqxBM1udqikb/Hbk52LK4nQSwr10u77iopCW5LsyHpuXS0GnEc48mLeew=="
},
"streamsearch": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-0.1.2.tgz",
"integrity": "sha1-gIudDlb8Jz2Am6VzOOkpkZoanxo="
},
"string_decoder": {
"version": "0.10.31",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
"integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ="
},
"to-fast-properties": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-1.0.3.tgz",
@ -731,6 +999,11 @@
"resolved": "https://registry.npmjs.org/token-stream/-/token-stream-0.0.1.tgz",
"integrity": "sha1-zu78cXp2xDFvEm0LnbqlXX598Bo="
},
"traverse": {
"version": "0.3.9",
"resolved": "https://registry.npmjs.org/traverse/-/traverse-0.3.9.tgz",
"integrity": "sha1-cXuPIgzAu3tE5AUUwisui7xw2Lk="
},
"type-is": {
"version": "1.6.16",
"resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.16.tgz",
@ -768,6 +1041,32 @@
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
"integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw="
},
"unzip": {
"version": "0.1.11",
"resolved": "https://registry.npmjs.org/unzip/-/unzip-0.1.11.tgz",
"integrity": "sha1-iXScY7BY19kNYZ+GuYqhU107l/A=",
"requires": {
"binary": ">= 0.3.0 < 1",
"fstream": ">= 0.1.30 < 1",
"match-stream": ">= 0.0.2 < 1",
"pullstream": ">= 0.4.1 < 1",
"readable-stream": "~1.0.31",
"setimmediate": ">= 1.0.1 < 2"
},
"dependencies": {
"readable-stream": {
"version": "1.0.34",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.34.tgz",
"integrity": "sha1-Elgg40vIQtLyqq+v5MKRbuMsFXw=",
"requires": {
"core-util-is": "~1.0.0",
"inherits": "~2.0.1",
"isarray": "0.0.1",
"string_decoder": "~0.10.x"
}
}
}
},
"utils-merge": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz",
@ -802,6 +1101,11 @@
"resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.2.tgz",
"integrity": "sha1-t5Zpu0LstAn4PVg8rVLKF+qhZD8="
},
"wrappy": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
},
"yargs": {
"version": "3.10.0",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-3.10.0.tgz",

View File

@ -7,6 +7,8 @@
},
"dependencies": {
"express": "^4.16.4",
"pug": "^2.0.3"
"express-fileupload": "^1.1.3-alpha.1",
"pug": "^2.0.3",
"unzip": "^0.1.11"
}
}

View File

@ -1 +1,3 @@
*.pyc
ai_manager
ai_manager_old

View File

@ -1,4 +0,0 @@
from os.path import dirname, basename, isfile
import glob
modules = glob.glob(dirname(__file__)+"/*/ai.py")
__all__ = ['.'.join(f.split('.')[:-1]) for f in modules if isfile(f)]

View File

@ -1,11 +0,0 @@
"""An AI to try things"""
from tron.player import Player, Direction
class Ai(Player):
"""" A basic AI"""
def __init__(self):
super(Ai, self).__init__()
def action(self, game):
return Direction.RIGHT

View File

@ -1,8 +0,0 @@
from tron.player import Player, Direction
class Ai(Player):
def __init__(self):
super(Ai, self).__init__()
def action(self, game):
return Direction.LEFT

View File

@ -70,6 +70,7 @@ def run_battle(ai1, ai2):
def main():
print('Welcome to pytron run!')
dictionnary = {"ais": list(map(lambda x: x.name, ais)), "battles": {}}
for (id1, ai1) in enumerate(ais):
@ -84,6 +85,8 @@ def main():
with open("assets/data.json", "w") as f:
f.write(json.dumps(dictionnary))
print('Pytron run has finished')
if __name__ == '__main__':
main()

View File

@ -1,8 +1,56 @@
const fs = require('fs');
const process = require('process');
const pathtools = require('path');
const express = require('express');
const fileUpload = require("express-fileupload");
const { spawn } = require('child_process');
const pug = require('pug');
const unzip = require('unzip');
const app = express();
const port = 8000;
const aisPath = "pytron_run/ai_manager/"
const aisPathOld = "pytron_run/ai_manager_old"
let pythonRunning = false;
let pythonShouldRun = false;
function runPython() {
process.stdout.write('Requested to run python');
if (pythonRunning) {
process.stdout.write(' buy python is already running');
pythonShouldRun = true;
} else {
pythonRunning = true;
}
process.stdout.write('\n');
let p = spawn('python', ['pytron_run/run.py']);
p.stdout.on('data', (data) => {
let content = data.toString().split('\n');
for (let line of content) {
console.log("run.py: " + line);
}
});
p.stderr.on('data', (data) => {
let content = data.toString().split('\n');
for (let line of content) {
console.log("run.py: " + line);
}
});
p.on('close', (code) => {
process.stdout.write("Python finished executing");
if (pythonShouldRun) {
process.stdout.write(' but another request arrive, so we will relaunch it\n');
pythonShouldRun = false;
runPython();
} else {
process.stdout.write('\n');
pythonRunning = false;
}
});
}
function parse(data) {
let content = JSON.parse(data);
@ -44,6 +92,7 @@ function parse(data) {
}
app.set('view engine', 'pug');
app.use(fileUpload());
app.get('/', (req, res) => {
fs.readFile('assets/data.json', 'utf-8', (err, data) => {
@ -55,8 +104,56 @@ app.get('/', (req, res) => {
});
});
app.get('/upload', (req, res) => {
res.render('upload', {});
});
app.post('/upload-target', (req, res) => {
let path = pathtools.join(aisPath, req.body.name)
try {
if (fs.statSync(path).isDirectory()) {
// Move it to old
let version = 0;
for(;;) {
let movePath = pathtools.join(aisPathOld, req.body.name + '.' + version);
try {
fs.statSync(movePath);
// If the sync succeded, it means that the directory already exists
version++;
} catch {
// If we're here, it means that we found the right path. We
// will move the old one to the old directories, and save
// the new one
fs.renameSync(path, movePath);
break;
}
}
}
} catch {
// Nothing to do here
}
fs.mkdirSync(path);
let zipfile = pathtools.join(path, "archive.zip");
req.files.archive.mv(zipfile, (err) => {
console.log(err);
fs.createReadStream(zipfile)
.pipe(unzip.Extract({path}))
.on('close', () => {
// Trigger python_run
runPython();
res.send('yo');
})
.on('error', () => {
res.send('an error occured while extracting the archive')
});
});
});
app.use('/static', express.static('static'));
app.listen(port, () => {
console.log(`Example app listening on port ${port}!`)
console.log(`Server listening on port ${port}!`)
})

22
views/upload.pug Normal file
View File

@ -0,0 +1,22 @@
extends base
block content
section.section
.container
.columns.is-centered
.column.is-narrow.is-desktop
form(action="upload-target", method="POST", encType="multipart/form-data")
.field
label.label Name
input.input(type="text", name="name", placeholder="Name of your AI")
.field
.file.has-name
label.file-label
input.file-input(type="file", name="archive")
span.file-cta
span.file-icon
i.fas.fa-upload
span.file-label Choose a file…
span.file-name
.control
button.button.is-link Submit