Skip to content

Commit

Permalink
feat: use full local paths (with python file name) as URL path
Browse files Browse the repository at this point in the history
  • Loading branch information
Yazawazi committed Oct 24, 2023
1 parent aa6e6bd commit 7336d09
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
7 changes: 4 additions & 3 deletions backend/funix/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,10 @@ def __prep(
path_difference: str | None = None
if base_dir:
# dir mode
path_difference = get_path_difference(
base_dir, sep.join(module_or_file.split(sep)[0:-1])
)
module = module_or_file.split(sep)
module[-1] = module[-1][:-3] # remove .py
module = sep.join(module)
path_difference = get_path_difference(base_dir, module)
if module_or_file:
if is_module:
module = import_module(module_or_file)
Expand Down
18 changes: 8 additions & 10 deletions backend/funix/decorator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,9 @@ def decorator(function: callable) -> callable:
# only when funix starts with `-R`, it will be not None

if safe_module_now:
unique_function_name = safe_module_now + "_AnD_" + function_name
unique_function_name = (
now_module.replace(".", "/") + "/" + function_name
)

if function_name in banned_function_name_and_path:
raise ValueError(
Expand Down Expand Up @@ -1212,6 +1214,7 @@ def parse_widget(widget_info: str | tuple | list) -> list[str] | str:
}

get_wrapper_id = app.get(f"/param/{function_id}")
get_wrapper_endpoint = app.get(f"/param/{endpoint}")

def decorated_function_param_getter():
"""
Expand Down Expand Up @@ -1260,13 +1263,11 @@ def decorated_function_param_getter():
)

get_wrapper_id(decorated_function_param_getter)

if not safe_module_now:
get_wrapper_endpoint = app.get(f"/param/{endpoint}")
get_wrapper_endpoint(decorated_function_param_getter)
get_wrapper_endpoint(decorated_function_param_getter)

if secret_key:
verify_secret_id = app.post(f"/verify/{function_id}")
verify_secret_endpoint = app.post(f"/verify/{endpoint}")

def verify_secret():
"""
Expand Down Expand Up @@ -1321,10 +1322,8 @@ def verify_secret():
verify_secret.__setattr__(
"__name__", decorated_function_verify_secret_name
)
if not safe_module_now:
verify_secret_endpoint = app.post(f"/verify/{endpoint}")
verify_secret_endpoint(verify_secret)

verify_secret_endpoint(verify_secret)
verify_secret_id(verify_secret)

@wraps(function)
Expand Down Expand Up @@ -1738,8 +1737,7 @@ def wrapped_function(**wrapped_function_kwargs):
if safe_module_now:
wrapper.__setattr__("__name__", safe_module_now + "_" + function_name)

if not safe_module_now:
app.post(f"/call/{endpoint}")(wrapper)
app.post(f"/call/{endpoint}")(wrapper)
app.post(f"/call/{function_id}")(wrapper)
return function

Expand Down
15 changes: 7 additions & 8 deletions frontend/src/components/FunixFunctionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,10 @@ const FunixFunctionList: React.FC<FunctionListProps> = ({ backend }) => {
};

useEffect(() => {
const pathParams = pathname.split("/").filter((value) => value !== "");
if (
pathParams.length !== 0 &&
state.length !== 0 &&
pathParams[0] !== radioGroupValue
) {
const functionPath = decodeURIComponent(pathParams[0]);
const pathParam = pathname.substring(1);
console.log(pathParam);
if (pathParam !== radioGroupValue) {
const functionPath = decodeURIComponent(pathParam);
const selectedFunctionPreview = state.filter(
(preview) => preview.path === functionPath
);
Expand Down Expand Up @@ -290,7 +287,9 @@ const FunixFunctionList: React.FC<FunctionListProps> = ({ backend }) => {
>
<ListItemText
primary={<MarkdownDiv markdown={k} isRenderInline={true} />}
disableTypography
sx={{
wordWrap: "break-word",
}}
/>
{treeState.hasOwnProperty(`${k}${v}`) ? (
treeState[`${k}${v}`] ? (
Expand Down

0 comments on commit 7336d09

Please sign in to comment.