|
@ -1,4 +1,5 @@ |
|
|
import { rejects } from "node:assert"; |
|
|
import { rejects } from "node:assert"; |
|
|
|
|
|
import { resolve } from "node:dns"; |
|
|
import { ImageInfo } from "../core/ImageInfo"; |
|
|
import { ImageInfo } from "../core/ImageInfo"; |
|
|
|
|
|
|
|
|
export class HttpRequest { |
|
|
export class HttpRequest { |
|
@ -67,7 +68,7 @@ export class HttpRequest { |
|
|
let xhr: XMLHttpRequest = new XMLHttpRequest(); |
|
|
let xhr: XMLHttpRequest = new XMLHttpRequest(); |
|
|
xhr.responseType = "arraybuffer"; |
|
|
xhr.responseType = "arraybuffer"; |
|
|
xhr.onreadystatechange = (ev: Event): any => { |
|
|
xhr.onreadystatechange = (ev: Event): any => { |
|
|
if (xhr.readyState === 4 && xhr.status === 2000) { |
|
|
|
|
|
|
|
|
if (xhr.readyState === 4 && xhr.status === 200) { |
|
|
resolve(xhr.response as ArrayBuffer); |
|
|
resolve(xhr.response as ArrayBuffer); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -75,4 +76,23 @@ export class HttpRequest { |
|
|
xhr.send(); |
|
|
xhr.send(); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* |
|
|
|
|
|
* @param url |
|
|
|
|
|
* @returns |
|
|
|
|
|
*/ |
|
|
|
|
|
public static loadImg(url: string): Promise<Blob>{ |
|
|
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
|
|
let xhr: XMLHttpRequest = new XMLHttpRequest(); |
|
|
|
|
|
xhr.responseType = "blob"; |
|
|
|
|
|
xhr.onreadystatechange = (e: Event): any => { |
|
|
|
|
|
if(xhr.readyState === 4 && xhr.status === 200){ |
|
|
|
|
|
resolve(xhr.response); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
xhr.open('GET', url); |
|
|
|
|
|
xhr.send(); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
} |
|
|
} |