From 7564901a84dfb6790e56a548a42bc49b4fd5d657 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Thu, 18 Aug 2022 22:18:57 +0200 Subject: [PATCH] use ts extension for private imports --- backend/src/scripts.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/backend/src/scripts.rs b/backend/src/scripts.rs index f9dabd6d44..c095ccdac8 100644 --- a/backend/src/scripts.rs +++ b/backend/src/scripts.rs @@ -544,7 +544,10 @@ async fn raw_script_by_path( Extension(user_db): Extension, Path((w_id, path)): Path<(String, StripPath)>, ) -> Result { - let path = path.to_path(); + let path = path + .to_path() + .strip_suffix(".ts") + .ok_or_else(|| Error::BadRequest("Raw script path must end with .ts".to_string()))?; let mut tx = user_db.begin(&authed).await?; let content_o = sqlx::query_scalar!( @@ -615,9 +618,12 @@ async fn get_script_by_hash( async fn raw_script_by_hash( authed: Authed, Extension(user_db): Extension, - Path((w_id, hash)): Path<(String, ScriptHash)>, + Path((w_id, hash_str)): Path<(String, String)>, ) -> Result { let mut tx = user_db.begin(&authed).await?; + let hash = ScriptHash(to_i64(hash_str.strip_suffix(".ts").ok_or_else(|| { + Error::BadRequest("Raw script path must end with .ts".to_string()) + })?)?); let r = get_script_by_hash_internal(&mut tx, &w_id, &hash).await?; tx.commit().await?;