Skip to content

Commit

Permalink
fix: send image to frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
visualDust committed Dec 1, 2023
1 parent edc29c0 commit 8ec94e6
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 175 deletions.
20 changes: 14 additions & 6 deletions neetbox/daemon/server/_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
werkzeug_log.setLevel(logging.ERROR) # disable flask http call logs

import setproctitle
from flask import abort, json, request, send_from_directory
from flask import Response, abort, json, request, send_from_directory
from websocket_server import WebsocketServer

from neetbox.daemon._protocol import *
Expand Down Expand Up @@ -348,18 +348,26 @@ def upload_image(project_id):
lastrowid = save_blob_to_history(
project_id=project_id, table_name="image", json_data=_json_data, blob_data=image_bytes
)
# ws_send_to_frontends_of_id() # todo
ws_send_to_frontends_of_id(
project_id,
json.dumps({"event-type": "image", "imageId": lastrowid, "metadata": _json_data}),
)
return {"result": "ok", "id": lastrowid}

@app.route(f"/image/<project_id>/<image_id>", methods=["GET"])
def get_image_of_id(project_id, image_id: int):
if project_id not in __BRIDGES:
return # cannot operate history if client is not connected
_, _, _json_data, _blob_data = __BRIDGES[project_id].historyDB.read(
table_name="image", condition=QueryCondition(id_range=image_id)
meta = request.args.get("meta") is not None
[(_, _, json, image)] = __BRIDGES[project_id].historyDB.read_blob(
table_name="image", condition=QueryCondition(id_range=image_id), meta_only=meta
)

return (
Response(json, mimetype="application/json")
if meta
else Response(image, mimetype="image")
)
_json_data["image"] = _blob_data
return _json_data

@app.route(f"{FRONTEND_API_ROOT}/shutdown", methods=["POST"])
def shutdown():
Expand Down
2 changes: 2 additions & 0 deletions neetbox/frontend/src/services/projectWebsocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export class WsClient {
} else if (json["event-type"] === "log") {
json.payload._id = this.nextLogId++;
project.handleLog(json.payload);
} else {
console.warn("ws unhandled message", json);
}
};
}
Expand Down
42 changes: 21 additions & 21 deletions neetbox/frontend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@

"@douyinfe/[email protected]":
version "2.47.1"
resolved "https://registry.yarnpkg.com/@douyinfe/semi-animation-react/-/semi-animation-react-2.47.1.tgz#1148e43e2e3cef8b7f57b42f484d403a71958f8e"
resolved "https://mirrors.huaweicloud.com/repository/npm/@douyinfe/semi-animation-react/-/semi-animation-react-2.47.1.tgz#1148e43e2e3cef8b7f57b42f484d403a71958f8e"
integrity sha512-5BzuEHSOW06IbNotshB1RsUoq0oJdY9IpmbQQL77kmvu8DvKnIsGDeYWP6TYwoKycCCMIDyCYsD13s+qMUGvwg==
dependencies:
"@douyinfe/semi-animation" "2.47.1"
Expand All @@ -262,19 +262,19 @@

"@douyinfe/[email protected]":
version "2.47.1"
resolved "https://registry.yarnpkg.com/@douyinfe/semi-animation-styled/-/semi-animation-styled-2.47.1.tgz#2d8b8403ce239a14139e17fa13ee35d03a833cf1"
resolved "https://mirrors.huaweicloud.com/repository/npm/@douyinfe/semi-animation-styled/-/semi-animation-styled-2.47.1.tgz#2d8b8403ce239a14139e17fa13ee35d03a833cf1"
integrity sha512-jjEwbVMKaIh74A1svvLdSseGIiJYX0CiMisfiwWtp/f3OCJTB20CaIHrINGTti5R9bB/MD5Oe3GuHLoD6/JQMw==

"@douyinfe/[email protected]":
version "2.47.1"
resolved "https://registry.yarnpkg.com/@douyinfe/semi-animation/-/semi-animation-2.47.1.tgz#aca61369ea6899a8dfc77109ba06ab04013b73b5"
resolved "https://mirrors.huaweicloud.com/repository/npm/@douyinfe/semi-animation/-/semi-animation-2.47.1.tgz#aca61369ea6899a8dfc77109ba06ab04013b73b5"
integrity sha512-DG4bP3N3UZSeIoP4hDGFyKzNF83cd9vVjCJnxHUGTtVtFSpO1b47iQ0kD1qcgkUZghEqeixPFFu+6ilhq0qzZg==
dependencies:
bezier-easing "^2.1.0"

