Move from browser-request to fetch (#9345)
This commit is contained in:
committed by
GitHub
parent
ae883bb94b
commit
8b54be6f48
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
Copyright 2021 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { IEventRelation } from "matrix-js-sdk/src/matrix";
|
||||
import { IAbortablePromise } from "matrix-js-sdk/src/@types/partials";
|
||||
|
||||
export interface IUpload {
|
||||
fileName: string;
|
||||
roomId: string;
|
||||
relation?: IEventRelation;
|
||||
total: number;
|
||||
loaded: number;
|
||||
promise: IAbortablePromise<any>;
|
||||
canceled?: boolean;
|
||||
}
|
||||
53
src/models/RoomUpload.ts
Normal file
53
src/models/RoomUpload.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
Copyright 2021 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { IEventRelation, UploadProgress } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import { IEncryptedFile } from "../customisations/models/IMediaEventContent";
|
||||
|
||||
export class RoomUpload {
|
||||
public readonly abortController = new AbortController();
|
||||
public promise: Promise<{ url?: string, file?: IEncryptedFile }>;
|
||||
private uploaded = 0;
|
||||
|
||||
constructor(
|
||||
public readonly roomId: string,
|
||||
public readonly fileName: string,
|
||||
public readonly relation?: IEventRelation,
|
||||
public fileSize = 0,
|
||||
) {}
|
||||
|
||||
public onProgress(progress: UploadProgress) {
|
||||
this.uploaded = progress.loaded;
|
||||
this.fileSize = progress.total;
|
||||
}
|
||||
|
||||
public abort(): void {
|
||||
this.abortController.abort();
|
||||
}
|
||||
|
||||
public get cancelled(): boolean {
|
||||
return this.abortController.signal.aborted;
|
||||
}
|
||||
|
||||
public get total(): number {
|
||||
return this.fileSize;
|
||||
}
|
||||
|
||||
public get loaded(): number {
|
||||
return this.uploaded;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user