mirror of
https://github.com/RuoJi6/ARTEX.git
synced 2026-10-31 18:23:50 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
542d7e9ca6 | ||
|
|
35a33b20f9 | ||
|
|
74d8b1efa2 | ||
|
|
92e58d3de7 | ||
|
|
21057b1a6b | ||
|
|
136782f48e | ||
|
|
3af131272c | ||
|
|
07c0c8ee35 | ||
|
|
3f2c44be91 | ||
|
|
57424249ce | ||
|
|
f48f4ec8e2 | ||
|
|
aac79d72e9 | ||
|
|
a55189a649 | ||
|
|
9745e7d019 | ||
|
|
af2f9e3560 |
No files matched your search
+62
-18
@@ -23,20 +23,21 @@ type DBFinding struct {
|
||||
ReportEvidenceVersion int64
|
||||
TrafficBindings []FindingTrafficBinding // populated only for export
|
||||
|
||||
ID int64
|
||||
TaskID *int64
|
||||
NodeID *int64
|
||||
VulnClass string
|
||||
Name string // 漏洞名称(可读标题);为空时前端回退展示 VulnClass
|
||||
Severity string
|
||||
Summary string
|
||||
Evidence string
|
||||
Worker string
|
||||
AssetIDs []int64
|
||||
Status string
|
||||
Report string // 详细报告(Markdown);仅 GetFinding 填充,列表查询不带
|
||||
CreatedAt time.Time
|
||||
TaskDescription string // populated via LEFT JOIN on tasks
|
||||
ID int64
|
||||
TaskID *int64
|
||||
NodeID *int64
|
||||
VulnClass string
|
||||
Name string // 漏洞名称(可读标题);为空时前端回退展示 VulnClass
|
||||
Severity string
|
||||
Summary string
|
||||
Evidence string
|
||||
Worker string
|
||||
AssetIDs []int64
|
||||
Status string
|
||||
Report string // 详细报告(Markdown);仅 GetFinding 填充,列表查询不带
|
||||
ReportConversationID *int64 `json:"report_conversation_id,omitempty"`
|
||||
CreatedAt time.Time
|
||||
TaskDescription string // populated via LEFT JOIN on tasks
|
||||
}
|
||||
|
||||
// Finding triage states (findings.status).
|
||||
@@ -106,9 +107,9 @@ func (d *DB) AddFinding(taskID, nodeID int64, vulnclass, name, severity, summary
|
||||
// findingSelectCols is the column list (with task_description join) every finding
|
||||
// list query selects, so scanFinding stays in sync across callers.
|
||||
const findingSelectCols = `f.id, f.task_id, f.node_id, f.vulnclass, COALESCE(f.name, ''), f.severity, f.summary,
|
||||
f.evidence, f.worker, f.asset_ids, COALESCE(f.status, 'pending'), f.created_at,
|
||||
f.evidence, f.worker, f.asset_ids, COALESCE(f.status, 'pending'), f.created_at,
|
||||
COALESCE(t.description, '') AS task_description, f.evidence_version, f.report_evidence_version,
|
||||
(SELECT count(*) FROM finding_traffic_bindings b WHERE b.finding_id=f.id)`
|
||||
(SELECT count(*) FROM finding_traffic_bindings b WHERE b.finding_id=f.id)`
|
||||
|
||||
// scanFindings materializes rows selected via findingSelectCols.
|
||||
func scanFindings(rows interface {
|
||||
@@ -661,13 +662,14 @@ func (d *DB) FindingStats() (*FindingStats, error) {
|
||||
func (d *DB) GetFinding(id int64) (*DBFinding, error) {
|
||||
f := &DBFinding{}
|
||||
var aidsJSON string
|
||||
err := d.QueryRow(`SELECT `+findingSelectCols+`, COALESCE(f.report, '')
|
||||
var reportConv sql.NullInt64
|
||||
err := d.QueryRow(`SELECT `+findingSelectCols+`, COALESCE(f.report, ''), f.report_conversation_id
|
||||
FROM findings f
|
||||
LEFT JOIN tasks t ON f.task_id = t.id
|
||||
WHERE f.id = $1`, id).Scan(
|
||||
&f.ID, &f.TaskID, &f.NodeID, &f.VulnClass, &f.Name, &f.Severity,
|
||||
&f.Summary, &f.Evidence, &f.Worker, &aidsJSON, &f.Status, &f.CreatedAt,
|
||||
&f.TaskDescription, &f.EvidenceVersion, &f.ReportEvidenceVersion, &f.TrafficCount, &f.Report)
|
||||
&f.TaskDescription, &f.EvidenceVersion, &f.ReportEvidenceVersion, &f.TrafficCount, &f.Report, &reportConv)
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil
|
||||
}
|
||||
@@ -675,9 +677,51 @@ func (d *DB) GetFinding(id int64) (*DBFinding, error) {
|
||||
return nil, err
|
||||
}
|
||||
_ = json.Unmarshal([]byte(aidsJSON), &f.AssetIDs)
|
||||
if reportConv.Valid {
|
||||
f.ReportConversationID = &reportConv.Int64
|
||||
}
|
||||
if f.ReportConversationID == nil && strings.TrimSpace(f.Report) != "" {
|
||||
if resolved, resolveErr := d.ResolveFindingReportConversation(f.ID); resolveErr == nil {
|
||||
f.ReportConversationID = resolved
|
||||
}
|
||||
}
|
||||
return f, nil
|
||||
}
|
||||
|
||||
func (d *DB) SetFindingReportConversationID(findingID, conversationID int64) error {
|
||||
_, err := d.Exec(`UPDATE findings SET report_conversation_id=$2 WHERE id=$1`, findingID, conversationID)
|
||||
return err
|
||||
}
|
||||
|
||||
// ResolveFindingReportConversation backfills links for reports generated before
|
||||
// report_conversation_id was persisted.
|
||||
func (d *DB) ResolveFindingReportConversation(findingID int64) (*int64, error) {
|
||||
var id int64
|
||||
err := d.QueryRow(`SELECT c.id FROM conversations c
|
||||
JOIN conversation_activities a ON a.conversation_id=c.id
|
||||
WHERE c.agent_key='reporter' AND (
|
||||
c.title = '漏洞报告 · finding#' || $1::text OR
|
||||
c.title ILIKE '%finding#' || $1::text || '%' OR
|
||||
a.detail ILIKE '%finding_id=' || $1::text || '%' OR
|
||||
a.detail ILIKE '%"finding_id":' || $1::text || '%'
|
||||
)
|
||||
ORDER BY CASE WHEN EXISTS (
|
||||
SELECT 1 FROM conversation_activities r
|
||||
WHERE r.conversation_id=c.id AND (r.tool='update_finding_report' OR r.summary ILIKE 'finding % report updated%')
|
||||
) THEN 0 ELSE 1 END,
|
||||
c.created_at ASC, c.id ASC LIMIT 1`, findingID).Scan(&id)
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := d.SetFindingReportConversationID(findingID, id); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &id, nil
|
||||
}
|
||||
|
||||
// DeleteFinding removes a finding entirely: the standalone findings row and its
|
||||
// originating exploration node (kind='finding'), so it disappears from the findings
|
||||
// list, the per-task 发现 Tab, and the exploration graph alike. Deleting the node
|
||||
|
||||
@@ -1162,11 +1162,13 @@ CREATE TABLE IF NOT EXISTS findings (
|
||||
status TEXT NOT NULL DEFAULT 'pending',
|
||||
-- 漏洞详细报告(Markdown);默认空,仅详情页读取/展示,不进列表接口以免 payload 膨胀。
|
||||
report TEXT NOT NULL DEFAULT '',
|
||||
report_conversation_id BIGINT REFERENCES conversations(id) ON DELETE SET NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||
);
|
||||
ALTER TABLE findings ADD COLUMN IF NOT EXISTS status TEXT NOT NULL DEFAULT 'pending';
|
||||
ALTER TABLE findings ADD COLUMN IF NOT EXISTS name TEXT NOT NULL DEFAULT '';
|
||||
ALTER TABLE findings ADD COLUMN IF NOT EXISTS report TEXT NOT NULL DEFAULT '';
|
||||
ALTER TABLE findings ADD COLUMN IF NOT EXISTS report_conversation_id BIGINT REFERENCES conversations(id) ON DELETE SET NULL;
|
||||
CREATE INDEX IF NOT EXISTS idx_findings_task ON findings(task_id, created_at DESC);
|
||||
CREATE INDEX IF NOT EXISTS idx_findings_time ON findings(created_at DESC);
|
||||
CREATE INDEX IF NOT EXISTS idx_findings_status ON findings(status, created_at DESC);
|
||||
|
||||
@@ -701,6 +701,14 @@ func (s *Server) readTriggerBehavior(agentKey string) triggerBehavior {
|
||||
// merging by task / all / none); parallel → run each fire in its own concurrent
|
||||
// conversation up to trigger_max_parallel. Distinct agents always run concurrently.
|
||||
func (s *Server) StartTriggeredRun(agentKey, title, message string, taskID int64, mergeable bool, taskDesc, taskGoal string) {
|
||||
s.startTriggeredRun(agentKey, title, message, taskID, mergeable, taskDesc, taskGoal, 0)
|
||||
}
|
||||
|
||||
func (s *Server) StartTriggeredRunWithConversation(agentKey, title, message string, taskID int64, mergeable bool, taskDesc, taskGoal string, conversationID int64) {
|
||||
s.startTriggeredRun(agentKey, title, message, taskID, mergeable, taskDesc, taskGoal, conversationID)
|
||||
}
|
||||
|
||||
func (s *Server) startTriggeredRun(agentKey, title, message string, taskID int64, mergeable bool, taskDesc, taskGoal string, conversationID int64) {
|
||||
if s.m.pg == nil || s.chatAgentRef() == nil {
|
||||
return
|
||||
}
|
||||
@@ -714,7 +722,7 @@ func (s *Server) StartTriggeredRun(agentKey, title, message string, taskID int64
|
||||
cfg := s.readTriggerBehavior(agentKey) // DB read BEFORE the lock (never under queueMu)
|
||||
s.queueMu.Lock()
|
||||
s.triggerCfg[agentKey] = cfg
|
||||
s.triggerQ[agentKey] = append(s.triggerQ[agentKey], triggeredRun{agentKey: agentKey, title: title, message: message, taskID: taskID, taskDesc: taskDesc, taskGoal: taskGoal, mergeable: mergeable})
|
||||
s.triggerQ[agentKey] = append(s.triggerQ[agentKey], triggeredRun{conversationID: conversationID, agentKey: agentKey, title: title, message: message, taskID: taskID, taskDesc: taskDesc, taskGoal: taskGoal, mergeable: mergeable})
|
||||
s.pumpLocked(agentKey)
|
||||
s.queueMu.Unlock()
|
||||
}
|
||||
|
||||
+19
-17
@@ -325,15 +325,16 @@ type FindingDTO struct {
|
||||
ReportStale bool `json:"report_stale"`
|
||||
TrafficBindings []db.FindingTrafficBinding `json:"traffic_bindings,omitempty"`
|
||||
|
||||
ID string `json:"id"`
|
||||
FindingID string `json:"finding_id,omitempty"` // standalone findings-table id — the handle for status updates
|
||||
VulnClass string `json:"vulnclass"`
|
||||
Name string `json:"name,omitempty"` // 漏洞名称;为空时前端回退展示 vulnclass
|
||||
Severity string `json:"severity"` // critical | high | medium | low
|
||||
Status string `json:"status"` // pending | in_progress | confirmed | resolved | fixed | false_positive | ignored | duplicate | risk_accepted
|
||||
Summary string `json:"summary"`
|
||||
Evidence string `json:"evidence"`
|
||||
Report string `json:"report,omitempty"` // 详细报告(Markdown);仅详情接口返回,列表为空
|
||||
ID string `json:"id"`
|
||||
FindingID string `json:"finding_id,omitempty"` // standalone findings-table id — the handle for status updates
|
||||
VulnClass string `json:"vulnclass"`
|
||||
Name string `json:"name,omitempty"` // 漏洞名称;为空时前端回退展示 vulnclass
|
||||
Severity string `json:"severity"` // critical | high | medium | low
|
||||
Status string `json:"status"` // pending | in_progress | confirmed | resolved | fixed | false_positive | ignored | duplicate | risk_accepted
|
||||
Summary string `json:"summary"`
|
||||
Evidence string `json:"evidence"`
|
||||
Report string `json:"report,omitempty"` // 详细报告(Markdown);仅详情接口返回,列表为空
|
||||
ReportConversationID *int64 `json:"report_conversation_id,omitempty"`
|
||||
|
||||
IntentID string `json:"intent_id,omitempty"`
|
||||
ParamID string `json:"param_id,omitempty"`
|
||||
@@ -464,14 +465,15 @@ func findingFromDB(f *db.DBFinding, assets map[int64]*db.Asset) FindingDTO {
|
||||
FindingID: i64s(f.ID),
|
||||
TrafficCount: f.TrafficCount, EvidenceVersion: f.EvidenceVersion, ReportEvidenceVersion: f.ReportEvidenceVersion,
|
||||
ReportStale: f.Report != "" && f.EvidenceVersion != f.ReportEvidenceVersion, TrafficBindings: f.TrafficBindings,
|
||||
VulnClass: f.VulnClass,
|
||||
Name: f.Name,
|
||||
Severity: f.Severity,
|
||||
Status: status,
|
||||
Summary: f.Summary,
|
||||
Evidence: f.Evidence,
|
||||
Report: f.Report,
|
||||
TS: rfc3339(f.CreatedAt),
|
||||
VulnClass: f.VulnClass,
|
||||
Name: f.Name,
|
||||
Severity: f.Severity,
|
||||
Status: status,
|
||||
Summary: f.Summary,
|
||||
Evidence: f.Evidence,
|
||||
Report: f.Report,
|
||||
ReportConversationID: f.ReportConversationID,
|
||||
TS: rfc3339(f.CreatedAt),
|
||||
}
|
||||
if f.ExportCaseID > 0 {
|
||||
d.ID = "case:" + i64s(f.ExportCaseID)
|
||||
|
||||
@@ -58,20 +58,30 @@ func (s *Server) generateFindingReport(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
message := manualFindingReportMessage(f, taskID)
|
||||
s.StartTriggeredRun(
|
||||
conversation, err := s.m.pg.CreateConversation("reporter", fmt.Sprintf("漏洞报告 · finding#%d", f.ID), nil)
|
||||
if err != nil {
|
||||
writeErr(w, http.StatusInternalServerError, "创建报告对话失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
if err := s.m.pg.SetFindingReportConversationID(f.ID, conversation.ID); err != nil {
|
||||
writeErr(w, http.StatusInternalServerError, "关联报告对话失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
s.StartTriggeredRunWithConversation(
|
||||
"reporter",
|
||||
fmt.Sprintf("人工生成步骤与报告 · finding#%d", f.ID),
|
||||
message,
|
||||
taskID,
|
||||
false,
|
||||
taskDesc,
|
||||
taskGoal,
|
||||
taskGoal, conversation.ID,
|
||||
)
|
||||
writeJSON(w, http.StatusAccepted, map[string]any{
|
||||
"queued": true,
|
||||
"agent_key": "reporter",
|
||||
"finding_id": f.ID,
|
||||
"finding_node_id": *f.NodeID,
|
||||
"conversation_id": conversation.ID,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
|
||||
"github.com/Autumn-27/artex/agent"
|
||||
"github.com/Autumn-27/artex/db"
|
||||
"github.com/Autumn-27/artex/intercept"
|
||||
"github.com/Autumn-27/norma/permission"
|
||||
actool "github.com/Autumn-27/norma/tool"
|
||||
)
|
||||
@@ -479,6 +480,11 @@ func (s *Server) toolUpdateFindingReport() actool.CoreTool {
|
||||
return actool.Errorf("归档报告截图失败: " + err.Error()), nil
|
||||
}
|
||||
}
|
||||
if conversationID := intercept.ConvIDFromContext(ctx); conversationID > 0 {
|
||||
if err := s.m.pg.SetFindingReportConversationID(fid, conversationID); err != nil {
|
||||
return actool.Errorf("关联报告对话失败: " + err.Error()), nil
|
||||
}
|
||||
}
|
||||
}
|
||||
n, err := s.m.pg.SetFindingReportVersionByNodeID(ctx, nodeID, a.Report, a.EvidenceVersion)
|
||||
if err != nil {
|
||||
|
||||
+4
-1
@@ -2332,7 +2332,10 @@ func (s *Server) findingsExport(w http.ResponseWriter, r *http.Request) {
|
||||
stamp := now.Format("20060102-150405")
|
||||
setDownload := func(contentType, filename string) {
|
||||
w.Header().Set("Content-Type", contentType)
|
||||
w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, filename))
|
||||
// Keep an ASCII fallback for older clients and provide the real UTF-8
|
||||
// name through RFC 5987. Browsers otherwise commonly decode Chinese
|
||||
// names using the platform legacy code page.
|
||||
w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"; filename*=UTF-8''%s`, sanitizeFilename(filename), url.PathEscape(filename)))
|
||||
}
|
||||
|
||||
switch format {
|
||||
|
||||
@@ -424,6 +424,7 @@ function FindingDetailInner() {
|
||||
agentLabel="报告撰写 Agent"
|
||||
promptPlaceholder="描述要如何调整漏洞报告…"
|
||||
modal
|
||||
initialConversationId={finding.report_conversation_id}
|
||||
open={reportChatOpen}
|
||||
onOpenChange={setReportChatOpen}
|
||||
/>
|
||||
|
||||
@@ -26,6 +26,7 @@ export function FindingAutoChat({
|
||||
agentLabel = "Auto Agent",
|
||||
promptPlaceholder = "询问这个漏洞…",
|
||||
modal = false,
|
||||
initialConversationId,
|
||||
open,
|
||||
onOpenChange,
|
||||
}: {
|
||||
@@ -35,6 +36,7 @@ export function FindingAutoChat({
|
||||
agentLabel?: string;
|
||||
promptPlaceholder?: string;
|
||||
modal?: boolean;
|
||||
initialConversationId?: number;
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
}) {
|
||||
@@ -49,6 +51,7 @@ export function FindingAutoChat({
|
||||
const [historyOpen, setHistoryOpen] = React.useState(false);
|
||||
const [history, setHistory] = React.useState<Conversation[]>([]);
|
||||
const cursor = React.useRef(0);
|
||||
const chatViewportRef = React.useRef<HTMLDivElement | null>(null);
|
||||
const safeTitle = findingTitle.replace(/[\[\]\r\n]/g, " ").trim().slice(0, 100);
|
||||
const storageKey = `artex.finding.${agentKey}-conversation.${findingId}`;
|
||||
|
||||
@@ -70,7 +73,11 @@ export function FindingAutoChat({
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!open || conversation || manualEmpty) return;
|
||||
const storedID = Number(window.localStorage.getItem(storageKey));
|
||||
if (initialConversationId && initialConversationId > 0) {
|
||||
setConversation({ id: initialConversationId, agent_key: agentKey, title: `漏洞 #${findingId} · ${safeTitle}`, created_at: "", updated_at: "" });
|
||||
return;
|
||||
}
|
||||
const storedID = agentKey === "auto" ? Number(window.localStorage.getItem(storageKey)) : 0;
|
||||
if (Number.isSafeInteger(storedID) && storedID > 0) {
|
||||
setConversation({
|
||||
id: storedID,
|
||||
@@ -82,7 +89,7 @@ export function FindingAutoChat({
|
||||
return;
|
||||
}
|
||||
void createConversation();
|
||||
}, [conversation, createConversation, manualEmpty, open, safeTitle, storageKey]);
|
||||
}, [conversation, createConversation, initialConversationId, manualEmpty, open, safeTitle, storageKey]);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!historyOpen && !running) return;
|
||||
@@ -130,6 +137,18 @@ export function FindingAutoChat({
|
||||
};
|
||||
}, [conversation, open, storageKey]);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!open || !conversation || loading || !messages.length) return;
|
||||
const viewport = chatViewportRef.current;
|
||||
if (!viewport) return;
|
||||
const key = `artex.conversation-scroll.${conversation.id}`;
|
||||
const saved = window.sessionStorage.getItem(key);
|
||||
requestAnimationFrame(() => {
|
||||
if (saved != null) viewport.scrollTop = Number(saved) || 0;
|
||||
else viewport.scrollTop = viewport.scrollHeight;
|
||||
});
|
||||
}, [conversation, loading, messages.length, open]);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!open || !conversation || !running) return;
|
||||
let live = true;
|
||||
@@ -265,7 +284,13 @@ export function FindingAutoChat({
|
||||
<XIcon />
|
||||
</Button>
|
||||
</header>
|
||||
<div className="min-h-0 min-w-0 flex-1 overflow-x-hidden overflow-y-auto p-3">
|
||||
<div
|
||||
ref={chatViewportRef}
|
||||
onScroll={(event) => {
|
||||
if (conversation) window.sessionStorage.setItem(`artex.conversation-scroll.${conversation.id}`, String(event.currentTarget.scrollTop));
|
||||
}}
|
||||
className="min-h-0 min-w-0 flex-1 overflow-x-hidden overflow-y-auto p-3"
|
||||
>
|
||||
<div className="w-full min-w-0 max-w-full">
|
||||
{loading ? (
|
||||
<div className="flex items-center justify-center py-10 text-muted-foreground text-sm">
|
||||
|
||||
@@ -18,6 +18,8 @@ function AuthenticatedImage({
|
||||
const [captureTimestamp, setCaptureTimestamp] = React.useState<string | null>(null);
|
||||
const [zoomed, setZoomed] = React.useState(false);
|
||||
const [zoomScale, setZoomScale] = React.useState(1);
|
||||
const [pan, setPan] = React.useState({ x: 0, y: 0 });
|
||||
const dragRef = React.useRef<{ x: number; y: number; panX: number; panY: number } | null>(null);
|
||||
const imageSrc = typeof src === "string" ? src : undefined;
|
||||
|
||||
React.useEffect(() => {
|
||||
@@ -29,6 +31,7 @@ function AuthenticatedImage({
|
||||
setCaptureTimestamp(null);
|
||||
setZoomed(false);
|
||||
setZoomScale(1);
|
||||
setPan({ x: 0, y: 0 });
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
@@ -75,31 +78,55 @@ function AuthenticatedImage({
|
||||
onClick={() => renderedSrc && setZoomed(true)}
|
||||
aria-label="放大查看报告截图"
|
||||
>
|
||||
<img {...props} src={renderedSrc} alt={alt || "报告截图,点击放大"} />
|
||||
<img {...props} src={renderedSrc} alt={alt || "报告截图,点击放大"} draggable={false} onDragStart={(event) => event.preventDefault()} />
|
||||
{timestamp}
|
||||
</button>
|
||||
<Dialog
|
||||
open={zoomed}
|
||||
onOpenChange={(next) => {
|
||||
setZoomed(next);
|
||||
if (!next) setZoomScale(1);
|
||||
if (!next) {
|
||||
setZoomScale(1);
|
||||
setPan({ x: 0, y: 0 });
|
||||
}
|
||||
}}
|
||||
>
|
||||
<DialogContent
|
||||
showCloseButton
|
||||
className="flex max-h-[96dvh] max-w-[96vw] items-center justify-center overflow-hidden bg-black/85 p-3 backdrop-blur-sm sm:max-w-[96vw]"
|
||||
>
|
||||
<div className="relative flex max-h-[90dvh] max-w-full items-center justify-center overflow-auto">
|
||||
<div className="relative inline-block origin-center transition-transform duration-150" style={{ transform: `scale(${zoomScale})` }}>
|
||||
<div
|
||||
className="relative flex h-[90dvh] w-[90vw] max-w-full items-center justify-center overflow-hidden"
|
||||
onPointerDown={(event) => {
|
||||
if (zoomScale <= 1 || event.button !== 0) return;
|
||||
event.currentTarget.setPointerCapture(event.pointerId);
|
||||
dragRef.current = { x: event.clientX, y: event.clientY, panX: pan.x, panY: pan.y };
|
||||
}}
|
||||
onPointerMove={(event) => {
|
||||
const drag = dragRef.current;
|
||||
if (!drag) return;
|
||||
setPan({ x: drag.panX + event.clientX - drag.x, y: drag.panY + event.clientY - drag.y });
|
||||
}}
|
||||
onPointerUp={(event) => {
|
||||
dragRef.current = null;
|
||||
event.currentTarget.releasePointerCapture?.(event.pointerId);
|
||||
}}
|
||||
onPointerCancel={() => { dragRef.current = null; }}
|
||||
style={{ cursor: zoomScale > 1 ? (dragRef.current ? "grabbing" : "grab") : "default" }}
|
||||
>
|
||||
<div className="relative inline-block origin-center" style={{ transform: `translate(${pan.x}px, ${pan.y}px) scale(${zoomScale})` }}>
|
||||
<img
|
||||
src={renderedSrc}
|
||||
alt={alt || "报告截图"}
|
||||
draggable={false}
|
||||
onDragStart={(event) => event.preventDefault()}
|
||||
className="max-h-[90dvh] max-w-[90vw] rounded-md object-contain"
|
||||
/>
|
||||
{timestamp}
|
||||
</div>
|
||||
</div>
|
||||
<div className="absolute top-3 left-3 z-10 flex items-center gap-1 rounded-lg bg-black/60 p-1 backdrop-blur-sm">
|
||||
<span className="px-2 text-xs font-medium text-white tabular-nums">{Math.round(zoomScale * 100)}%</span>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
|
||||
+22
-3
@@ -119,6 +119,24 @@ import type {
|
||||
SystemMetrics,
|
||||
} from "@/lib/types";
|
||||
|
||||
/**
|
||||
* Read a download name from Content-Disposition. RFC 5987's filename* is
|
||||
* preferred because it preserves UTF-8 names; older filename remains the
|
||||
* fallback for clients that do not understand it.
|
||||
*/
|
||||
export function downloadFilename(contentDisposition: string, fallback: string): string {
|
||||
const encoded = contentDisposition.match(/(?:^|;)\s*filename\*\s*=\s*UTF-8''([^;]+)/i)?.[1];
|
||||
if (encoded) {
|
||||
try {
|
||||
return decodeURIComponent(encoded.replace(/^"|"$/g, ""));
|
||||
} catch {
|
||||
// Fall through to the legacy token when a malformed header is received.
|
||||
}
|
||||
}
|
||||
const legacy = contentDisposition.match(/(?:^|;)\s*filename\s*=\s*(?:"([^"]*)"|([^;\s]+))/i);
|
||||
return (legacy?.[1] ?? legacy?.[2] ?? fallback).trim() || fallback;
|
||||
}
|
||||
|
||||
function getToken(): string | null {
|
||||
if (typeof window === "undefined") return null;
|
||||
return localStorage.getItem("artex_token");
|
||||
@@ -534,6 +552,7 @@ export const api = {
|
||||
},
|
||||
workspaceDownload: async (path: string) => {
|
||||
let blob: Blob;
|
||||
let contentDisposition = "";
|
||||
if (MOCK) {
|
||||
blob = new Blob([`(demo)${path} 的下载内容示例。`], { type: "text/plain" });
|
||||
} else {
|
||||
@@ -542,12 +561,13 @@ export const api = {
|
||||
headers: { ...(token ? { Authorization: `Bearer ${token}` } : {}) },
|
||||
});
|
||||
if (!r.ok) throw new Error(`下载失败: ${r.status}`);
|
||||
contentDisposition = r.headers.get("Content-Disposition") ?? "";
|
||||
blob = await r.blob();
|
||||
}
|
||||
const objUrl = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.href = objUrl;
|
||||
a.download = path.split("/").pop() || "download";
|
||||
a.download = downloadFilename(contentDisposition, path.split("/").pop() || "download");
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
a.remove();
|
||||
@@ -703,8 +723,7 @@ export const api = {
|
||||
const blob = await r.blob();
|
||||
// 文件名优先取后端 Content-Disposition,取不到则用默认名。
|
||||
const disp = r.headers.get("Content-Disposition") ?? "";
|
||||
const m = disp.match(/filename="?([^"]+)"?/);
|
||||
const filename = m?.[1] ?? `findings-export`;
|
||||
const filename = downloadFilename(disp, `findings-export`);
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.href = url;
|
||||
|
||||
@@ -529,6 +529,7 @@ export interface Finding {
|
||||
summary: string;
|
||||
evidence: string;
|
||||
report?: string; // 详细报告(Markdown);仅详情接口返回,列表为空
|
||||
report_conversation_id?: number;
|
||||
intent_id?: string;
|
||||
param_id?: string;
|
||||
task_id?: string;
|
||||
|
||||
Reference in new issue
Block a user