feat: add mounted web ui shells
这个提交存在于:
父节点
7c41348939
当前提交
5888e3b4fd
共有 23 个文件被更改,包括 2469 次插入 和 40 次删除
4
.gitignore
Vendored
4
.gitignore
Vendored
|
|
@ -31,10 +31,6 @@ data/exports/*
|
|||
!data/temp/.gitkeep
|
||||
!data/exports/.gitkeep
|
||||
|
||||
# Built static assets generated by frontend builds
|
||||
pages/imagestudio/assets/
|
||||
web/assets/
|
||||
|
||||
# Local machine/editor noise
|
||||
.env
|
||||
.env.*
|
||||
|
|
|
|||
|
|
@ -1 +1,14 @@
|
|||
"""AstrBot WebUI adapter placeholder."""
|
||||
"""AstrBot WebUI adapter helpers.
|
||||
|
||||
The actual AstrBot runtime performs route registration. This adapter keeps the
|
||||
ImageStudio mount contract in one place so the runtime layer can wire it
|
||||
without starting a standalone server.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from backend.services.web_hosting_service import WebHostingService
|
||||
|
||||
|
||||
def get_web_mount_manifest() -> dict:
|
||||
return WebHostingService().manifest()
|
||||
|
|
|
|||
23
backend/routes/web_routes.py
普通文件
23
backend/routes/web_routes.py
普通文件
|
|
@ -0,0 +1,23 @@
|
|||
"""Web UI route helpers."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from backend.routes.common import handle_request
|
||||
from backend.services.web_hosting_service import WebHostingService
|
||||
from core.identity import RequestContext
|
||||
from core.security import require_authenticated
|
||||
|
||||
|
||||
def get_web_manifest(
|
||||
ctx: RequestContext,
|
||||
service: WebHostingService | None = None,
|
||||
) -> dict:
|
||||
web_service = service or WebHostingService()
|
||||
|
||||
def action() -> dict[str, Any]:
|
||||
require_authenticated(ctx)
|
||||
return web_service.manifest()
|
||||
|
||||
return handle_request(ctx, action)
|
||||
|
|
@ -193,7 +193,12 @@ def _mask_sensitive(value: Any, path: str = "") -> Any:
|
|||
masked: dict[str, Any] = {}
|
||||
for key, child in value.items():
|
||||
child_path = f"{path}.{key}" if path else str(key)
|
||||
masked[str(key)] = "***MASKED***" if _is_sensitive_key(child_path) and child else _mask_sensitive(child, child_path)
|
||||
if _is_sensitive_key(child_path) and child:
|
||||
masked[str(key)] = "***MASKED***"
|
||||
elif _is_path_key(child_path) and _is_absolute_path_value(child):
|
||||
masked[str(key)] = "***PATH***"
|
||||
else:
|
||||
masked[str(key)] = _mask_sensitive(child, child_path)
|
||||
return masked
|
||||
if isinstance(value, list):
|
||||
return [_mask_sensitive(item, path) for item in value]
|
||||
|
|
@ -218,6 +223,15 @@ def _is_sensitive_key(path: str) -> bool:
|
|||
return any(part in lowered for part in SENSITIVE_KEY_PARTS)
|
||||
|
||||
|
||||
def _is_path_key(path: str) -> bool:
|
||||
lowered = path.lower()
|
||||
return lowered.endswith("_path") or lowered.endswith(".path")
|
||||
|
||||
|
||||
def _is_absolute_path_value(value: Any) -> bool:
|
||||
return isinstance(value, str) and Path(value).is_absolute()
|
||||
|
||||
|
||||
def _resolve_path(path: str | Path) -> Path:
|
||||
resolved = Path(path)
|
||||
if not resolved.is_absolute():
|
||||
|
|
|
|||
|
|
@ -0,0 +1,66 @@
|
|||
"""Web UI mount metadata and static asset resolution."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import mimetypes
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from backend.dto.common import ApiError, ErrorCode
|
||||
from database.db_helper import REPO_ROOT
|
||||
|
||||
|
||||
PLUGIN_PAGE_DIR = REPO_ROOT / "pages" / "imagestudio"
|
||||
STANDALONE_WEB_DIR = REPO_ROOT / "web"
|
||||
PLUGIN_PAGE_URL = "/plugin/imagestudio"
|
||||
STANDALONE_WEB_URL = "/api/v1/plugins/extensions/astrbot_plugin_imagestudio/web"
|
||||
|
||||
|
||||
class WebHostingService:
|
||||
def __init__(
|
||||
self,
|
||||
plugin_page_dir: Path = PLUGIN_PAGE_DIR,
|
||||
standalone_web_dir: Path = STANDALONE_WEB_DIR,
|
||||
):
|
||||
self.plugin_page_dir = plugin_page_dir
|
||||
self.standalone_web_dir = standalone_web_dir
|
||||
|
||||
def manifest(self) -> dict[str, Any]:
|
||||
return {
|
||||
"plugin_page": {
|
||||
"url": PLUGIN_PAGE_URL,
|
||||
"built": (self.plugin_page_dir / "index.html").exists(),
|
||||
},
|
||||
"standalone_web": {
|
||||
"url": STANDALONE_WEB_URL,
|
||||
"assets_url": f"{STANDALONE_WEB_URL}/assets",
|
||||
"built": (self.standalone_web_dir / "index.html").exists(),
|
||||
},
|
||||
}
|
||||
|
||||
def resolve_standalone_asset(self, relative_path: str = "index.html") -> dict[str, Any]:
|
||||
asset_path = self._resolve(self.standalone_web_dir, relative_path or "index.html")
|
||||
return _asset_metadata(asset_path)
|
||||
|
||||
def resolve_plugin_page_asset(self, relative_path: str = "index.html") -> dict[str, Any]:
|
||||
asset_path = self._resolve(self.plugin_page_dir, relative_path or "index.html")
|
||||
return _asset_metadata(asset_path)
|
||||
|
||||
def _resolve(self, root: Path, relative_path: str) -> Path:
|
||||
root = root.resolve()
|
||||
candidate = (root / relative_path).resolve()
|
||||
if candidate != root and root not in candidate.parents:
|
||||
raise ApiError(ErrorCode.FORBIDDEN, "web asset escapes its root", {"asset": relative_path})
|
||||
if candidate.is_dir():
|
||||
candidate = candidate / "index.html"
|
||||
if not candidate.exists() or not candidate.is_file():
|
||||
raise ApiError(ErrorCode.RESOURCE_NOT_FOUND, "web asset not built", {"asset": relative_path})
|
||||
return candidate
|
||||
|
||||
|
||||
def _asset_metadata(path: Path) -> dict[str, Any]:
|
||||
return {
|
||||
"content_type": mimetypes.guess_type(path.name)[0] or "application/octet-stream",
|
||||
"size_bytes": path.stat().st_size,
|
||||
"etag": f"{path.stat().st_mtime_ns:x}-{path.stat().st_size:x}",
|
||||
}
|
||||
1533
frontend/package-lock.json
自动生成
普通文件
1533
frontend/package-lock.json
自动生成
普通文件
文件差异内容过多而无法显示
加载差异
|
|
@ -1,7 +1,112 @@
|
|||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from "vue"
|
||||
import { endpoints } from "../../shared/api/endpoints"
|
||||
import { getJson } from "../../shared/api/client"
|
||||
import type { UiBootstrap } from "../../shared/types/bootstrap"
|
||||
import type { DashboardSummary } from "../../shared/types/dashboard"
|
||||
|
||||
const bootstrap = ref<UiBootstrap | null>(null)
|
||||
const dashboard = ref<DashboardSummary | null>(null)
|
||||
const loading = ref(true)
|
||||
const error = ref("")
|
||||
|
||||
const workbenchUrl = computed(() => `${bootstrap.value?.api_base ?? ""}/web`)
|
||||
const queueTotal = computed(() => {
|
||||
const queue = dashboard.value?.queue
|
||||
return queue ? queue.pending + queue.running + queue.failed + queue.dead_letter : 0
|
||||
})
|
||||
|
||||
onMounted(load)
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
error.value = ""
|
||||
try {
|
||||
const [bootstrapData, dashboardData] = await Promise.all([
|
||||
getJson<UiBootstrap>(endpoints.uiBootstrap),
|
||||
getJson<DashboardSummary>(endpoints.dashboardSummary),
|
||||
])
|
||||
bootstrap.value = bootstrapData
|
||||
dashboard.value = dashboardData
|
||||
} catch (err) {
|
||||
error.value = err instanceof Error ? err.message : "加载失败"
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function formatBytes(value = 0) {
|
||||
if (value < 1024) return `${value} B`
|
||||
if (value < 1024 * 1024) return `${(value / 1024).toFixed(1)} KB`
|
||||
if (value < 1024 * 1024 * 1024) return `${(value / 1024 / 1024).toFixed(1)} MB`
|
||||
return `${(value / 1024 / 1024 / 1024).toFixed(1)} GB`
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<main class="plugin-page-shell">
|
||||
<h1>ImageStudio</h1>
|
||||
<p>Plugin Page UI scaffold is ready.</p>
|
||||
<header class="topbar">
|
||||
<div>
|
||||
<h1>{{ bootstrap?.display_name ?? "ImageStudio" }}</h1>
|
||||
<p>{{ bootstrap?.dashboard_user ?? "AstrBot" }}</p>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<span class="status" :data-state="dashboard?.plugin_status ?? 'loading'">
|
||||
{{ dashboard?.plugin_status ?? "loading" }}
|
||||
</span>
|
||||
<button type="button" @click="load">刷新</button>
|
||||
<a v-if="bootstrap" class="primary" :href="workbenchUrl" target="_blank" rel="noreferrer">工作台</a>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<section v-if="error" class="notice">{{ error }}</section>
|
||||
<section v-else-if="loading" class="notice">加载中</section>
|
||||
|
||||
<section v-else class="metrics" aria-label="ImageStudio dashboard">
|
||||
<article>
|
||||
<span>角色</span>
|
||||
<strong>{{ dashboard?.active_profiles ?? 0 }}</strong>
|
||||
</article>
|
||||
<article>
|
||||
<span>队列</span>
|
||||
<strong>{{ queueTotal }}</strong>
|
||||
</article>
|
||||
<article>
|
||||
<span>运行中</span>
|
||||
<strong>{{ dashboard?.queue.running ?? 0 }}</strong>
|
||||
</article>
|
||||
<article>
|
||||
<span>失败</span>
|
||||
<strong>{{ dashboard?.queue.failed ?? 0 }}</strong>
|
||||
</article>
|
||||
<article>
|
||||
<span>存储</span>
|
||||
<strong>{{ formatBytes(dashboard?.storage.total_bytes) }}</strong>
|
||||
</article>
|
||||
</section>
|
||||
|
||||
<section class="activity">
|
||||
<div>
|
||||
<h2>最近图片</h2>
|
||||
<ul>
|
||||
<li v-for="image in dashboard?.recent_images ?? []" :key="String((image as any).image_id)">
|
||||
<span>{{ (image as any).image_id }}</span>
|
||||
<small>{{ (image as any).created_at }}</small>
|
||||
</li>
|
||||
<li v-if="!dashboard?.recent_images?.length" class="empty">暂无图片</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div>
|
||||
<h2>任务</h2>
|
||||
<ul>
|
||||
<li v-for="job in dashboard?.recent_jobs ?? []" :key="String((job as any).task_id)">
|
||||
<span>{{ (job as any).task_id }}</span>
|
||||
<small>{{ (job as any).status }}</small>
|
||||
</li>
|
||||
<li v-if="!dashboard?.recent_jobs?.length" class="empty">暂无任务</li>
|
||||
</ul>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
</template>
|
||||
|
||||
|
|
@ -10,20 +115,164 @@
|
|||
box-sizing: border-box;
|
||||
min-height: 100vh;
|
||||
padding: 24px;
|
||||
color: #1f2937;
|
||||
background: #f8fafc;
|
||||
color: #1d2430;
|
||||
background: #f4f6f8;
|
||||
font-family:
|
||||
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
||||
}
|
||||
|
||||
.topbar,
|
||||
.activity {
|
||||
display: grid;
|
||||
gap: 16px;
|
||||
grid-template-columns: minmax(0, 1fr) auto;
|
||||
align-items: start;
|
||||
}
|
||||
|
||||
h1,
|
||||
h2,
|
||||
p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin: 0 0 8px;
|
||||
font-size: 24px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
color: #64748b;
|
||||
h2 {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
p,
|
||||
small,
|
||||
.empty {
|
||||
color: #667085;
|
||||
}
|
||||
|
||||
.actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
button,
|
||||
a.primary {
|
||||
min-height: 36px;
|
||||
padding: 0 14px;
|
||||
border: 1px solid #c7d0da;
|
||||
border-radius: 6px;
|
||||
color: #1d2430;
|
||||
background: #ffffff;
|
||||
font: inherit;
|
||||
text-decoration: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
a.primary {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
border-color: #256f5b;
|
||||
color: #ffffff;
|
||||
background: #256f5b;
|
||||
}
|
||||
|
||||
.status {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
min-height: 28px;
|
||||
padding: 0 10px;
|
||||
border-radius: 999px;
|
||||
color: #245347;
|
||||
background: #dff3eb;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.status[data-state="loading"] {
|
||||
color: #6b4f1d;
|
||||
background: #f7e7c5;
|
||||
}
|
||||
|
||||
.notice {
|
||||
margin-top: 18px;
|
||||
padding: 14px;
|
||||
border: 1px solid #d6dde6;
|
||||
border-radius: 8px;
|
||||
background: #ffffff;
|
||||
}
|
||||
|
||||
.metrics {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(5, minmax(120px, 1fr));
|
||||
gap: 12px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
article,
|
||||
.activity > div {
|
||||
border: 1px solid #d6dde6;
|
||||
border-radius: 8px;
|
||||
background: #ffffff;
|
||||
}
|
||||
|
||||
article {
|
||||
display: grid;
|
||||
gap: 8px;
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
article span {
|
||||
color: #667085;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
article strong {
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.activity {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.activity > div {
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
ul {
|
||||
display: grid;
|
||||
gap: 10px;
|
||||
margin: 12px 0 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
li {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
li span,
|
||||
li small {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
@media (max-width: 820px) {
|
||||
.topbar,
|
||||
.activity {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.actions {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.metrics {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
|
|
|||
53
frontend/shared/api/client.ts
普通文件
53
frontend/shared/api/client.ts
普通文件
|
|
@ -0,0 +1,53 @@
|
|||
import { API_BASE } from "./endpoints"
|
||||
import type { ApiResponse } from "../types/api"
|
||||
|
||||
export class ApiClientError extends Error {
|
||||
readonly code: string
|
||||
readonly details: Record<string, unknown>
|
||||
|
||||
constructor(code: string, message: string, details: Record<string, unknown> = {}) {
|
||||
super(message)
|
||||
this.name = "ApiClientError"
|
||||
this.code = code
|
||||
this.details = details
|
||||
}
|
||||
}
|
||||
|
||||
export async function getJson<T>(endpoint: string, query?: Record<string, string | number | boolean | undefined>) {
|
||||
return request<T>(endpoint, { method: "GET", query })
|
||||
}
|
||||
|
||||
export async function postJson<T>(endpoint: string, body?: unknown) {
|
||||
return request<T>(endpoint, { method: "POST", body })
|
||||
}
|
||||
|
||||
export async function request<T>(
|
||||
endpoint: string,
|
||||
options: {
|
||||
method?: "GET" | "POST" | "PUT" | "DELETE"
|
||||
query?: Record<string, string | number | boolean | undefined>
|
||||
body?: unknown
|
||||
} = {},
|
||||
): Promise<T> {
|
||||
const response = await fetch(buildUrl(endpoint, options.query), {
|
||||
method: options.method ?? "GET",
|
||||
headers: options.body === undefined ? undefined : { "Content-Type": "application/json" },
|
||||
body: options.body === undefined ? undefined : JSON.stringify(options.body),
|
||||
})
|
||||
const payload = (await response.json()) as ApiResponse<T>
|
||||
if (!payload.ok) {
|
||||
throw new ApiClientError(payload.error_code, payload.message, payload.details)
|
||||
}
|
||||
return payload.data
|
||||
}
|
||||
|
||||
export function buildUrl(endpoint: string, query?: Record<string, string | number | boolean | undefined>) {
|
||||
const trimmed = endpoint.replace(/^\/+/, "")
|
||||
const url = new URL(`${API_BASE}/${trimmed}`, window.location.origin)
|
||||
for (const [key, value] of Object.entries(query ?? {})) {
|
||||
if (value !== undefined) {
|
||||
url.searchParams.set(key, String(value))
|
||||
}
|
||||
}
|
||||
return `${url.pathname}${url.search}`
|
||||
}
|
||||
|
|
@ -10,4 +10,5 @@ export const endpoints = {
|
|||
settingsCurrent: "settings/current",
|
||||
storageStatus: "storage/status",
|
||||
mediaSign: "media/sign",
|
||||
webManifest: "web/manifest",
|
||||
} as const
|
||||
|
|
|
|||
20
frontend/shared/types/job.ts
普通文件
20
frontend/shared/types/job.ts
普通文件
|
|
@ -0,0 +1,20 @@
|
|||
export interface GenerationJob {
|
||||
task_id: string
|
||||
profile_id?: string | null
|
||||
workflow_id?: string | null
|
||||
node_id?: string | null
|
||||
task_type: string
|
||||
status: string
|
||||
model_route?: string | null
|
||||
progress: number
|
||||
error_message?: string | null
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
export interface JobListResult {
|
||||
items: GenerationJob[]
|
||||
total: number
|
||||
page: number
|
||||
page_size: number
|
||||
}
|
||||
17
frontend/shared/types/profile.ts
普通文件
17
frontend/shared/types/profile.ts
普通文件
|
|
@ -0,0 +1,17 @@
|
|||
export interface CharacterProfile {
|
||||
profile_id: string
|
||||
name: string
|
||||
status: string
|
||||
avatar_image_uri?: string | null
|
||||
description?: string | null
|
||||
default_model_route?: string | null
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
export interface ProfileListResult {
|
||||
items: CharacterProfile[]
|
||||
total: number
|
||||
page: number
|
||||
page_size: number
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
export interface SettingsSchema {
|
||||
schema_version: string
|
||||
sections: Array<{
|
||||
key: string
|
||||
title: string
|
||||
fields: Array<{
|
||||
key: string
|
||||
type: string
|
||||
options: string[]
|
||||
sensitive: boolean
|
||||
readonly: boolean
|
||||
}>
|
||||
}>
|
||||
}
|
||||
|
||||
export interface CurrentSettings {
|
||||
config_path: string
|
||||
config: Record<string, unknown>
|
||||
}
|
||||
10
frontend/shared/types/storage.ts
普通文件
10
frontend/shared/types/storage.ts
普通文件
|
|
@ -0,0 +1,10 @@
|
|||
export interface StorageStatus {
|
||||
roots: Array<{
|
||||
root: string
|
||||
uri_prefix: string
|
||||
exists: boolean
|
||||
writable: boolean
|
||||
bytes: number
|
||||
}>
|
||||
total_bytes: number
|
||||
}
|
||||
|
|
@ -1,13 +1,182 @@
|
|||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from "vue"
|
||||
import { endpoints } from "../../shared/api/endpoints"
|
||||
import { getJson } from "../../shared/api/client"
|
||||
import type { UiBootstrap } from "../../shared/types/bootstrap"
|
||||
import type { DashboardSummary } from "../../shared/types/dashboard"
|
||||
import type { JobListResult } from "../../shared/types/job"
|
||||
import type { ProfileListResult } from "../../shared/types/profile"
|
||||
import type { CurrentSettings, SettingsSchema } from "../../shared/types/settings"
|
||||
import type { StorageStatus } from "../../shared/types/storage"
|
||||
|
||||
type ViewKey = "dashboard" | "profiles" | "jobs" | "settings"
|
||||
|
||||
const activeView = ref<ViewKey>("dashboard")
|
||||
const bootstrap = ref<UiBootstrap | null>(null)
|
||||
const dashboard = ref<DashboardSummary | null>(null)
|
||||
const profiles = ref<ProfileListResult | null>(null)
|
||||
const jobs = ref<JobListResult | null>(null)
|
||||
const settingsSchema = ref<SettingsSchema | null>(null)
|
||||
const currentSettings = ref<CurrentSettings | null>(null)
|
||||
const storage = ref<StorageStatus | null>(null)
|
||||
const loading = ref(true)
|
||||
const error = ref("")
|
||||
|
||||
const queueTotal = computed(() => {
|
||||
const queue = dashboard.value?.queue
|
||||
return queue ? queue.pending + queue.running + queue.failed + queue.dead_letter : 0
|
||||
})
|
||||
|
||||
onMounted(load)
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
error.value = ""
|
||||
try {
|
||||
const [bootstrapData, dashboardData, profileData, jobData, schemaData, settingsData, storageData] =
|
||||
await Promise.all([
|
||||
getJson<UiBootstrap>(endpoints.uiBootstrap),
|
||||
getJson<DashboardSummary>(endpoints.dashboardSummary),
|
||||
getJson<ProfileListResult>(endpoints.profiles, { page: 1, page_size: 20 }),
|
||||
getJson<JobListResult>(endpoints.jobs, { page: 1, page_size: 20 }),
|
||||
getJson<SettingsSchema>(endpoints.settingsSchema),
|
||||
getJson<CurrentSettings>(endpoints.settingsCurrent),
|
||||
getJson<StorageStatus>(endpoints.storageStatus),
|
||||
])
|
||||
bootstrap.value = bootstrapData
|
||||
dashboard.value = dashboardData
|
||||
profiles.value = profileData
|
||||
jobs.value = jobData
|
||||
settingsSchema.value = schemaData
|
||||
currentSettings.value = settingsData
|
||||
storage.value = storageData
|
||||
} catch (err) {
|
||||
error.value = err instanceof Error ? err.message : "加载失败"
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function formatBytes(value = 0) {
|
||||
if (value < 1024) return `${value} B`
|
||||
if (value < 1024 * 1024) return `${(value / 1024).toFixed(1)} KB`
|
||||
if (value < 1024 * 1024 * 1024) return `${(value / 1024 / 1024).toFixed(1)} MB`
|
||||
return `${(value / 1024 / 1024 / 1024).toFixed(1)} GB`
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<main class="web-shell">
|
||||
<aside class="sidebar">
|
||||
<strong>ImageStudio</strong>
|
||||
<span>Standalone Web UI</span>
|
||||
<div class="brand">
|
||||
<strong>{{ bootstrap?.display_name ?? "ImageStudio" }}</strong>
|
||||
<span>{{ bootstrap?.dashboard_user ?? "AstrBot" }}</span>
|
||||
</div>
|
||||
<nav>
|
||||
<button type="button" :class="{ active: activeView === 'dashboard' }" @click="activeView = 'dashboard'">
|
||||
概览
|
||||
</button>
|
||||
<button type="button" :class="{ active: activeView === 'profiles' }" @click="activeView = 'profiles'">
|
||||
角色
|
||||
</button>
|
||||
<button type="button" :class="{ active: activeView === 'jobs' }" @click="activeView = 'jobs'">
|
||||
队列
|
||||
</button>
|
||||
<button type="button" :class="{ active: activeView === 'settings' }" @click="activeView = 'settings'">
|
||||
设置
|
||||
</button>
|
||||
</nav>
|
||||
</aside>
|
||||
|
||||
<section class="workspace">
|
||||
<h1>Workspace Scaffold</h1>
|
||||
<p>The full AstrBot-mounted workbench starts here.</p>
|
||||
<header class="topbar">
|
||||
<div>
|
||||
<h1>{{ activeView === "dashboard" ? "ImageStudio" : "" }}</h1>
|
||||
<p>{{ dashboard?.plugin_status ?? "loading" }}</p>
|
||||
</div>
|
||||
<button type="button" @click="load">刷新</button>
|
||||
</header>
|
||||
|
||||
<section v-if="error" class="notice">{{ error }}</section>
|
||||
<section v-else-if="loading" class="notice">加载中</section>
|
||||
|
||||
<template v-else>
|
||||
<section v-if="activeView === 'dashboard'" class="dashboard-grid">
|
||||
<article>
|
||||
<span>角色</span>
|
||||
<strong>{{ dashboard?.active_profiles ?? 0 }}</strong>
|
||||
</article>
|
||||
<article>
|
||||
<span>队列</span>
|
||||
<strong>{{ queueTotal }}</strong>
|
||||
</article>
|
||||
<article>
|
||||
<span>存储</span>
|
||||
<strong>{{ formatBytes(storage?.total_bytes ?? dashboard?.storage.total_bytes) }}</strong>
|
||||
</article>
|
||||
<article>
|
||||
<span>图片</span>
|
||||
<strong>{{ dashboard?.recent_images.length ?? 0 }}</strong>
|
||||
</article>
|
||||
</section>
|
||||
|
||||
<section v-if="activeView === 'profiles'" class="list-view">
|
||||
<header>
|
||||
<h2>角色</h2>
|
||||
<span>{{ profiles?.total ?? 0 }}</span>
|
||||
</header>
|
||||
<ul>
|
||||
<li v-for="profile in profiles?.items ?? []" :key="profile.profile_id">
|
||||
<strong>{{ profile.name }}</strong>
|
||||
<span>{{ profile.status }}</span>
|
||||
</li>
|
||||
<li v-if="!profiles?.items.length" class="empty">暂无角色</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<section v-if="activeView === 'jobs'" class="list-view">
|
||||
<header>
|
||||
<h2>队列</h2>
|
||||
<span>{{ jobs?.total ?? 0 }}</span>
|
||||
</header>
|
||||
<ul>
|
||||
<li v-for="job in jobs?.items ?? []" :key="job.task_id">
|
||||
<strong>{{ job.task_id }}</strong>
|
||||
<span>{{ job.status }}</span>
|
||||
</li>
|
||||
<li v-if="!jobs?.items.length" class="empty">暂无任务</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<section v-if="activeView === 'settings'" class="settings-view">
|
||||
<div class="settings-sections">
|
||||
<article v-for="section in settingsSchema?.sections ?? []" :key="section.key">
|
||||
<h2>{{ section.title }}</h2>
|
||||
<span>{{ section.fields.length }}</span>
|
||||
</article>
|
||||
</div>
|
||||
<pre>{{ JSON.stringify(currentSettings?.config ?? {}, null, 2) }}</pre>
|
||||
</section>
|
||||
</template>
|
||||
</section>
|
||||
|
||||
<aside class="inspector">
|
||||
<h2>运行</h2>
|
||||
<dl>
|
||||
<div>
|
||||
<dt>Pending</dt>
|
||||
<dd>{{ dashboard?.queue.pending ?? 0 }}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>Running</dt>
|
||||
<dd>{{ dashboard?.queue.running ?? 0 }}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>Failed</dt>
|
||||
<dd>{{ dashboard?.queue.failed ?? 0 }}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</aside>
|
||||
</main>
|
||||
</template>
|
||||
|
||||
|
|
@ -15,43 +184,212 @@
|
|||
.web-shell {
|
||||
box-sizing: border-box;
|
||||
display: grid;
|
||||
grid-template-columns: 240px minmax(0, 1fr);
|
||||
grid-template-columns: 220px minmax(0, 1fr) 260px;
|
||||
min-height: 100vh;
|
||||
color: #172033;
|
||||
background: #f6f7f9;
|
||||
color: #1b2430;
|
||||
background: #f5f6f8;
|
||||
font-family:
|
||||
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
padding: 24px;
|
||||
border-right: 1px solid #d7dde6;
|
||||
.sidebar,
|
||||
.inspector {
|
||||
background: #ffffff;
|
||||
}
|
||||
|
||||
.sidebar strong {
|
||||
font-size: 18px;
|
||||
.sidebar {
|
||||
border-right: 1px solid #d9e0e8;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.sidebar span,
|
||||
.workspace p {
|
||||
color: #607086;
|
||||
.inspector {
|
||||
border-left: 1px solid #d9e0e8;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.brand {
|
||||
display: grid;
|
||||
gap: 4px;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.brand strong {
|
||||
font-size: 19px;
|
||||
}
|
||||
|
||||
.brand span,
|
||||
p,
|
||||
dt,
|
||||
.empty {
|
||||
color: #667085;
|
||||
}
|
||||
|
||||
nav {
|
||||
display: grid;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
button {
|
||||
min-height: 36px;
|
||||
border: 1px solid transparent;
|
||||
border-radius: 6px;
|
||||
color: #1b2430;
|
||||
background: transparent;
|
||||
font: inherit;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
nav button {
|
||||
padding: 0 10px;
|
||||
}
|
||||
|
||||
button.active {
|
||||
border-color: #b8d8cf;
|
||||
color: #164f43;
|
||||
background: #e5f4ef;
|
||||
}
|
||||
|
||||
.workspace {
|
||||
padding: 32px;
|
||||
min-width: 0;
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
.topbar {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.topbar button {
|
||||
padding: 0 14px;
|
||||
border-color: #c7d0da;
|
||||
background: #ffffff;
|
||||
}
|
||||
|
||||
h1,
|
||||
h2,
|
||||
p,
|
||||
dl,
|
||||
dd {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin: 0 0 8px;
|
||||
font-size: 28px;
|
||||
min-height: 30px;
|
||||
font-size: 26px;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
h2 {
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
.notice,
|
||||
article,
|
||||
.list-view,
|
||||
pre {
|
||||
border: 1px solid #d9e0e8;
|
||||
border-radius: 8px;
|
||||
background: #ffffff;
|
||||
}
|
||||
|
||||
.notice {
|
||||
margin-top: 18px;
|
||||
padding: 14px;
|
||||
}
|
||||
|
||||
.dashboard-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, minmax(130px, 1fr));
|
||||
gap: 12px;
|
||||
margin-top: 18px;
|
||||
}
|
||||
|
||||
article {
|
||||
display: grid;
|
||||
gap: 8px;
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
article span {
|
||||
color: #667085;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
article strong {
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.list-view,
|
||||
.settings-view {
|
||||
margin-top: 18px;
|
||||
}
|
||||
|
||||
.list-view {
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.list-view header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
ul {
|
||||
display: grid;
|
||||
gap: 10px;
|
||||
margin: 14px 0 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
li {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
li strong,
|
||||
li span {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.settings-sections {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, minmax(120px, 1fr));
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
pre {
|
||||
overflow: auto;
|
||||
max-height: 420px;
|
||||
margin: 12px 0 0;
|
||||
padding: 14px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
dl {
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
margin-top: 14px;
|
||||
}
|
||||
|
||||
dl div {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
@media (max-width: 1100px) {
|
||||
.web-shell {
|
||||
grid-template-columns: 190px minmax(0, 1fr);
|
||||
}
|
||||
|
||||
.inspector {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 760px) {
|
||||
|
|
@ -61,7 +399,20 @@ p {
|
|||
|
||||
.sidebar {
|
||||
border-right: 0;
|
||||
border-bottom: 1px solid #d7dde6;
|
||||
border-bottom: 1px solid #d9e0e8;
|
||||
}
|
||||
|
||||
nav {
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
nav button {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.dashboard-grid,
|
||||
.settings-sections {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
|
||||
文件差异因一行或多行过长而隐藏
|
|
@ -0,0 +1 @@
|
|||
.plugin-page-shell[data-v-7e06e9af]{box-sizing:border-box;min-height:100vh;padding:24px;color:#1d2430;background:#f4f6f8;font-family:Inter,ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,sans-serif}.topbar[data-v-7e06e9af],.activity[data-v-7e06e9af]{display:grid;gap:16px;grid-template-columns:minmax(0,1fr) auto;align-items:start}h1[data-v-7e06e9af],h2[data-v-7e06e9af],p[data-v-7e06e9af]{margin:0}h1[data-v-7e06e9af]{font-size:24px;font-weight:700}h2[data-v-7e06e9af]{font-size:14px}p[data-v-7e06e9af],small[data-v-7e06e9af],.empty[data-v-7e06e9af]{color:#667085}.actions[data-v-7e06e9af]{display:flex;gap:8px;align-items:center}button[data-v-7e06e9af],a.primary[data-v-7e06e9af]{min-height:36px;padding:0 14px;border:1px solid #c7d0da;border-radius:6px;color:#1d2430;background:#fff;font:inherit;text-decoration:none;cursor:pointer}a.primary[data-v-7e06e9af]{display:inline-flex;align-items:center;border-color:#256f5b;color:#fff;background:#256f5b}.status[data-v-7e06e9af]{display:inline-flex;align-items:center;min-height:28px;padding:0 10px;border-radius:999px;color:#245347;background:#dff3eb;font-size:13px}.status[data-state=loading][data-v-7e06e9af]{color:#6b4f1d;background:#f7e7c5}.notice[data-v-7e06e9af]{margin-top:18px;padding:14px;border:1px solid #d6dde6;border-radius:8px;background:#fff}.metrics[data-v-7e06e9af]{display:grid;grid-template-columns:repeat(5,minmax(120px,1fr));gap:12px;margin-top:20px}article[data-v-7e06e9af],.activity>div[data-v-7e06e9af]{border:1px solid #d6dde6;border-radius:8px;background:#fff}article[data-v-7e06e9af]{display:grid;gap:8px;padding:16px}article span[data-v-7e06e9af]{color:#667085;font-size:13px}article strong[data-v-7e06e9af]{font-size:24px}.activity[data-v-7e06e9af]{grid-template-columns:repeat(2,minmax(0,1fr));margin-top:16px}.activity>div[data-v-7e06e9af]{padding:16px}ul[data-v-7e06e9af]{display:grid;gap:10px;margin:12px 0 0;padding:0;list-style:none}li[data-v-7e06e9af]{display:flex;justify-content:space-between;gap:12px;min-width:0}li span[data-v-7e06e9af],li small[data-v-7e06e9af]{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}@media(max-width:820px){.topbar[data-v-7e06e9af],.activity[data-v-7e06e9af]{grid-template-columns:1fr}.actions[data-v-7e06e9af]{flex-wrap:wrap}.metrics[data-v-7e06e9af]{grid-template-columns:repeat(2,minmax(0,1fr))}}
|
||||
3
pages/imagestudio/index.html
普通文件
3
pages/imagestudio/index.html
普通文件
|
|
@ -0,0 +1,3 @@
|
|||
<script type="module" crossorigin src="/assets/index-DJoLO_ft.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/assets/index-KxvCyOGk.css">
|
||||
<div id="app"></div>
|
||||
|
|
@ -37,6 +37,7 @@ from backend.routes.settings_routes import (
|
|||
)
|
||||
from backend.routes.storage_routes import get_storage_status
|
||||
from backend.routes.ui_routes import get_ui_bootstrap
|
||||
from backend.routes.web_routes import get_web_manifest
|
||||
from backend.routes.workflow_routes import (
|
||||
archive_workflow,
|
||||
create_profile_workflow,
|
||||
|
|
@ -51,6 +52,7 @@ from backend.services.profile_service import ProfileService
|
|||
from backend.services.queue_service import QueueService
|
||||
from backend.services.settings_service import SettingsService
|
||||
from backend.services.ui_service import UiService
|
||||
from backend.services.web_hosting_service import WebHostingService
|
||||
from backend.services.workflow_service import WorkflowService
|
||||
from core.audit_service import AuditService
|
||||
from core.config_service import ConfigService
|
||||
|
|
@ -127,6 +129,7 @@ storage:
|
|||
)
|
||||
self.settings_service = SettingsService(self.config_service)
|
||||
self.media_service = MediaService(self.config_service)
|
||||
self.web_hosting_service = WebHostingService()
|
||||
self.ctx = RequestContext.from_astrbot(
|
||||
username="admin",
|
||||
user_id="user_001",
|
||||
|
|
@ -431,6 +434,15 @@ security:
|
|||
self.assertFalse(response["ok"])
|
||||
self.assertEqual(response["error_code"], "FORBIDDEN")
|
||||
|
||||
def test_settings_current_masks_absolute_paths(self):
|
||||
response = get_current_settings(self.ctx, self.settings_service)
|
||||
|
||||
self.assertTrue(response["ok"])
|
||||
storage = response["data"]["config"]["storage"]
|
||||
self.assertEqual(storage["images_path"], "***PATH***")
|
||||
self.assertEqual(storage["thumbnails_path"], "***PATH***")
|
||||
self.assertNotIn(str(self.root), str(response["data"]))
|
||||
|
||||
def test_storage_status_and_media_signing_do_not_expose_real_paths(self):
|
||||
response = get_storage_status(self.ctx, self.media_service)
|
||||
|
||||
|
|
@ -477,6 +489,18 @@ security:
|
|||
self.assertFalse(missing["ok"])
|
||||
self.assertEqual(missing["error_code"], "MEDIA_NOT_FOUND")
|
||||
|
||||
def test_web_manifest_returns_public_mounts_without_local_paths(self):
|
||||
response = get_web_manifest(self.ctx, self.web_hosting_service)
|
||||
|
||||
self.assertTrue(response["ok"])
|
||||
self.assertEqual(
|
||||
response["data"]["standalone_web"]["url"],
|
||||
"/api/v1/plugins/extensions/astrbot_plugin_imagestudio/web",
|
||||
)
|
||||
self.assertIn("built", response["data"]["plugin_page"])
|
||||
self.assertNotIn(str(self.root), str(response["data"]))
|
||||
self.assertNotIn("C:\\", str(response["data"]))
|
||||
|
||||
def test_workflow_node_image_routes_return_wrapped_responses(self):
|
||||
profile = self.profile_service.create_profile({"name": "Nova"}, self.ctx)
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
|
||||
17
web/assets/index-C821iZVM.js
普通文件
17
web/assets/index-C821iZVM.js
普通文件
文件差异因一行或多行过长而隐藏
|
|
@ -0,0 +1 @@
|
|||
.web-shell[data-v-34b16aee]{box-sizing:border-box;display:grid;grid-template-columns:220px minmax(0,1fr) 260px;min-height:100vh;color:#1b2430;background:#f5f6f8;font-family:Inter,ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,sans-serif}.sidebar[data-v-34b16aee],.inspector[data-v-34b16aee]{background:#fff}.sidebar[data-v-34b16aee]{border-right:1px solid #d9e0e8;padding:20px}.inspector[data-v-34b16aee]{border-left:1px solid #d9e0e8;padding:20px}.brand[data-v-34b16aee]{display:grid;gap:4px;margin-bottom:24px}.brand strong[data-v-34b16aee]{font-size:19px}.brand span[data-v-34b16aee],p[data-v-34b16aee],dt[data-v-34b16aee],.empty[data-v-34b16aee]{color:#667085}nav[data-v-34b16aee]{display:grid;gap:6px}button[data-v-34b16aee]{min-height:36px;border:1px solid transparent;border-radius:6px;color:#1b2430;background:transparent;font:inherit;text-align:left;cursor:pointer}nav button[data-v-34b16aee]{padding:0 10px}button.active[data-v-34b16aee]{border-color:#b8d8cf;color:#164f43;background:#e5f4ef}.workspace[data-v-34b16aee]{min-width:0;padding:24px}.topbar[data-v-34b16aee]{display:flex;justify-content:space-between;gap:16px;align-items:center}.topbar button[data-v-34b16aee]{padding:0 14px;border-color:#c7d0da;background:#fff}h1[data-v-34b16aee],h2[data-v-34b16aee],p[data-v-34b16aee],dl[data-v-34b16aee],dd[data-v-34b16aee]{margin:0}h1[data-v-34b16aee]{min-height:30px;font-size:26px}h2[data-v-34b16aee]{font-size:15px}.notice[data-v-34b16aee],article[data-v-34b16aee],.list-view[data-v-34b16aee],pre[data-v-34b16aee]{border:1px solid #d9e0e8;border-radius:8px;background:#fff}.notice[data-v-34b16aee]{margin-top:18px;padding:14px}.dashboard-grid[data-v-34b16aee]{display:grid;grid-template-columns:repeat(4,minmax(130px,1fr));gap:12px;margin-top:18px}article[data-v-34b16aee]{display:grid;gap:8px;padding:16px}article span[data-v-34b16aee]{color:#667085;font-size:13px}article strong[data-v-34b16aee]{font-size:24px}.list-view[data-v-34b16aee],.settings-view[data-v-34b16aee]{margin-top:18px}.list-view[data-v-34b16aee]{padding:16px}.list-view header[data-v-34b16aee]{display:flex;justify-content:space-between}ul[data-v-34b16aee]{display:grid;gap:10px;margin:14px 0 0;padding:0;list-style:none}li[data-v-34b16aee]{display:flex;justify-content:space-between;gap:12px;min-width:0}li strong[data-v-34b16aee],li span[data-v-34b16aee]{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.settings-sections[data-v-34b16aee]{display:grid;grid-template-columns:repeat(3,minmax(120px,1fr));gap:12px}pre[data-v-34b16aee]{overflow:auto;max-height:420px;margin:12px 0 0;padding:14px;font-size:12px}dl[data-v-34b16aee]{display:grid;gap:12px;margin-top:14px}dl div[data-v-34b16aee]{display:flex;justify-content:space-between}@media(max-width:1100px){.web-shell[data-v-34b16aee]{grid-template-columns:190px minmax(0,1fr)}.inspector[data-v-34b16aee]{display:none}}@media(max-width:760px){.web-shell[data-v-34b16aee]{grid-template-columns:1fr}.sidebar[data-v-34b16aee]{border-right:0;border-bottom:1px solid #d9e0e8}nav[data-v-34b16aee]{grid-template-columns:repeat(4,minmax(0,1fr))}nav button[data-v-34b16aee]{text-align:center}.dashboard-grid[data-v-34b16aee],.settings-sections[data-v-34b16aee]{grid-template-columns:1fr}}
|
||||
3
web/index.html
普通文件
3
web/index.html
普通文件
|
|
@ -0,0 +1,3 @@
|
|||
<script type="module" crossorigin src="/api/v1/plugins/extensions/astrbot_plugin_imagestudio/web/assets/index-C821iZVM.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/api/v1/plugins/extensions/astrbot_plugin_imagestudio/web/assets/index-DlB5CKB0.css">
|
||||
<div id="app"></div>
|
||||
正在加载…
添加表格
在新工单中引用