"@douyinfe/[email protected]":
version "2.47.1"
resolved "https://registry.yarnpkg.com/@douyinfe/semi-foundation/-/semi-foundation-2.47.1.tgz#ca45941d057a1ebc71b93e7ec4f5980faf0b5dc4"
resolved "https://mirrors.huaweicloud.com/repository/npm/@douyinfe/semi-foundation/-/semi-foundation-2.47.1.tgz#ca45941d057a1ebc71b93e7ec4f5980faf0b5dc4"
integrity sha512-2yO2kPO9TX+7gzRikmUy34CRckTB3Qkt+K9eIA2FMnIQ7R00yus7nAeoLaOaU8qUJd+OrqIEtwHGxthd0V1Wrg==
dependencies:
"@douyinfe/semi-animation" "2.47.1"
Expand All @@ -288,26 +288,26 @@

"@douyinfe/[email protected]", "@douyinfe/semi-icons@^2.47.1":
version "2.47.1"
resolved "https://registry.yarnpkg.com/@douyinfe/semi-icons/-/semi-icons-2.47.1.tgz#100883e71a7eab9ca2abb91110f48a348b9ad895"
resolved "https://mirrors.huaweicloud.com/repository/npm/@douyinfe/semi-icons/-/semi-icons-2.47.1.tgz#100883e71a7eab9ca2abb91110f48a348b9ad895"
integrity sha512-+gC22MWuOCKSRwB5Yxq55+NUgoO9b7stYvIkuCmPuD3kYgjFhhGRR+o9dscQmDa8Wjd98wY05zI01S4BV/ptLw==
dependencies:
classnames "^2.2.6"

"@douyinfe/[email protected]":
version "2.47.1"
resolved "https://registry.yarnpkg.com/@douyinfe/semi-illustrations/-/semi-illustrations-2.47.1.tgz#c4e1d4881cdc50ebb2f370b5cde299706dc5a5f6"
resolved "https://mirrors.huaweicloud.com/repository/npm/@douyinfe/semi-illustrations/-/semi-illustrations-2.47.1.tgz#c4e1d4881cdc50ebb2f370b5cde299706dc5a5f6"
integrity sha512-ouhdAHzcBEW5kv5EFvHQsITSHIxlL0mnCMz63TVIywGA6QnCcxyMG6er0rlChAnu76FhlERR/Ys5Dlf2e5VhSQ==

"@douyinfe/[email protected]":
version "2.47.1"
resolved "https://registry.yarnpkg.com/@douyinfe/semi-theme-default/-/semi-theme-default-2.47.1.tgz#5a43c71764bebe9ec0add75ea4de25dc42d05e35"
resolved "https://mirrors.huaweicloud.com/repository/npm/@douyinfe/semi-theme-default/-/semi-theme-default-2.47.1.tgz#5a43c71764bebe9ec0add75ea4de25dc42d05e35"
integrity sha512-GGWH6sBvwBft8eB+7V0VSueSVmsfLhabzSv/GXYwZeyljyuj4/JTRZa2qyiSgN1BOZbwn3vPW1si2QFioR0gQA==
dependencies:
glob "^7.1.6"

"@douyinfe/semi-ui@^2.47.1":
version "2.47.1"
resolved "https://registry.yarnpkg.com/@douyinfe/semi-ui/-/semi-ui-2.47.1.tgz#7553114eeea38c285633a19acda2472f48676032"
resolved "https://mirrors.huaweicloud.com/repository/npm/@douyinfe/semi-ui/-/semi-ui-2.47.1.tgz#7553114eeea38c285633a19acda2472f48676032"
integrity sha512-HxYvjn32DJsDPmcspM8jzHMY84f4skEAN6Zheg4FPW74uAUSnGILj5HXd/vZM4c6bbJeQSnxP0Grqa5qrZFpkg==
dependencies:
"@dnd-kit/core" "^6.0.8"
Expand All @@ -334,19 +334,19 @@

"@emotion/is-prop-valid@^1.2.1":
version "1.2.1"
resolved "https://registry.yarnpkg.com/@emotion/is-prop-valid/-/is-prop-valid-1.2.1.tgz#23116cf1ed18bfeac910ec6436561ecb1a3885cc"
resolved "https://mirrors.huaweicloud.com/repository/npm/@emotion/is-prop-valid/-/is-prop-valid-1.2.1.tgz#23116cf1ed18bfeac910ec6436561ecb1a3885cc"
integrity sha512-61Mf7Ufx4aDxx1xlDeOm8aFFigGHE4z+0sKCa+IHCeZKiyP9RLD0Mmx7m8b9/Cf37f7NAvQOOJAbQQGVr5uERw==
dependencies:
"@emotion/memoize" "^0.8.1"

"@emotion/memoize@^0.8.1":
version "0.8.1"
resolved "https://registry.yarnpkg.com/@emotion/memoize/-/memoize-0.8.1.tgz#c1ddb040429c6d21d38cc945fe75c818cfb68e17"
resolved "https://mirrors.huaweicloud.com/repository/npm/@emotion/memoize/-/memoize-0.8.1.tgz#c1ddb040429c6d21d38cc945fe75c818cfb68e17"
integrity sha512-W2P2c/VRW1/1tLox0mVUalvnWXxavmv/Oum2aPsRcoDJuob75FC3Y8FbpfLwUegRcxINtGUMPq0tFCvYNTBXNA==

