mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 19:45:05 +01:00
Convert HomeServerRequest.js to ts
This commit is contained in:
parent
e1a823400a
commit
ff53c2757d
@ -16,7 +16,7 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {encodeQueryParams, encodeBody} from "./common";
|
import {encodeQueryParams, encodeBody} from "./common";
|
||||||
import {HomeServerRequest} from "./HomeServerRequest.js";
|
import {HomeServerRequest} from "./HomeServerRequest";
|
||||||
|
|
||||||
const CS_R0_PREFIX = "/_matrix/client/r0";
|
const CS_R0_PREFIX = "/_matrix/client/r0";
|
||||||
const DEHYDRATION_PREFIX = "/_matrix/client/unstable/org.matrix.msc2697.v2";
|
const DEHYDRATION_PREFIX = "/_matrix/client/unstable/org.matrix.msc2697.v2";
|
||||||
|
@ -16,9 +16,16 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {HomeServerError, ConnectionError} from "../error.js";
|
import {HomeServerError, ConnectionError} from "../error.js";
|
||||||
|
import type {RequestResult} from "../../platform/web/dom/request/fetch.js";
|
||||||
|
import type {LogItem} from "../../logging/LogItem";
|
||||||
|
|
||||||
export class HomeServerRequest {
|
export class HomeServerRequest {
|
||||||
constructor(method, url, sourceRequest, log) {
|
// todo: Shouldn't log be of type ILogItem; but ILogItem does not have finish method
|
||||||
|
private readonly _log?: LogItem;
|
||||||
|
private _sourceRequest?: RequestResult;
|
||||||
|
private readonly _promise: Promise<Request>;
|
||||||
|
|
||||||
|
constructor(method:string, url:string, sourceRequest:RequestResult, log?: LogItem) {
|
||||||
this._log = log;
|
this._log = log;
|
||||||
this._sourceRequest = sourceRequest;
|
this._sourceRequest = sourceRequest;
|
||||||
this._promise = sourceRequest.response().then(response => {
|
this._promise = sourceRequest.response().then(response => {
|
||||||
@ -80,16 +87,16 @@ export class HomeServerRequest {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
abort() {
|
abort(): void {
|
||||||
if (this._sourceRequest) {
|
if (this._sourceRequest) {
|
||||||
this._log?.set("aborted", true);
|
this._log?.set("aborted", true);
|
||||||
this._sourceRequest.abort();
|
this._sourceRequest.abort();
|
||||||
// to mark that it was on purpose in above rejection handler
|
// to mark that it was on purpose in above rejection handler
|
||||||
this._sourceRequest = null;
|
this._sourceRequest = undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
response() {
|
response(): Promise<Request> {
|
||||||
return this._promise;
|
return this._promise;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user