force raw path to ends with .py, .sh, .go, .ts

This commit is contained in:
Ruben Fiszel
2023-05-11 11:00:01 +02:00
parent 52e7e29a61
commit 56f4272a1b
2 changed files with 17 additions and 2 deletions
+16 -1
View File
@@ -600,7 +600,22 @@ async fn raw_script_by_path(
Extension(user_db): Extension<UserDB>,
Path((w_id, path)): Path<(String, StripPath)>,
) -> Result<String> {
let path = path.to_path().split(".").next().unwrap_or_default();
let path = path.to_path();
if !path.ends_with(".py")
&& !path.ends_with(".ts")
&& !path.ends_with(".go")
&& !path.ends_with(".sh")
{
return Err(Error::BadRequest(format!(
"Path must ends with a .py, .ts, .go. or .sh extension: {}",
path
)));
}
let path = path
.trim_end_matches(".py")
.trim_end_matches(".ts")
.trim_end_matches(".go")
.trim_end_matches(".sh");
let mut tx = user_db.begin(&authed).await?;
let content_o = sqlx::query_scalar!(
+1 -1
View File
@@ -30,7 +30,7 @@ class WindmillFinder(MetaPathFinder):
script_path = "/".join(splitted)
import requests
url = f"{os.environ.get('BASE_INTERNAL_URL')}/api/w/{os.environ.get('WM_WORKSPACE')}/scripts/raw/p/{script_path}"
url = f"{os.environ.get('BASE_INTERNAL_URL')}/api/w/{os.environ.get('WM_WORKSPACE')}/scripts/raw/p/{script_path}.py"
r = requests.get(
url, headers={"Authorization": f"Bearer {os.environ.get('WM_TOKEN')}"}