fix: discriminate execute apps by component
This commit is contained in:
@@ -3290,6 +3290,8 @@ paths:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
component:
|
||||
type: string
|
||||
#script: script/<path>
|
||||
#flow: flow/<path>
|
||||
path:
|
||||
@@ -3311,6 +3313,7 @@ paths:
|
||||
type: object
|
||||
required:
|
||||
- args
|
||||
- component
|
||||
|
||||
responses:
|
||||
"200":
|
||||
|
||||
@@ -667,6 +667,7 @@ pub struct ExecuteApp {
|
||||
// - script: script/<path>
|
||||
// - flow: flow/<path>
|
||||
pub path: Option<String>,
|
||||
pub component: String,
|
||||
pub raw_code: Option<RawCode>,
|
||||
// if set, the app is executed as viewer with the given static fields
|
||||
pub force_viewer_static_fields: Option<StaticFields>,
|
||||
@@ -705,11 +706,16 @@ async fn execute_component(
|
||||
|
||||
let policy = if let Some(static_fields) = payload.clone().force_viewer_static_fields {
|
||||
let mut hm = HashMap::new();
|
||||
|
||||
if let Some(path) = payload.path.clone() {
|
||||
hm.insert(path, static_fields);
|
||||
hm.insert(format!("{}:{path}", payload.component), static_fields);
|
||||
} else {
|
||||
hm.insert(
|
||||
digest(payload.raw_code.clone().unwrap().content.as_str()),
|
||||
format!(
|
||||
"{}:{}",
|
||||
payload.component,
|
||||
digest(payload.raw_code.clone().unwrap().content.as_str())
|
||||
),
|
||||
static_fields,
|
||||
);
|
||||
}
|
||||
@@ -761,14 +767,14 @@ async fn execute_component(
|
||||
};
|
||||
|
||||
let (job_payload, args, tag) = match &payload {
|
||||
ExecuteApp { args, raw_code: Some(raw_code), path: None, .. } => {
|
||||
ExecuteApp { args, component, raw_code: Some(raw_code), path: None, .. } => {
|
||||
let content = &raw_code.content;
|
||||
let payload = JobPayload::Code(raw_code.clone());
|
||||
let path = digest(content);
|
||||
let args = build_args(policy, path, args)?;
|
||||
let args = build_args(policy, component, path, args)?;
|
||||
(payload, args, None)
|
||||
}
|
||||
ExecuteApp { args, raw_code: None, path: Some(path), .. } => {
|
||||
ExecuteApp { args, component, raw_code: None, path: Some(path), .. } => {
|
||||
let (payload, tag) = if path.starts_with("script/") {
|
||||
script_path_to_payload(
|
||||
path.strip_prefix("script/").unwrap(),
|
||||
@@ -787,7 +793,7 @@ async fn execute_component(
|
||||
path
|
||||
)));
|
||||
};
|
||||
let args = build_args(policy, path.to_string(), args)?;
|
||||
let args = build_args(policy, component, path.to_string(), args)?;
|
||||
(payload, args, tag)
|
||||
}
|
||||
_ => unreachable!(),
|
||||
@@ -860,15 +866,18 @@ async fn exists_app(
|
||||
|
||||
fn build_args(
|
||||
policy: Policy,
|
||||
component: &str,
|
||||
path: String,
|
||||
args: &Map<String, Value>,
|
||||
) -> Result<Map<String, Value>> {
|
||||
// disallow var and res access in args coming from the user for security reasons
|
||||
args.into_iter()
|
||||
.try_for_each(|x| disallow_var_res_access(x.1))?;
|
||||
let key = format!("{}:{}", component, &path);
|
||||
let static_args = policy
|
||||
.triggerables
|
||||
.get(&path)
|
||||
.get(&key)
|
||||
.or_else(|| policy.triggerables.get(&path))
|
||||
.map(|x| x.clone())
|
||||
.or_else(|| {
|
||||
if matches!(policy.execution_mode, ExecutionMode::Viewer) {
|
||||
|
||||
@@ -29,6 +29,7 @@ pub enum FavoriteKind {
|
||||
Script,
|
||||
Flow,
|
||||
App,
|
||||
#[allow(non_camel_case_types)]
|
||||
Raw_App,
|
||||
}
|
||||
#[derive(Deserialize)]
|
||||
|
||||
@@ -229,6 +229,7 @@
|
||||
|
||||
const requestBody = {
|
||||
args: nonStaticRunnableInputs,
|
||||
component: id,
|
||||
force_viewer_static_fields: !isEditor ? undefined : staticRunnableInputs
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
import SettingsPanel from './SettingsPanel.svelte'
|
||||
import { secondaryMenu, SecondaryMenu } from './settingsPanel/secondaryMenu'
|
||||
import Popover from '../../Popover.svelte'
|
||||
import { migrateApp } from '../utils'
|
||||
import { BG_PREFIX, migrateApp } from '../utils'
|
||||
|
||||
export let app: App
|
||||
export let path: string
|
||||
@@ -148,7 +148,7 @@
|
||||
selectedTab = 'settings'
|
||||
|
||||
if (befSelected) {
|
||||
if (!['ctx', 'state'].includes(befSelected) && !befSelected?.startsWith('bg_')) {
|
||||
if (!['ctx', 'state'].includes(befSelected) && !befSelected?.startsWith(BG_PREFIX)) {
|
||||
let item = findGridItem($appStore, befSelected)
|
||||
if (item?.data.type === 'containercomponent') {
|
||||
$focusedGrid = {
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
UserAppInput
|
||||
} from '../inputType'
|
||||
import type { AppEditorContext, AppViewerContext } from '../types'
|
||||
import { allItems, toStatic } from '../utils'
|
||||
import { BG_PREFIX, allItems, toStatic } from '../utils'
|
||||
import AppExportButton from './AppExportButton.svelte'
|
||||
import AppInputs from './AppInputs.svelte'
|
||||
import type { AppComponent } from './component/components'
|
||||
@@ -139,16 +139,17 @@
|
||||
if (c.type === 'tablecomponent') {
|
||||
r.push(...c.actionButtons.map((x) => x.componentInput))
|
||||
}
|
||||
return r.filter((x) => x)
|
||||
})
|
||||
.map(async (input) => {
|
||||
if (input?.type == 'runnable') {
|
||||
return await processRunnable(input.runnable, input.fields)
|
||||
}
|
||||
return r
|
||||
.filter((x) => x)
|
||||
.map(async (input) => {
|
||||
if (input?.type == 'runnable') {
|
||||
return await processRunnable(x.id, input.runnable, input.fields)
|
||||
}
|
||||
})
|
||||
})
|
||||
.concat(
|
||||
Object.values($app.hiddenInlineScripts ?? {}).map(async (v) => {
|
||||
return await processRunnable(v, v.fields)
|
||||
Object.values($app.hiddenInlineScripts ?? {}).map(async (v, i) => {
|
||||
return await processRunnable(BG_PREFIX + i, v, v.fields)
|
||||
})
|
||||
)
|
||||
)) as ([string, Record<string, any>] | undefined)[]
|
||||
@@ -158,16 +159,17 @@
|
||||
}
|
||||
|
||||
async function processRunnable(
|
||||
id: string,
|
||||
runnable: Runnable,
|
||||
fields: Record<string, any>
|
||||
): Promise<[string, Record<string, any>] | undefined> {
|
||||
const staticInputs = collectStaticFields(fields)
|
||||
if (runnable?.type == 'runnableByName') {
|
||||
let hex = await hash(runnable.inlineScript?.content)
|
||||
return [`rawscript/${hex}`, staticInputs]
|
||||
return [`${id}:rawscript/${hex}`, staticInputs]
|
||||
} else if (runnable?.type == 'runnableByPath') {
|
||||
let prefix = runnable.runType !== 'hubscript' ? runnable.runType : 'script'
|
||||
return [`${prefix}/${runnable.path}`, staticInputs]
|
||||
return [`${id}:${prefix}/${runnable.path}`, staticInputs]
|
||||
}
|
||||
}
|
||||
async function createApp(path: string) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import Toggle from '$lib/components/Toggle.svelte'
|
||||
import { getContext } from 'svelte'
|
||||
import type { AppViewerContext } from '../types'
|
||||
import { allItems } from '../utils'
|
||||
import { BG_PREFIX, allItems } from '../utils'
|
||||
import AppComponentInput from './AppComponentInput.svelte'
|
||||
import InputsSpecsEditor from './settingsPanel/InputsSpecsEditor.svelte'
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
<span class="text-sm text-gray-600">No resource input</span>
|
||||
{:else}
|
||||
<InputsSpecsEditor
|
||||
id={`bg_${index}`}
|
||||
id={BG_PREFIX + index}
|
||||
shouldCapitalize={false}
|
||||
bind:inputSpecs={script.fields}
|
||||
userInputEnabled={false}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
import { HiddenComponent } from '../components'
|
||||
import { deepEqual } from 'fast-equals'
|
||||
import { dfs } from './appUtils'
|
||||
import { migrateApp } from '../utils'
|
||||
import { BG_PREFIX, migrateApp } from '../utils'
|
||||
|
||||
export let app: App
|
||||
export let appPath: string
|
||||
@@ -168,7 +168,7 @@
|
||||
{#if app.hiddenInlineScripts}
|
||||
{#each app.hiddenInlineScripts as runnable, index}
|
||||
{#if runnable}
|
||||
<HiddenComponent id={`bg_${index}`} {runnable} />
|
||||
<HiddenComponent id={BG_PREFIX + index} {runnable} />
|
||||
{/if}
|
||||
{/each}
|
||||
{/if}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
import { classNames } from '$lib/utils'
|
||||
import Toggle from '$lib/components/Toggle.svelte'
|
||||
import Tooltip from '$lib/components/Tooltip.svelte'
|
||||
import { BG_PREFIX } from '../utils'
|
||||
|
||||
export let policy: Policy
|
||||
|
||||
@@ -129,7 +130,7 @@
|
||||
{#if $app.hiddenInlineScripts}
|
||||
{#each $app.hiddenInlineScripts as runnable, index}
|
||||
{#if runnable}
|
||||
<HiddenComponent id={`bg_${index}`} {runnable} />
|
||||
<HiddenComponent id={BG_PREFIX + index} {runnable} />
|
||||
{/if}
|
||||
{/each}
|
||||
{/if}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { getContext } from 'svelte'
|
||||
import type { App, AppViewerContext } from '../types'
|
||||
import { allItems } from '../utils'
|
||||
import { BG_PREFIX, allItems } from '../utils'
|
||||
import { findGridItem } from './appUtils'
|
||||
import PanelSection from './settingsPanel/common/PanelSection.svelte'
|
||||
import ComponentPanel from './settingsPanel/ComponentPanel.svelte'
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
$: hiddenInlineScript = $app?.hiddenInlineScripts
|
||||
?.map((x, i) => ({ script: x, index: i }))
|
||||
.find(({ script, index }) => $selectedComponent?.includes(`bg_${index}`))
|
||||
.find(({ script, index }) => $selectedComponent?.includes(BG_PREFIX + index))
|
||||
|
||||
$: componentSettings = findComponentSettings($app, $selectedComponent?.[0])
|
||||
$: tableActionSettings = findTableActionSettings($app, $selectedComponent?.[0])
|
||||
@@ -81,7 +81,7 @@
|
||||
/>
|
||||
{/key}
|
||||
{:else if hiddenInlineScript}
|
||||
{@const id = `bg_${hiddenInlineScript.index}`}
|
||||
{@const id = BG_PREFIX + hiddenInlineScript.index}
|
||||
<BackgroundScriptSettings bind:runnable={hiddenInlineScript.script} {id} />
|
||||
|
||||
<div class="mb-8">
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
import SubGridOutput from './SubGridOutput.svelte'
|
||||
import OutputHeader from './components/OutputHeader.svelte'
|
||||
import TableActionsOutput from './components/TableActionsOutput.svelte'
|
||||
import { BG_PREFIX } from '../../utils'
|
||||
|
||||
export let gridItem: GridItem
|
||||
export let first: boolean = false
|
||||
@@ -21,7 +22,7 @@
|
||||
return components[gridItem?.data.type].name
|
||||
} else if (componentId == 'ctx') {
|
||||
return 'Context'
|
||||
} else if (componentId.startsWith('bg_')) {
|
||||
} else if (componentId.startsWith(BG_PREFIX)) {
|
||||
return 'Background'
|
||||
} else {
|
||||
return 'Table action'
|
||||
|
||||
@@ -2,12 +2,13 @@
|
||||
import type { AppViewerContext } from '$lib/components/apps/types'
|
||||
import { getContext } from 'svelte'
|
||||
import BackgroundScriptOutput from './BackgroundScriptOutput.svelte'
|
||||
import { BG_PREFIX } from '$lib/components/apps/utils'
|
||||
|
||||
const { app } = getContext<AppViewerContext>('AppViewerContext')
|
||||
</script>
|
||||
|
||||
{#each $app.hiddenInlineScripts as action, index}
|
||||
{#if !action.hidden}
|
||||
<BackgroundScriptOutput id={`bg_${index}`} name={action.name} first={index === 0} />
|
||||
<BackgroundScriptOutput id={BG_PREFIX + index} name={action.name} first={index === 0} />
|
||||
{/if}
|
||||
{/each}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
import InlineScriptsPanelWithTable from './InlineScriptsPanelWithTable.svelte'
|
||||
import { findGridItem } from '../appUtils'
|
||||
import InlineScriptHiddenRunnable from './InlineScriptHiddenRunnable.svelte'
|
||||
import { BG_PREFIX } from '../../utils'
|
||||
|
||||
const { app, runnableComponents } = getContext<AppViewerContext>('AppViewerContext')
|
||||
const { selectedComponentInEditor } = getContext<AppEditorContext>('AppEditorContext')
|
||||
@@ -30,16 +31,16 @@
|
||||
}
|
||||
|
||||
$selectedComponentInEditor = undefined
|
||||
delete $runnableComponents[`bg_${index}`]
|
||||
delete $runnableComponents[BG_PREFIX + index]
|
||||
}
|
||||
|
||||
$: gridItem =
|
||||
$selectedComponentInEditor && !$selectedComponentInEditor.startsWith('bg_')
|
||||
$selectedComponentInEditor && !$selectedComponentInEditor.startsWith(BG_PREFIX)
|
||||
? findGridItem($app, $selectedComponentInEditor?.split('_')?.[0])
|
||||
: undefined
|
||||
|
||||
$: hiddenInlineScript = $app?.hiddenInlineScripts?.findIndex(
|
||||
(k_, index) => `bg_${index}` === $selectedComponentInEditor
|
||||
(k_, index) => BG_PREFIX + index === $selectedComponentInEditor
|
||||
)
|
||||
|
||||
$: unusedInlineScript = $app?.unusedInlineScripts?.findIndex(
|
||||
@@ -79,7 +80,7 @@
|
||||
{#if $app.hiddenInlineScripts?.[hiddenInlineScript]}
|
||||
<InlineScriptHiddenRunnable
|
||||
on:delete={() => deleteBackgroundScript(hiddenInlineScript)}
|
||||
id={`bg_${hiddenInlineScript}`}
|
||||
id={BG_PREFIX + hiddenInlineScript}
|
||||
bind:runnable={$app.hiddenInlineScripts[hiddenInlineScript]}
|
||||
/>{/if}{/key}
|
||||
{:else}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import { getContext } from 'svelte'
|
||||
import Tooltip from '../../../Tooltip.svelte'
|
||||
import type { AppEditorContext, AppViewerContext } from '../../types'
|
||||
import { getAllScriptNames } from '../../utils'
|
||||
import { BG_PREFIX, getAllScriptNames } from '../../utils'
|
||||
import PanelSection from '../settingsPanel/common/PanelSection.svelte'
|
||||
import { getAppScripts } from './utils'
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
function selectScript(id: string) {
|
||||
$selectedComponentInEditor = id
|
||||
if (!id.startsWith('unused-') || !id.startsWith('bg_')) {
|
||||
if (!id.startsWith('unused-') || !id.startsWith(BG_PREFIX)) {
|
||||
$selectedComponent = [$selectedComponentInEditor.split('_transformer')[0]]
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@
|
||||
if (script.hidden) {
|
||||
delete script.hidden
|
||||
$app.hiddenInlineScripts = $app.hiddenInlineScripts
|
||||
selectScript(`bg_${index}`)
|
||||
selectScript(BG_PREFIX + index)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -66,7 +66,7 @@
|
||||
recomputeIds: undefined
|
||||
})
|
||||
$app.hiddenInlineScripts = $app.hiddenInlineScripts
|
||||
selectScript(`bg_${$app.hiddenInlineScripts.length - 1}`)
|
||||
selectScript(`${BG_PREFIX}${$app.hiddenInlineScripts.length - 1}`)
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -181,7 +181,7 @@
|
||||
{#if $app.hiddenInlineScripts?.length > 0}
|
||||
{#each $app.hiddenInlineScripts as { name, hidden }, index (index)}
|
||||
{#if !hidden}
|
||||
{@const id = `bg_${index}`}
|
||||
{@const id = BG_PREFIX + index}
|
||||
<button
|
||||
id={PREFIX + id}
|
||||
class="panel-item
|
||||
|
||||
@@ -14,6 +14,8 @@ import type {
|
||||
VerticalAlignment
|
||||
} from './types'
|
||||
|
||||
export const BG_PREFIX = 'bg_'
|
||||
|
||||
export function migrateApp(app: App) {
|
||||
app.hiddenInlineScripts.forEach((x) => {
|
||||
if (x.type == undefined) {
|
||||
@@ -184,7 +186,7 @@ export function toStatic(
|
||||
})
|
||||
|
||||
newApp.hiddenInlineScripts?.forEach((x, i) => {
|
||||
x.noBackendValue = staticExporter[`bg_` + i]()
|
||||
x.noBackendValue = staticExporter[BG_PREFIX + i]()
|
||||
})
|
||||
|
||||
return { app: newApp, summary }
|
||||
|
||||
Reference in New Issue
Block a user