Update website and send total=-1 when no content-type

This commit is contained in:
Jerome Wu
2022-10-05 17:51:09 +08:00
parent c9f20b8dc2
commit b8314a96e3
26 changed files with 193 additions and 66 deletions

View File

@@ -165,7 +165,7 @@ export class FFmpeg extends EventEmitter {
*/
public load = (config: FFMessageLoadConfig = {}): Promise<IsFirst> => {
if (!this.#worker) {
this.#worker = new Worker(new URL("./worker.ts", import.meta.url));
this.#worker = new Worker(new URL("./worker", import.meta.url));
this.#registerHandlers();
}
return this.#send({

View File

@@ -1,9 +1,6 @@
export const ERROR_RESPONSE_BODY_READER = new Error(
"failed to get response body reader"
);
export const ERROR_ZERO_CONTENT_LENGTH = new Error(
"failed to get Content-Length"
);
export const ERROR_UNKNOWN_MESSAGE_TYPE = new Error("unknown message type");
export const ERROR_NOT_LOADED = new Error(
"ffmpeg is not loaded, call `await ffmpeg.load()` first"

View File

@@ -1,6 +1,5 @@
import {
ERROR_RESPONSE_BODY_READER,
ERROR_ZERO_CONTENT_LENGTH,
ERROR_INCOMPLETED_DOWNLOAD,
} from "./errors";
import { HeaderContentLength } from "./const";
@@ -28,8 +27,8 @@ export const downloadWithProgress = async (
let buf;
try {
const total = parseInt(resp.headers.get(HeaderContentLength) || "0");
if (total === 0) throw ERROR_ZERO_CONTENT_LENGTH;
// Set total to -1 to indicate that there is not Content-Type Header.
const total = parseInt(resp.headers.get(HeaderContentLength) || "-1");
const reader = resp.body?.getReader();
if (!reader) throw ERROR_RESPONSE_BODY_READER;