mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-25 16:02:11 +00:00
all
This commit is contained in:
@@ -1389,13 +1389,19 @@ async fn get_empty_ts_script_by_path() -> String {
|
||||
return String::new();
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct RawScriptByPathQuery {
|
||||
cache_key: Option<String>,
|
||||
}
|
||||
|
||||
async fn raw_script_by_path(
|
||||
authed: ApiAuthed,
|
||||
Extension(user_db): Extension<UserDB>,
|
||||
Extension(db): Extension<DB>,
|
||||
Path((w_id, path)): Path<(String, StripPath)>,
|
||||
Query(query): Query<RawScriptByPathQuery>,
|
||||
) -> Result<String> {
|
||||
raw_script_by_path_internal(path, user_db, db, authed, w_id, false).await
|
||||
raw_script_by_path_internal(path, user_db, db, authed, w_id, false, query.cache_key).await
|
||||
}
|
||||
|
||||
async fn raw_script_by_path_unpinned(
|
||||
@@ -1403,8 +1409,9 @@ async fn raw_script_by_path_unpinned(
|
||||
Extension(user_db): Extension<UserDB>,
|
||||
Extension(db): Extension<DB>,
|
||||
Path((w_id, path)): Path<(String, StripPath)>,
|
||||
Query(query): Query<RawScriptByPathQuery>,
|
||||
) -> Result<String> {
|
||||
raw_script_by_path_internal(path, user_db, db, authed, w_id, true).await
|
||||
raw_script_by_path_internal(path, user_db, db, authed, w_id, true, query.cache_key).await
|
||||
}
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
@@ -1419,6 +1426,7 @@ async fn raw_script_by_path_internal(
|
||||
authed: ApiAuthed,
|
||||
w_id: String,
|
||||
unpin: bool,
|
||||
cache_key: Option<String>,
|
||||
) -> Result<String> {
|
||||
let path = path.to_path();
|
||||
check_scopes(&authed, || format!("scripts:read:{}", path))?;
|
||||
|
||||
@@ -537,6 +537,48 @@ pub mod flow {
|
||||
}
|
||||
}
|
||||
|
||||
pub mod python_import_by_path {
|
||||
use super::*;
|
||||
use crate::DB;
|
||||
|
||||
#[derive(Eq, PartialEq, Debug, Hash, Clone)]
|
||||
pub struct ScriptPathWithCacheKey {
|
||||
pub path: String,
|
||||
pub cache_key: String,
|
||||
}
|
||||
|
||||
impl Item for ScriptPathWithCacheKey {
|
||||
fn path(&self, root: impl AsRef<Path>) -> PathBuf {
|
||||
root.as_ref()
|
||||
.join(self.path.clone())
|
||||
.join(self.cache_key.clone())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, Debug, Hash, Clone, Serialize, Deserialize)]
|
||||
pub struct ScriptContentOrPrefix {
|
||||
pub content: String,
|
||||
pub prefix: bool,
|
||||
}
|
||||
|
||||
make_static! {
|
||||
static ref CACHE: { ScriptPathWithCacheKey => ScriptContentOrPrefix } in "python_import_by_path" <= 1000;
|
||||
}
|
||||
|
||||
pub async fn fetch(
|
||||
db: &DB,
|
||||
path: &str,
|
||||
w_id: &str,
|
||||
cache_key: &str,
|
||||
) -> error::Result<ScriptContentOrPrefix> {
|
||||
let r =sqlx::query_scalar!(
|
||||
"SELECT content FROM script WHERE path = $1 AND workspace_id = $2 AND archived = false ORDER BY created_at DESC LIMIT 1",
|
||||
path,
|
||||
w_id
|
||||
).fetch_optional(db).await?;
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
pub mod script {
|
||||
use crate::{worker::Connection, DB};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user