@@ -128,15 +128,12 @@ export const OperationViewer: ComponentType<{
128
128
)
129
129
}
130
130
131
- const handleCopyShortCode = ( ) => {
132
- if ( ! operation ?. id ) {
133
- AppToaster . show ( {
134
- message : '获取作业失败' ,
135
- intent : 'danger' ,
136
- } )
137
- return
138
- }
131
+ const operationDoc = useMemo (
132
+ ( ) => toCopilotOperation ( operation ) ,
133
+ [ operation ] ,
134
+ )
139
135
136
+ const handleCopyShortCode = ( ) => {
140
137
const shortCode = toShortCode ( operation . id )
141
138
navigator . clipboard . writeText ( shortCode )
142
139
@@ -147,22 +144,15 @@ export const OperationViewer: ComponentType<{
147
144
}
148
145
149
146
const handleDownloadJSON = ( ) => {
150
- const content = operation ?. content
151
- if ( ! content ) {
152
- AppToaster . show ( {
153
- message : '获取作业失败' ,
154
- intent : 'danger' ,
155
- } )
156
- return
157
- }
158
-
159
- const blob = new Blob ( [ content ] , {
147
+ // pretty print the JSON
148
+ const json = JSON . stringify ( operationDoc , null , 2 )
149
+ const blob = new Blob ( [ json ] , {
160
150
type : 'application/json' ,
161
151
} )
162
152
const url = URL . createObjectURL ( blob )
163
153
const link = document . createElement ( 'a' )
164
154
link . href = url
165
- link . download = `MAACopilot_作业 ${ operation . id } .json`
155
+ link . download = `MAACopilot_ ${ operationDoc . doc . title } .json`
166
156
link . click ( )
167
157
URL . revokeObjectURL ( url )
168
158
@@ -187,11 +177,6 @@ export const OperationViewer: ComponentType<{
187
177
) . catch ( noop )
188
178
}
189
179
190
- const operationDoc = useMemo (
191
- ( ) => toCopilotOperation ( operation ) ,
192
- [ operation ] ,
193
- )
194
-
195
180
return (
196
181
< OperationDrawer
197
182
title = {
0 commit comments