|
@@ -1,4 +1,4 @@
|
|
|
-import { Show, createEffect, createSignal, onCleanup } from "solid-js"
|
|
|
|
|
|
|
+import { Show, createEffect, createSignal, onCleanup, onMount } from "solid-js"
|
|
|
import { Icon } from "@opencode-ai/ui/icon"
|
|
import { Icon } from "@opencode-ai/ui/icon"
|
|
|
import { usePlatform } from "@/context/platform"
|
|
import { usePlatform } from "@/context/platform"
|
|
|
import type { PaasPlatform, PaasPreviewContent } from "@/paas"
|
|
import type { PaasPlatform, PaasPreviewContent } from "@/paas"
|
|
@@ -28,6 +28,7 @@ export function PaasPreview(props: { api?: PaasPlatform; file?: PaasPreviewFile;
|
|
|
const platform = usePlatform()
|
|
const platform = usePlatform()
|
|
|
const [content, setContent] = createSignal<PaasPreviewContent>()
|
|
const [content, setContent] = createSignal<PaasPreviewContent>()
|
|
|
const [loading, setLoading] = createSignal(false)
|
|
const [loading, setLoading] = createSignal(false)
|
|
|
|
|
+ const [saving, setSaving] = createSignal(false)
|
|
|
const [error, setError] = createSignal("")
|
|
const [error, setError] = createSignal("")
|
|
|
const [url, setUrl] = createSignal("")
|
|
const [url, setUrl] = createSignal("")
|
|
|
let request = 0
|
|
let request = 0
|
|
@@ -98,6 +99,36 @@ export function PaasPreview(props: { api?: PaasPlatform; file?: PaasPreviewFile;
|
|
|
onCleanup(() => URL.revokeObjectURL(next))
|
|
onCleanup(() => URL.revokeObjectURL(next))
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
|
|
+ const save = async () => {
|
|
|
|
|
+ const target = file()
|
|
|
|
|
+ if (!target || !props.api) return
|
|
|
|
|
+ setSaving(true)
|
|
|
|
|
+ try {
|
|
|
|
|
+ await props.api.request({
|
|
|
|
|
+ action: "download",
|
|
|
|
|
+ agentID: target.agentID,
|
|
|
|
|
+ runID: target.runID,
|
|
|
|
|
+ name: target.name,
|
|
|
|
|
+ path: target.path,
|
|
|
|
|
+ artifactID: target.artifactID,
|
|
|
|
|
+ })
|
|
|
|
|
+ } catch (reason) {
|
|
|
|
|
+ setError(reason instanceof Error ? reason.message : "文件保存失败,请重试。")
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ setSaving(false)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ onMount(() => {
|
|
|
|
|
+ const close = (event: KeyboardEvent) => {
|
|
|
|
|
+ if (event.key !== "Escape") return
|
|
|
|
|
+ event.preventDefault()
|
|
|
|
|
+ props.onClose()
|
|
|
|
|
+ }
|
|
|
|
|
+ document.addEventListener("keydown", close)
|
|
|
|
|
+ onCleanup(() => document.removeEventListener("keydown", close))
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
return (
|
|
return (
|
|
|
<aside class="paas-preview" id="paas-preview" aria-label="右侧预览">
|
|
<aside class="paas-preview" id="paas-preview" aria-label="右侧预览">
|
|
|
<header class="paas-preview-header">
|
|
<header class="paas-preview-header">
|
|
@@ -105,15 +136,29 @@ export function PaasPreview(props: { api?: PaasPlatform; file?: PaasPreviewFile;
|
|
|
<strong>预览</strong>
|
|
<strong>预览</strong>
|
|
|
<span>{file()?.name || "文件"}</span>
|
|
<span>{file()?.name || "文件"}</span>
|
|
|
</div>
|
|
</div>
|
|
|
- <button
|
|
|
|
|
- type="button"
|
|
|
|
|
- class="paas-icon-action paas-preview-close"
|
|
|
|
|
- aria-label="关闭预览"
|
|
|
|
|
- title="关闭预览"
|
|
|
|
|
- onClick={() => props.onClose()}
|
|
|
|
|
- >
|
|
|
|
|
- <Icon name="close" size="small" />
|
|
|
|
|
- </button>
|
|
|
|
|
|
|
+ <div class="paas-preview-actions">
|
|
|
|
|
+ <Show when={file()}>
|
|
|
|
|
+ <button
|
|
|
|
|
+ type="button"
|
|
|
|
|
+ class="paas-preview-close"
|
|
|
|
|
+ aria-label="保存文件"
|
|
|
|
|
+ title="保存文件"
|
|
|
|
|
+ disabled={saving()}
|
|
|
|
|
+ onClick={() => void save()}
|
|
|
|
|
+ >
|
|
|
|
|
+ <Icon name="download" size="small" />
|
|
|
|
|
+ </button>
|
|
|
|
|
+ </Show>
|
|
|
|
|
+ <button
|
|
|
|
|
+ type="button"
|
|
|
|
|
+ class="paas-preview-close"
|
|
|
|
|
+ aria-label="关闭预览"
|
|
|
|
|
+ title="关闭预览"
|
|
|
|
|
+ onClick={() => props.onClose()}
|
|
|
|
|
+ >
|
|
|
|
|
+ <Icon name="close" size="small" />
|
|
|
|
|
+ </button>
|
|
|
|
|
+ </div>
|
|
|
</header>
|
|
</header>
|
|
|
<Show
|
|
<Show
|
|
|
when={file()}
|
|
when={file()}
|