()
| 371 | extension = "svg"; |
| 372 | |
| 373 | static init() { |
| 374 | // Override file handling to allow drag & drop of SVG |
| 375 | const handleFile = app.handleFile; |
| 376 | app.handleFile = async function (file) { |
| 377 | if (file && (file.type === "image/svg+xml" || file.name?.endsWith(".svg"))) { |
| 378 | const reader = new FileReader(); |
| 379 | reader.onload = () => { |
| 380 | // Extract embedded workflow from desc tags |
| 381 | const descEnd = reader.result.lastIndexOf("</desc>"); |
| 382 | if (descEnd !== -1) { |
| 383 | const descStart = reader.result.lastIndexOf("<desc>", descEnd); |
| 384 | if (descStart !== -1) { |
| 385 | const json = reader.result.substring(descStart + 6, descEnd); |
| 386 | this.loadGraphData(JSON.parse(SvgWorkflowImage.unescapeXml(json))); |
| 387 | } |
| 388 | } |
| 389 | }; |
| 390 | reader.readAsText(file); |
| 391 | return; |
| 392 | } else if (file && (file.type === "image/jpeg" || file.name?.endsWith(".jpg") || file.name?.endsWith(".jpeg"))) { |
| 393 | if ( |
| 394 | await new Promise((resolve) => { |
| 395 | try { |
| 396 | // This shouldnt go in here but it's easier than refactoring handleFile |
| 397 | const reader = new FileReader(); |
| 398 | reader.onload = async () => { |
| 399 | try { |
| 400 | const value = new Jpeg().readExif(reader.result); |
| 401 | importA1111(app.graph, value); |
| 402 | resolve(true); |
| 403 | } catch (error) { |
| 404 | resolve(false); |
| 405 | } |
| 406 | }; |
| 407 | reader.onerror = () => resolve(false); |
| 408 | reader.readAsArrayBuffer(file); |
| 409 | } catch (error) { |
| 410 | resolve(false); |
| 411 | } |
| 412 | }) |
| 413 | ) { |
| 414 | return; |
| 415 | } |
| 416 | } |
| 417 | return handleFile.apply(this, arguments); |
| 418 | }; |
| 419 | } |
| 420 | |
| 421 | static escapeXml(unsafe) { |
| 422 | return unsafe.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">"); |
nothing calls this directly
no test coverage detected