"@emotion/unitless@^0.8.0":
version "0.8.1"
resolved "https://registry.yarnpkg.com/@emotion/unitless/-/unitless-0.8.1.tgz#182b5a4704ef8ad91bde93f7a860a88fd92c79a3"
resolved "https://mirrors.huaweicloud.com/repository/npm/@emotion/unitless/-/unitless-0.8.1.tgz#182b5a4704ef8ad91bde93f7a860a88fd92c79a3"
integrity sha512-KOEGMu6dmJZtpadb476IsZBclKvILjopjUii3V+7MnXIQCYh8W3NgNcgwo21n9LXZX6EDIKvqfjYxXebDwxKmQ==

"@esbuild/[email protected]":
Expand Down Expand Up @@ -709,7 +709,7 @@

"@types/stylis@^4.0.2":
version "4.2.4"
resolved "https://registry.yarnpkg.com/@types/stylis/-/stylis-4.2.4.tgz#14b61f022e832d87d442ae1795e0f0f0b7daa879"
resolved "https://mirrors.huaweicloud.com/repository/npm/@types/stylis/-/stylis-4.2.4.tgz#14b61f022e832d87d442ae1795e0f0f0b7daa879"
integrity sha512-36ZrGJ8fgtBr6nwNnuJ9jXIj+bn/pF6UoqmrQT7+Y99+tFFeHHsoR54+194dHdyhPjgbeoNz3Qru0oRt0l6ASQ==

"@typescript-eslint/eslint-plugin@^6.10.0":
Expand Down Expand Up @@ -999,7 +999,7 @@ callsites@^3.0.0:

camelize@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/camelize/-/camelize-1.0.1.tgz#89b7e16884056331a35d6b5ad064332c91daa6c3"
resolved "https://mirrors.huaweicloud.com/repository/npm/camelize/-/camelize-1.0.1.tgz#89b7e16884056331a35d6b5ad064332c91daa6c3"
integrity sha512-dU+Tx2fsypxTgtLoE36npi3UqcjSSMNYfkqgmoEhtZrraP5VWq0K7FkWVTYa8eMPtnU/G2txVsfdCJTn9uzpuQ==

caniuse-lite@^1.0.30001541:
Expand Down Expand Up @@ -1109,12 +1109,12 @@ cross-spawn@^7.0.2:

css-color-keywords@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/css-color-keywords/-/css-color-keywords-1.0.0.tgz#fea2616dc676b2962686b3af8dbdbe180b244e05"
resolved "https://mirrors.huaweicloud.com/repository/npm/css-color-keywords/-/css-color-keywords-1.0.0.tgz#fea2616dc676b2962686b3af8dbdbe180b244e05"
integrity sha512-FyyrDHZKEjXDpNJYvVsV960FiqQyXc/LlYmsxl2BcdMb2WPx0OGRVgTg55rPSyLSNMqP52R9r8geSp7apN3Ofg==

css-to-react-native@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/css-to-react-native/-/css-to-react-native-3.2.0.tgz#cdd8099f71024e149e4f6fe17a7d46ecd55f1e32"
resolved "https://mirrors.huaweicloud.com/repository/npm/css-to-react-native/-/css-to-react-native-3.2.0.tgz#cdd8099f71024e149e4f6fe17a7d46ecd55f1e32"
integrity sha512-e8RKaLXMOFii+02mOlqwjbD00KSEKqblnpO9e++1aXS1fPQOpS1YoqdVHBqPjHNoxeF2mimzVqawm2KCbEdtHQ==
dependencies:
camelize "^1.0.0"
Expand Down Expand Up @@ -2036,7 +2036,7 @@ nanoid@^3.3.6:

nanoid@^5.0.3:
version "5.0.3"
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-5.0.3.tgz#6c97f53d793a7a1de6a38ebb46f50f95bf9793c7"
resolved "https://mirrors.huaweicloud.com/repository/npm/nanoid/-/nanoid-5.0.3.tgz#6c97f53d793a7a1de6a38ebb46f50f95bf9793c7"
integrity sha512-I7X2b22cxA4LIHXPSqbBCEQSL+1wv8TuoefejsX4HFWyC6jc5JG7CEaxOltiKjc1M+YCS2YkrZZcj4+dytw9GA==

natural-compare@^1.4.0:
Expand Down Expand Up @@ -2184,7 +2184,7 @@ picomatch@^2.0.4, picomatch@^2.2.1, picomatch@^2.3.1:

