Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
pre-commit-ci[bot] committed May 22, 2024
1 parent 66e7f83 commit b3b1d24
Showing 4 changed files with 27 additions and 26 deletions.
18 changes: 11 additions & 7 deletions pyflask/app.py
Original file line number Diff line number Diff line change
@@ -10,9 +10,8 @@
from os.path import isabs
from pathlib import Path
from signal import SIGINT
from urllib.parse import unquote

from typing import Union
from urllib.parse import unquote

# https://stackoverflow.com/questions/32672596/pyinstaller-loads-script-multiple-times#comment103216434_32677108
multiprocessing.freeze_support()
@@ -68,7 +67,10 @@
responses=server_error_responses(codes=[200, 400, 500]),
)
class Log(Resource):
@api.doc(description="Nicely format the exception and the payload that caused it.", responses=server_error_responses(codes=[200, 400, 404, 500]))
@api.doc(
description="Nicely format the exception and the payload that caused it.",
responses=server_error_responses(codes=[200, 400, 404, 500]),
)
@catch_exception_and_abort(api=api, code=500)
def post(self):
payload = api.payload
@@ -81,6 +83,7 @@ def post(self):
selected_logger = getattr(api.logger, type)
selected_logger(message)


# Used for the standalone preview page
@flask_app.route(rule="/files/<path:file_path>", methods=["GET", "POST"])
@api.doc(
@@ -104,16 +107,17 @@ def handle_file_request(file_path: str) -> Union[str, Response, None]:
return

if request.method == "GET":
parsed_file_path = unquote(file_path) # Decode any URL encoding applied to the file path
is_file_relative = not isabs(parsed_file_path) # Check if the file path is relative
parsed_file_path = unquote(file_path) # Decode any URL encoding applied to the file path
is_file_relative = not isabs(parsed_file_path) # Check if the file path is relative
if is_file_relative:
parsed_file_path = f"/{parsed_file_path}"
return send_file(path_or_file=parsed_file_path)

# Register access to the provided file path
elif request.method == "POST":
nwbfile_registry.append(file_path)
return request.base_url # Return the URL of the newly added file
return request.base_url # Return the URL of the newly added file


@flask_app.route("/cpus")
def get_cpu_count():
2 changes: 1 addition & 1 deletion pyflask/utils/_catch_flask_errors.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import contextlib
from typing import Dict, List, Union

import flask_restx
from typing import List, Union, Dict


def server_error_responses(*, codes: List[str]) -> Dict[int, str]:
2 changes: 0 additions & 2 deletions src/renderer/src/stories/pages/preview/PreviewPage.js
Original file line number Diff line number Diff line change
@@ -18,13 +18,11 @@ export class PreviewPage extends Page {

updatePath = async (path) => {
if (path) {

// Enable access to the explicit file path
const result = await fetch(`${baseUrl}/files/${path}`, { method: "POST" }).then((res) => res.text());

// Set Neurosift to access the returned URL
if (result) this.neurosift.url = result;

} else this.neurosift.url = undefined;
};

31 changes: 15 additions & 16 deletions src/renderer/src/stories/preview/NWBFilePreview.js
Original file line number Diff line number Diff line change
@@ -56,27 +56,26 @@ class NWBPreviewInstance extends LitElement {
render() {
const isOnline = navigator.onLine;

if (!isOnline) return until(
(async () => {
const htmlRep = await run("html", { nwbfile_path: this.file }, { swal: false });
return unsafeHTML(htmlRep);
})(),
html`<small>Loading HTML representation...</small>`
);
if (!isOnline)
return until(
(async () => {
const htmlRep = await run("html", { nwbfile_path: this.file }, { swal: false });
return unsafeHTML(htmlRep);
})(),
html`<small>Loading HTML representation...</small>`
);

const neurosift = new Neurosift({ fullscreen: false })
const neurosift = new Neurosift({ fullscreen: false });

// Enable access to the explicit file path
fetch(`${baseUrl}/files/${this.file}`, { method: "POST" })
.then((res) => res.text())
.then((result) => {
.then((res) => res.text())
.then((result) => {
// Set Neurosift to access the returned URL
if (result) neurosift.url = result;
});

// Set Neurosift to access the returned URL
if (result) neurosift.url = result;
})


return neurosift
return neurosift;
}
}

0 comments on commit b3b1d24

Please sign in to comment.