diff --git a/backend/windmill-api/openapi.yaml b/backend/windmill-api/openapi.yaml index 3ba08175a5..2eda57f7f2 100644 --- a/backend/windmill-api/openapi.yaml +++ b/backend/windmill-api/openapi.yaml @@ -13005,31 +13005,50 @@ paths: usage_kind: $ref: '#/components/schemas/AssetUsageKind' - /w/{workspace}/assets/list_for_usage: - get: - summary: List all assets used by a given usage path - operationId: listAssetsForUsage + /w/{workspace}/assets/list_by_usages: + post: + summary: List all assets used by given usages paths + operationId: listAssetsByUsage tags: - asset parameters: - $ref: '#/components/parameters/WorkspaceId' - - $ref: '#/components/parameters/AssetUsageKind' - - $ref: '#/components/parameters/AssetUsagePath' + requestBody: + description: list assets by usages + required: true + content: + application/json: + schema: + type: object + required: [usages] + properties: + usages: + type: array + items: + type: object + required: [usage_path, usage_kind] + properties: + usage_path: + type: string + usage_kind: + $ref: '#/components/schemas/AssetUsageKind' responses: '200': - description: all assets used by the given usage path + description: all assets used by the given usage paths, in the same order content: application/json: schema: type: array items: - type: object - required: [path, kind] - properties: - path: - type: string - kind: - $ref: '#/components/schemas/AssetKind' + type: array + items: + type: object + required: [path, kind] + properties: + path: + type: string + kind: + $ref: '#/components/schemas/AssetKind' components: securitySchemes: diff --git a/backend/windmill-api/src/assets.rs b/backend/windmill-api/src/assets.rs index 335483ca4b..954e3c978a 100644 --- a/backend/windmill-api/src/assets.rs +++ b/backend/windmill-api/src/assets.rs @@ -1,5 +1,5 @@ use axum::{ - extract::{Path, Query}, + extract::Path, routing::{get, post}, Extension, Json, Router, }; @@ -17,7 +17,7 @@ pub fn workspaced_service() -> Router { Router::new() .route("/link", post(link_assets)) .route("/list", get(list_assets)) - .route("/list_for_usage", get(list_assets_for_usage)) + .route("/list_by_usages", post(list_assets_by_usages)) } #[derive(Serialize, Deserialize, Debug, PartialEq, Copy, Clone, Hash, Eq, sqlx::Type)] @@ -42,6 +42,12 @@ pub struct Asset { pub kind: AssetKind, } +#[derive(Deserialize)] +struct Usage { + usage_kind: AssetUsageKind, + usage_path: String, +} + #[derive(Deserialize)] pub struct LinkAssetsBody { pub assets: Vec, @@ -117,31 +123,37 @@ async fn list_assets( } #[derive(Deserialize)] -struct ListAssetForUsageQuery { - usage_kind: AssetUsageKind, - usage_path: String, +struct ListAssetsByUsagesBody { + usages: Vec, } -async fn list_assets_for_usage( +async fn list_assets_by_usages( authed: ApiAuthed, Path(w_id): Path, - Query(ListAssetForUsageQuery { usage_kind, usage_path }): Query, Extension(user_db): Extension, -) -> JsonResult> { - let assets = sqlx::query_scalar!( - r#"SELECT - jsonb_build_object( - 'path', path, - 'kind', kind - ) as "list!: _" - FROM asset - WHERE workspace_id = $1 AND usage_path = $2 AND usage_kind = $3"#, - w_id, - usage_path, - usage_kind as AssetUsageKind - ) - .fetch_all(&mut *user_db.begin(&authed).await?) - .await?; + Json(body): Json, +) -> JsonResult>> { + let mut assets_vec = vec![]; - Ok(Json(assets)) + let mut tx = user_db.begin(&authed).await?; + + for usage in body.usages { + let assets = sqlx::query_scalar!( + r#"SELECT + jsonb_build_object( + 'path', path, + 'kind', kind + ) as "list!: _" + FROM asset + WHERE workspace_id = $1 AND usage_path = $2 AND usage_kind = $3"#, + w_id, + usage.usage_path, + usage.usage_kind as AssetUsageKind + ) + .fetch_all(&mut *tx) + .await?; + assets_vec.push(assets); + } + + Ok(Json(assets_vec)) } diff --git a/frontend/src/lib/components/flows/types.ts b/frontend/src/lib/components/flows/types.ts index 4d1e4d9c7a..d6bbcba798 100644 --- a/frontend/src/lib/components/flows/types.ts +++ b/frontend/src/lib/components/flows/types.ts @@ -86,7 +86,7 @@ export type FlowEditorContext = { export type FlowGraphAssetContext = StateStore<{ selectedAsset: Asset | undefined - assetsMap?: Record // Maps module ids to their assets + assetsMap: Record // Maps module ids to their assets s3FilePicker: S3FilePicker | undefined dbManagerDrawer: DbManagerDrawer | undefined resourceEditorDrawer: ResourceEditorDrawer | undefined diff --git a/frontend/src/lib/components/graph/FlowGraphV2.svelte b/frontend/src/lib/components/graph/FlowGraphV2.svelte index 58468e437c..5e5b5e4f74 100644 --- a/frontend/src/lib/components/graph/FlowGraphV2.svelte +++ b/frontend/src/lib/components/graph/FlowGraphV2.svelte @@ -1,5 +1,11 @@