File tree Expand file tree Collapse file tree
services/image-split/tasks/download-split-canvas Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -91,7 +91,7 @@ function ImageSplitRoute(): React.ReactNode {
9191 DownloadSplitCanvasTasks (
9292 {
9393 ...data ,
94- filename : "tralala" ,
94+ filename : imageFile . file . name ,
9595 } ,
9696 imageFile
9797 )
Original file line number Diff line number Diff line change @@ -18,5 +18,6 @@ export default function DownloadSplitCanvasTasks(config: DownloadSplitCanvasConf
1818 Tasks . CreateCanvas ( ) ,
1919 Tasks . CreateAndZip ( { config, imageFile } ) ,
2020 Tasks . PackageZip ( ) ,
21+ Tasks . DownloadZip ( { config } ) ,
2122 ] ;
2223}
Original file line number Diff line number Diff line change 1+ import { createTask } from "@lilbunnyrabbit/task-manager" ;
2+ import { DownloadSplitCanvasConfig , DownloadSplitCanvasTask } from ".." ;
3+
4+ export default createTask < { config : DownloadSplitCanvasConfig } , string > ( {
5+ name : "Download ZIP" ,
6+
7+ parse ( ) {
8+ switch ( this . status ) {
9+ default :
10+ case "idle" : {
11+ return {
12+ status : "Download ZIP" ,
13+ } ;
14+ }
15+ case "in-progress" : {
16+ return {
17+ status : "Downloading..." ,
18+ } ;
19+ }
20+ case "error" : {
21+ return {
22+ status : "Failed to download..." ,
23+ } ;
24+ }
25+ case "success" : {
26+ if ( this . result . isPresent ( ) ) {
27+ return {
28+ status : "Downloaded" ,
29+ result : this . result . get ( ) ,
30+ } ;
31+ }
32+
33+ return {
34+ status : "No result." ,
35+ } ;
36+ }
37+ }
38+ } ,
39+
40+ async execute ( { config } ) {
41+ const blob = this . manager . getTaskResult ( DownloadSplitCanvasTask . PackageZip ) ;
42+
43+ const url = URL . createObjectURL ( blob ) ;
44+ const a = document . createElement ( "a" ) ;
45+ a . href = url ;
46+ a . download = `${ config . filename } .zip` ;
47+ document . body . appendChild ( a ) ;
48+ a . click ( ) ;
49+ document . body . removeChild ( a ) ;
50+
51+ return url ;
52+ } ,
53+ } ) ;
Original file line number Diff line number Diff line change 11export { default as CreateAndZip } from "./createAndZip.task" ;
22export { default as CreateCanvas } from "./createCanvas.task" ;
33export { default as CreateZip } from "./createZip.task" ;
4+ export { default as DownloadZip } from "./downloadZip.task" ;
45export { default as GenerateInfo } from "./generateInfo.task" ;
56export { default as PackageZip } from "./packageZip.task" ;
You can’t perform that action at this time.
0 commit comments