@@ -5,9 +5,7 @@ import type {
55} from "../types/downloader" ;
66import { ApiError } from "./api" ;
77import { API_BASE as BASE } from "./env" ;
8- import { isIosDevice , isMobileDownloadDevice } from "./ios-device" ;
9-
10- let preparedIosWindow : Window | null = null ;
8+ import { isMobileDownloadDevice } from "./ios-device" ;
119
1210type ErrorBody = {
1311 error ?: string ;
@@ -52,41 +50,6 @@ export async function fetchDownloaderJob(jobId: string): Promise<DownloaderJobRe
5250 return body as DownloaderJobResponse ;
5351}
5452
55- export function prepareIosArtifactWindow ( ) {
56- if ( ! isIosDevice ( ) ) return ;
57- if ( preparedIosWindow && ! preparedIosWindow . closed ) return ;
58- const opened = window . open ( "about:blank" , "_blank" ) ;
59- if ( ! opened ) return ;
60- opened . document . title = "Preparing download" ;
61- preparedIosWindow = opened ;
62- }
63-
64- export function cancelPreparedIosArtifactWindow ( ) {
65- if ( ! preparedIosWindow || preparedIosWindow . closed ) {
66- preparedIosWindow = null ;
67- return ;
68- }
69- preparedIosWindow . close ( ) ;
70- preparedIosWindow = null ;
71- }
72-
73- function consumePreparedIosArtifactWindow ( ) : Window | null {
74- const target = preparedIosWindow ;
75- preparedIosWindow = null ;
76- if ( ! target || target . closed ) return null ;
77- return target ;
78- }
79-
80- function clickDownloadAnchor ( doc : Document , href : string ) {
81- const a = doc . createElement ( "a" ) ;
82- a . href = href ;
83- a . download = "" ;
84- a . rel = "noopener" ;
85- doc . body . appendChild ( a ) ;
86- a . click ( ) ;
87- doc . body . removeChild ( a ) ;
88- }
89-
9053function extensionFromType ( contentType : string | null ) : string {
9154 const value = contentType ?? "" ;
9255 if ( value . includes ( "video/mp4" ) ) return "mp4" ;
@@ -106,33 +69,8 @@ function filenameFromHeader(contentDisposition: string | null): string | null {
10669
10770export async function downloadDownloaderArtifact ( jobId : string ) : Promise < void > {
10871 const endpoint = `${ BASE } /downloader/jobs/${ encodeURIComponent ( jobId ) } /artifact` ;
109- if ( isIosDevice ( ) ) {
110- const target = consumePreparedIosArtifactWindow ( ) ;
111- if ( target ) {
112- try {
113- const doc = target . document ;
114- doc . open ( ) ;
115- doc . write (
116- "<!doctype html><html><head><title>Preparing download</title></head><body></body></html>" ,
117- ) ;
118- doc . close ( ) ;
119- clickDownloadAnchor ( doc , endpoint ) ;
120- return ;
121- } catch {
122- target . location . assign ( endpoint ) ;
123- return ;
124- }
125- }
126- try {
127- clickDownloadAnchor ( document , endpoint ) ;
128- return ;
129- } catch {
130- window . location . assign ( endpoint ) ;
131- return ;
132- }
133- }
13472 if ( isMobileDownloadDevice ( ) ) {
135- clickDownloadAnchor ( document , endpoint ) ;
73+ window . location . assign ( endpoint ) ;
13674 return ;
13775 }
13876 const res = await fetch ( endpoint ) ;
0 commit comments