postcss-value-parser@^4.0.2:
version "4.2.0"
resolved "https://registry.yarnpkg.com/postcss-value-parser/-/postcss-value-parser-4.2.0.tgz#723c09920836ba6d3e5af019f92bc0971c02e514"
resolved "https://mirrors.huaweicloud.com/repository/npm/postcss-value-parser/-/postcss-value-parser-4.2.0.tgz#723c09920836ba6d3e5af019f92bc0971c02e514"
integrity sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ==

postcss@^8.4.31:
Expand All @@ -2203,7 +2203,7 @@ prelude-ls@^1.2.1:

prettier@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.1.0.tgz#c6d16474a5f764ea1a4a373c593b779697744d5e"
resolved "https://mirrors.huaweicloud.com/repository/npm/prettier/-/prettier-3.1.0.tgz#c6d16474a5f764ea1a4a373c593b779697744d5e"
integrity sha512-TQLvXjq5IAibjh8EpBIkNKxO749UEWABoiIZehEPiY4GNpVdhaFKqSTu+QrlU6D2dPAfubRmtJTi4K4YkQ5eXw==

[email protected], prop-types@^15.7.2, prop-types@^15.8.1:
Expand Down Expand Up @@ -2442,7 +2442,7 @@ set-function-name@^2.0.0:

shallowequal@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/shallowequal/-/shallowequal-1.1.0.tgz#188d521de95b9087404fd4dcb68b13df0ae4e7f8"
resolved "https://mirrors.huaweicloud.com/repository/npm/shallowequal/-/shallowequal-1.1.0.tgz#188d521de95b9087404fd4dcb68b13df0ae4e7f8"
integrity sha512-y0m1JoUZSlPAjXVtPPW70aZWfIL/dSP7AFkRnniLCrK/8MDKog3TySTBmckD+RObVxH0v4Tox67+F14PdED2oQ==

shebang-command@^2.0.0:
Expand Down Expand Up @@ -2522,7 +2522,7 @@ strip-json-comments@^3.1.1:

styled-components@^6.1.1:
version "6.1.1"
resolved "https://registry.yarnpkg.com/styled-components/-/styled-components-6.1.1.tgz#a5414ada07fb1c17b96a26a05369daa4e2ad55e5"
resolved "https://mirrors.huaweicloud.com/repository/npm/styled-components/-/styled-components-6.1.1.tgz#a5414ada07fb1c17b96a26a05369daa4e2ad55e5"
integrity sha512-cpZZP5RrKRIClBW5Eby4JM1wElLVP4NQrJbJ0h10TidTyJf4SIIwa3zLXOoPb4gJi8MsJ8mjq5mu2IrEhZIAcQ==
dependencies:
"@emotion/is-prop-valid" "^1.2.1"
Expand All @@ -2537,7 +2537,7 @@ styled-components@^6.1.1:

stylis@^4.3.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/stylis/-/stylis-4.3.0.tgz#abe305a669fc3d8777e10eefcfc73ad861c5588c"
resolved "https://mirrors.huaweicloud.com/repository/npm/stylis/-/stylis-4.3.0.tgz#abe305a669fc3d8777e10eefcfc73ad861c5588c"
integrity sha512-E87pIogpwUsUwXw7dNyU4QDjdgVMy52m+XEOPEKUn161cCzWjjhPSQhByfd1CcNvrOLnXQ6OnnZDwnJrz/Z4YQ==

supports-color@^5.3.0:
Expand Down
16 changes: 13 additions & 3 deletions neetbox/history/_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,19 @@ def write_blob(self, table_name, json_data, blob_data, timestamp=None):
_, lastrowid = self._execute(sql_query, _timestamp, json_data, blob_data)
return lastrowid

def read(self, table_name: str, condition: QueryCondition = None):
def read_json(self, table_name: str, condition: QueryCondition = None):
return self.read(table_name, ("id", "timestamp", "data"), condition)

def read_blob(self, table_name: str, condition: QueryCondition = None, meta_only=False):
return self.read(
table_name,
("id", "timestamp", "json", *(("data",) if not meta_only else ())),
condition,
)

def read(self, table_name: str, columns: Tuple[str], condition: QueryCondition = None):
condition = condition.dumps() if condition else ""
sql_query = f"SELECT id, timestamp, data FROM {table_name} {condition}"
sql_query = f"SELECT {', '.join(columns)} FROM {table_name} {condition}"
result, _ = self._execute(sql_query, fetch=FetchType.ALL)
return result

Expand All @@ -192,7 +202,7 @@ def read(self, table_name: str, condition: QueryCondition = None):
"uploadInterval": 10,
},
)
for item in conn.read(
for item in conn.read_json(
table_name="test_log",
condition=QueryCondition(
timestamp_range=(datetime.now() - timedelta(days=1)).strftime(DATETIME_FORMAT)
Expand Down
Loading

0 comments on commit 8ec94e6

Please sign in to comment.