Skip to content

Commit

Permalink
refactor: kcl playground frontend
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy committed Jul 8, 2024
1 parent 6d70443 commit e1ae8cc
Show file tree
Hide file tree
Showing 48 changed files with 8,962 additions and 11,799 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
run:
cd web && npm run build
pluto run

fmt:
Expand Down
39 changes: 6 additions & 33 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import json
import re
import hashlib
from pluto_client import Website, KVStore, Router, HttpRequest, HttpResponse
import kcl_lib.api as kcl_api
import tempfile
from pluto_client import Website, Router, HttpRequest, HttpResponse
import kcl_lib.api as kcl_api

color_pattern = re.compile(r"\x1b\[[0-9;]+m")
api = kcl_api.API()
router = Router("router")
store = KVStore("store")
website = Website("./website", "kcl-playground")
website = Website("./web/dist", "kcl-playground")
website.addEnv("BACKEND_URL", router.url())


Expand Down Expand Up @@ -37,7 +35,7 @@ def compile_handler(req: HttpRequest) -> HttpResponse:
status_code=200,
body=json.dumps(
{
"errors": color_pattern.sub("", str(err).removeprefix("ERROR:")),
"error": color_pattern.sub("", str(err).removeprefix("ERROR:")),
}
),
)
Expand All @@ -46,23 +44,14 @@ def compile_handler(req: HttpRequest) -> HttpResponse:
status_code=200,
body=json.dumps(
{
"errors": color_pattern.sub("", result.err_message),
"error": color_pattern.sub("", result.err_message),
}
),
)
else:
return HttpResponse(
status_code=200,
body=json.dumps(
{
"events": [
{
"message": result.yaml_result,
"kind": "stdout",
}
],
}
),
body=json.dumps({"body": result.yaml_result}),
)


Expand All @@ -72,21 +61,5 @@ def fmt_handler(req: HttpRequest) -> HttpResponse:
return HttpResponse(status_code=200, body=json.dumps({"body": result}))


def share_handler(req: HttpRequest) -> HttpResponse:
code = req.body["body"]
sha1 = hashlib.sha1()
sha1.update(code.encode("utf-8"))
id = sha1.hexdigest()
store.set(id, code)
return HttpResponse(status_code=200, body=json.dumps({"body": id}))


def query_handler(req: HttpRequest) -> HttpResponse:
id = req.query["id"]
return HttpResponse(status_code=200, body=json.dumps({"body": store.get(id)}))


router.post("/-/play/compile", compile_handler)
router.post("/-/play/fmt", fmt_handler)
router.post("/-/play/share", share_handler)
router.get("/-/play/query", query_handler)
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"name": "kcl-playground",
"version": "0.0.0",
"version": "0.9.0",
"scripts": {
"dev": "pluto run",
"test:dev": "pluto test --sim",
"test:prod": "pluto test",
"deploy": "pluto deploy",
Expand Down
1 change: 1 addition & 0 deletions web/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/dist
7 changes: 7 additions & 0 deletions web/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"printWidth": 100,
"semi": true,
"singleQuote": true,
"trailingComma": "all",
"arrowParens": "always"
}
Loading

0 comments on commit e1ae8cc

Please sign in to comment.