2020-10-26 20:14:11 +05:30
|
|
|
/*
|
|
|
|
Copyright 2020 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 {createFetchRequest} from "./dom/request/fetch.js";
|
|
|
|
import {xhrRequest} from "./dom/request/xhr.js";
|
2021-08-13 22:43:40 +05:30
|
|
|
import {StorageFactory} from "../../matrix/storage/idb/StorageFactory";
|
2021-11-25 15:18:03 +05:30
|
|
|
import {SessionInfoStorage} from "../../matrix/sessioninfo/localstorage/SessionInfoStorage";
|
2020-11-20 20:21:16 +05:30
|
|
|
import {SettingsStorage} from "./dom/SettingsStorage.js";
|
2021-02-12 20:31:54 +05:30
|
|
|
import {Encoding} from "./utils/Encoding.js";
|
2020-10-26 20:14:11 +05:30
|
|
|
import {OlmWorker} from "../../matrix/e2ee/OlmWorker.js";
|
2022-05-06 19:24:45 +05:30
|
|
|
import {IDBLogPersister} from "../../logging/IDBLogPersister";
|
|
|
|
import {ConsoleReporter} from "../../logging/ConsoleReporter";
|
|
|
|
import {Logger} from "../../logging/Logger";
|
2020-10-26 20:14:11 +05:30
|
|
|
import {RootView} from "./ui/RootView.js";
|
|
|
|
import {Clock} from "./dom/Clock.js";
|
|
|
|
import {ServiceWorkerHandler} from "./dom/ServiceWorkerHandler.js";
|
2021-03-19 01:13:40 +05:30
|
|
|
import {NotificationService} from "./dom/NotificationService.js";
|
2020-10-26 20:14:11 +05:30
|
|
|
import {History} from "./dom/History.js";
|
|
|
|
import {OnlineStatus} from "./dom/OnlineStatus.js";
|
|
|
|
import {Crypto} from "./dom/Crypto.js";
|
|
|
|
import {estimateStorageUsage} from "./dom/StorageEstimate.js";
|
|
|
|
import {WorkerPool} from "./dom/WorkerPool.js";
|
2020-11-11 03:06:26 +05:30
|
|
|
import {BlobHandle} from "./dom/BlobHandle.js";
|
2021-03-10 00:05:25 +05:30
|
|
|
import {hasReadPixelPermission, ImageHandle, VideoHandle} from "./dom/ImageHandle.js";
|
2020-11-10 21:53:23 +05:30
|
|
|
import {downloadInIframe} from "./dom/download.js";
|
2021-11-16 14:13:35 +05:30
|
|
|
import {Disposables} from "../../utils/Disposables";
|
2021-07-13 03:16:42 +05:30
|
|
|
import {parseHTML} from "./parsehtml.js";
|
2022-02-25 15:52:54 +05:30
|
|
|
import {handleAvatarError} from "./ui/avatar";
|
2022-03-17 16:01:36 +05:30
|
|
|
import {MediaDevicesWrapper} from "./dom/MediaDevices";
|
|
|
|
import {DOMWebRTC} from "./dom/WebRTC";
|
2022-05-12 16:03:06 +05:30
|
|
|
import {ThemeLoader} from "./ThemeLoader";
|
2020-10-26 20:14:11 +05:30
|
|
|
|
|
|
|
function addScript(src) {
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
var s = document.createElement("script");
|
|
|
|
s.setAttribute("src", src );
|
|
|
|
s.onload=resolve;
|
|
|
|
s.onerror=reject;
|
|
|
|
document.body.appendChild(s);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function loadOlm(olmPaths) {
|
|
|
|
// make crypto.getRandomValues available without
|
|
|
|
// a prefix on IE11, needed by olm to work
|
|
|
|
if (window.msCrypto && !window.crypto) {
|
|
|
|
window.crypto = window.msCrypto;
|
|
|
|
}
|
|
|
|
if (olmPaths) {
|
|
|
|
if (window.WebAssembly) {
|
|
|
|
await addScript(olmPaths.wasmBundle);
|
|
|
|
await window.Olm.init({locateFile: () => olmPaths.wasm});
|
|
|
|
} else {
|
|
|
|
await addScript(olmPaths.legacyBundle);
|
|
|
|
await window.Olm.init();
|
|
|
|
}
|
|
|
|
return window.Olm;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2021-12-06 20:08:01 +05:30
|
|
|
// turn asset path to absolute path if it isn't already
|
|
|
|
// so it can be loaded independent of base
|
|
|
|
function assetAbsPath(assetPath) {
|
|
|
|
if (!assetPath.startsWith("/")) {
|
|
|
|
return new URL(assetPath, document.location.href).pathname;
|
|
|
|
}
|
|
|
|
return assetPath;
|
2020-10-26 20:14:11 +05:30
|
|
|
}
|
|
|
|
|
2021-12-22 22:18:08 +05:30
|
|
|
async function loadOlmWorker(assetPaths) {
|
|
|
|
const workerPool = new WorkerPool(assetPaths.worker, 4);
|
2020-10-26 20:14:11 +05:30
|
|
|
await workerPool.init();
|
2021-12-06 18:19:14 +05:30
|
|
|
await workerPool.sendAll({
|
|
|
|
type: "load_olm",
|
2021-12-22 22:18:08 +05:30
|
|
|
path: assetAbsPath(assetPaths.olm.legacyBundle)
|
2021-12-06 18:19:14 +05:30
|
|
|
});
|
2020-10-26 20:14:11 +05:30
|
|
|
const olmWorker = new OlmWorker(workerPool);
|
|
|
|
return olmWorker;
|
|
|
|
}
|
|
|
|
|
2021-03-17 00:04:34 +05:30
|
|
|
// needed for mobile Safari which shifts the layout viewport up without resizing it
|
|
|
|
// when the keyboard shows (see https://bugs.webkit.org/show_bug.cgi?id=141832)
|
|
|
|
function adaptUIOnVisualViewportResize(container) {
|
|
|
|
if (!window.visualViewport) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const handler = () => {
|
|
|
|
const sessionView = container.querySelector('.SessionView');
|
|
|
|
if (!sessionView) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const scrollable = container.querySelector('.bottom-aligned-scroll');
|
|
|
|
let scrollTopBefore, heightBefore, heightAfter;
|
|
|
|
|
|
|
|
if (scrollable) {
|
|
|
|
scrollTopBefore = scrollable.scrollTop;
|
|
|
|
heightBefore = scrollable.offsetHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ideally we'd use window.visualViewport.offsetTop but that seems to occasionally lag
|
|
|
|
// behind (last tested on iOS 14.4 simulator) so we have to compute the offset manually
|
|
|
|
const offsetTop = sessionView.offsetTop + sessionView.offsetHeight - window.visualViewport.height;
|
|
|
|
|
|
|
|
container.style.setProperty('--ios-viewport-height', window.visualViewport.height.toString() + 'px');
|
|
|
|
container.style.setProperty('--ios-viewport-top', offsetTop.toString() + 'px');
|
|
|
|
|
|
|
|
if (scrollable) {
|
|
|
|
heightAfter = scrollable.offsetHeight;
|
|
|
|
scrollable.scrollTop = scrollTopBefore + heightBefore - heightAfter;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
window.visualViewport.addEventListener('resize', handler);
|
|
|
|
return () => {
|
|
|
|
window.visualViewport.removeEventListener('resize', handler);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-10-26 20:14:11 +05:30
|
|
|
export class Platform {
|
2022-05-06 19:24:45 +05:30
|
|
|
constructor({ container, assetPaths, config, configURL, logger, options = null, cryptoExtras = null }) {
|
2020-10-26 20:14:11 +05:30
|
|
|
this._container = container;
|
2021-12-22 22:18:08 +05:30
|
|
|
this._assetPaths = assetPaths;
|
|
|
|
this._config = config;
|
2022-04-20 12:25:23 +05:30
|
|
|
this._configURL = configURL;
|
2021-02-12 22:35:39 +05:30
|
|
|
this.settingsStorage = new SettingsStorage("hydrogen_setting_v1_");
|
2020-10-26 20:14:11 +05:30
|
|
|
this.clock = new Clock();
|
2021-02-12 22:35:39 +05:30
|
|
|
this.encoding = new Encoding();
|
|
|
|
this.random = Math.random;
|
2022-05-06 19:24:45 +05:30
|
|
|
this.logger = logger ?? this._createLogger(options?.development);
|
2020-10-26 20:14:11 +05:30
|
|
|
this.history = new History();
|
|
|
|
this.onlineStatus = new OnlineStatus();
|
|
|
|
this._serviceWorkerHandler = null;
|
2021-12-22 22:18:08 +05:30
|
|
|
if (assetPaths.serviceWorker && "serviceWorker" in navigator) {
|
2020-10-26 20:14:11 +05:30
|
|
|
this._serviceWorkerHandler = new ServiceWorkerHandler();
|
2021-12-22 22:18:08 +05:30
|
|
|
this._serviceWorkerHandler.registerAndStart(assetPaths.serviceWorker);
|
2020-10-26 20:14:11 +05:30
|
|
|
}
|
2022-04-21 14:14:38 +05:30
|
|
|
this.notificationService = undefined;
|
2022-03-02 14:47:59 +05:30
|
|
|
// Only try to use crypto when olm is provided
|
|
|
|
if(this._assetPaths.olm) {
|
2022-02-25 13:29:48 +05:30
|
|
|
this.crypto = new Crypto(cryptoExtras);
|
|
|
|
}
|
2020-10-26 20:14:11 +05:30
|
|
|
this.storageFactory = new StorageFactory(this._serviceWorkerHandler);
|
|
|
|
this.sessionInfoStorage = new SessionInfoStorage("hydrogen_sessions_v1");
|
|
|
|
this.estimateStorageUsage = estimateStorageUsage;
|
|
|
|
if (typeof fetch === "function") {
|
2021-03-19 00:04:41 +05:30
|
|
|
this.request = createFetchRequest(this.clock.createTimeout, this._serviceWorkerHandler);
|
2020-10-26 20:14:11 +05:30
|
|
|
} else {
|
|
|
|
this.request = xhrRequest;
|
|
|
|
}
|
2020-11-02 15:46:19 +05:30
|
|
|
const isIE11 = !!window.MSInputMethodContext && !!document.documentMode;
|
2020-11-10 22:21:39 +05:30
|
|
|
this.isIE11 = isIE11;
|
2021-03-17 00:04:34 +05:30
|
|
|
// From https://stackoverflow.com/questions/9038625/detect-if-device-is-ios/9039885
|
|
|
|
const isIOS = /iPad|iPhone|iPod/.test(navigator.platform) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1) && !window.MSStream;
|
|
|
|
this.isIOS = isIOS;
|
|
|
|
this._disposables = new Disposables();
|
2021-12-22 21:49:10 +05:30
|
|
|
this._olmPromise = undefined;
|
|
|
|
this._workerPromise = undefined;
|
2022-03-17 16:01:36 +05:30
|
|
|
this.mediaDevices = new MediaDevicesWrapper(navigator.mediaDevices);
|
|
|
|
this.webRTC = new DOMWebRTC();
|
2022-05-11 15:46:12 +05:30
|
|
|
this._themeLoader = import.meta.env.DEV? null: new ThemeLoader(this);
|
2020-10-26 20:14:11 +05:30
|
|
|
}
|
|
|
|
|
2022-04-20 12:25:23 +05:30
|
|
|
async init() {
|
2022-05-19 01:11:31 +05:30
|
|
|
try {
|
|
|
|
await this.logger.run("Platform init", async (log) => {
|
|
|
|
if (!this._config) {
|
|
|
|
if (!this._configURL) {
|
|
|
|
throw new Error("Neither config nor configURL was provided!");
|
|
|
|
}
|
|
|
|
const {status, body}= await this.request(this._configURL, {method: "GET", format: "json", cache: true}).response();
|
|
|
|
if (status === 404) {
|
|
|
|
throw new Error(`Could not find ${this._configURL}. Did you copy over config.sample.json?`);
|
|
|
|
} else if (status >= 400) {
|
|
|
|
throw new Error(`Got status ${status} while trying to fetch ${this._configURL}`);
|
|
|
|
}
|
|
|
|
this._config = body;
|
2022-05-18 16:09:09 +05:30
|
|
|
}
|
2022-05-19 01:11:31 +05:30
|
|
|
this.notificationService = new NotificationService(
|
|
|
|
this._serviceWorkerHandler,
|
|
|
|
this._config.push
|
|
|
|
);
|
2022-06-12 16:51:10 +05:30
|
|
|
if (this._themeLoader) {
|
|
|
|
const manifests = this.config["themeManifests"];
|
|
|
|
await this._themeLoader?.init(manifests, log);
|
|
|
|
const { themeName, themeVariant } = await this._themeLoader.getActiveTheme();
|
|
|
|
log.log({ l: "Active theme", name: themeName, variant: themeVariant });
|
|
|
|
this._themeLoader.setTheme(themeName, themeVariant, log);
|
|
|
|
}
|
2022-05-19 01:11:31 +05:30
|
|
|
});
|
|
|
|
} catch (err) {
|
|
|
|
this._container.innerText = err.message;
|
|
|
|
throw err;
|
2022-04-20 12:25:23 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-30 13:28:28 +05:30
|
|
|
_createLogger(isDevelopment) {
|
2022-05-06 19:24:45 +05:30
|
|
|
const logger = new Logger({platform: this});
|
2021-11-30 13:28:28 +05:30
|
|
|
// Make sure that loginToken does not end up in the logs
|
|
|
|
const transformer = (item) => {
|
|
|
|
if (item.e?.stack) {
|
2021-12-08 22:35:57 +05:30
|
|
|
item.e.stack = item.e.stack.replace(/\/\?loginToken=(.+)/, "?loginToken=<snip>");
|
2021-11-30 13:28:28 +05:30
|
|
|
}
|
|
|
|
return item;
|
|
|
|
};
|
2022-05-06 19:24:45 +05:30
|
|
|
const logPersister = new IDBLogPersister({name: "hydrogen_logs", platform: this, serializedTransformer: transformer});
|
|
|
|
logger.addReporter(logPersister);
|
2021-11-30 13:28:28 +05:30
|
|
|
if (isDevelopment) {
|
2022-05-06 19:24:45 +05:30
|
|
|
logger.addReporter(new ConsoleReporter());
|
2021-11-30 13:28:28 +05:30
|
|
|
}
|
2022-05-06 19:24:45 +05:30
|
|
|
return logger;
|
2021-11-30 13:28:28 +05:30
|
|
|
}
|
|
|
|
|
2020-10-26 20:14:11 +05:30
|
|
|
get updateService() {
|
|
|
|
return this._serviceWorkerHandler;
|
|
|
|
}
|
|
|
|
|
|
|
|
loadOlm() {
|
2021-12-22 21:49:10 +05:30
|
|
|
if (!this._olmPromise) {
|
2021-12-22 22:18:08 +05:30
|
|
|
this._olmPromise = loadOlm(this._assetPaths.olm);
|
2021-12-22 21:49:10 +05:30
|
|
|
}
|
|
|
|
return this._olmPromise;
|
2020-10-26 20:14:11 +05:30
|
|
|
}
|
|
|
|
|
2021-03-30 22:13:03 +05:30
|
|
|
get config() {
|
|
|
|
return this._config;
|
|
|
|
}
|
|
|
|
|
2020-10-26 20:14:11 +05:30
|
|
|
async loadOlmWorker() {
|
|
|
|
if (!window.WebAssembly) {
|
2021-12-22 21:49:10 +05:30
|
|
|
if (!this._workerPromise) {
|
2021-12-22 22:18:08 +05:30
|
|
|
this._workerPromise = loadOlmWorker(this._assetPaths);
|
2021-12-22 21:49:10 +05:30
|
|
|
}
|
|
|
|
return this._workerPromise;
|
2020-10-26 20:14:11 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
createAndMountRootView(vm) {
|
2020-11-02 15:46:19 +05:30
|
|
|
if (this.isIE11) {
|
2020-10-26 20:14:11 +05:30
|
|
|
this._container.className += " legacy";
|
|
|
|
}
|
2021-03-17 00:04:34 +05:30
|
|
|
if (this.isIOS) {
|
|
|
|
this._container.className += " ios";
|
|
|
|
const disposable = adaptUIOnVisualViewportResize(this._container);
|
|
|
|
if (disposable) {
|
|
|
|
this._disposables.track(disposable);
|
|
|
|
}
|
|
|
|
}
|
2021-06-30 23:30:44 +05:30
|
|
|
this._container.addEventListener("error", handleAvatarError, true);
|
2021-07-01 15:42:07 +05:30
|
|
|
this._disposables.track(() => this._container.removeEventListener("error", handleAvatarError, true));
|
2020-10-26 20:14:11 +05:30
|
|
|
window.__hydrogenViewModel = vm;
|
|
|
|
const view = new RootView(vm);
|
|
|
|
this._container.appendChild(view.mount());
|
|
|
|
}
|
|
|
|
|
|
|
|
setNavigation(navigation) {
|
|
|
|
this._serviceWorkerHandler?.setNavigation(navigation);
|
|
|
|
}
|
2020-10-26 21:48:17 +05:30
|
|
|
|
2020-11-11 03:06:26 +05:30
|
|
|
createBlob(buffer, mimetype) {
|
|
|
|
return BlobHandle.fromBuffer(buffer, mimetype);
|
2020-10-26 21:48:17 +05:30
|
|
|
}
|
2020-11-10 21:53:23 +05:30
|
|
|
|
2020-11-11 03:06:26 +05:30
|
|
|
saveFileAs(blobHandle, filename) {
|
2020-11-10 21:53:23 +05:30
|
|
|
if (navigator.msSaveBlob) {
|
2020-11-11 15:14:44 +05:30
|
|
|
navigator.msSaveBlob(blobHandle.nativeBlob, filename);
|
2020-11-10 21:53:23 +05:30
|
|
|
} else {
|
2021-12-22 22:18:08 +05:30
|
|
|
downloadInIframe(this._container, this._assetPaths.downloadSandbox, blobHandle, filename, this.isIOS);
|
2020-11-10 21:53:23 +05:30
|
|
|
}
|
|
|
|
}
|
2020-11-11 03:06:26 +05:30
|
|
|
|
|
|
|
openFile(mimeType = null) {
|
|
|
|
const input = document.createElement("input");
|
|
|
|
input.setAttribute("type", "file");
|
2020-11-11 17:17:26 +05:30
|
|
|
input.className = "hidden";
|
2020-11-11 03:06:26 +05:30
|
|
|
if (mimeType) {
|
|
|
|
input.setAttribute("accept", mimeType);
|
|
|
|
}
|
2021-08-24 19:01:18 +05:30
|
|
|
const promise = new Promise(resolve => {
|
2020-11-11 03:06:26 +05:30
|
|
|
const checkFile = () => {
|
|
|
|
input.removeEventListener("change", checkFile, true);
|
|
|
|
const file = input.files[0];
|
2020-11-11 17:17:26 +05:30
|
|
|
this._container.removeChild(input);
|
2020-11-11 03:06:26 +05:30
|
|
|
if (file) {
|
2020-11-12 18:20:06 +05:30
|
|
|
resolve({name: file.name, blob: BlobHandle.fromBlob(file)});
|
2020-11-11 03:06:26 +05:30
|
|
|
} else {
|
2020-11-19 00:37:31 +05:30
|
|
|
resolve();
|
2020-11-11 03:06:26 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
input.addEventListener("change", checkFile, true);
|
|
|
|
});
|
2020-11-11 17:17:26 +05:30
|
|
|
// IE11 needs the input to be attached to the document
|
|
|
|
this._container.appendChild(input);
|
2020-11-11 03:06:26 +05:30
|
|
|
input.click();
|
|
|
|
return promise;
|
|
|
|
}
|
2020-11-12 18:20:06 +05:30
|
|
|
|
2021-07-30 23:03:18 +05:30
|
|
|
openUrl(url) {
|
|
|
|
location.href = url;
|
|
|
|
}
|
|
|
|
|
2021-07-03 03:35:50 +05:30
|
|
|
parseHTML(html) {
|
2021-07-13 03:16:42 +05:30
|
|
|
return parseHTML(html);
|
2021-07-03 03:35:50 +05:30
|
|
|
}
|
|
|
|
|
2020-11-12 18:20:06 +05:30
|
|
|
async loadImage(blob) {
|
|
|
|
return ImageHandle.fromBlob(blob);
|
|
|
|
}
|
|
|
|
|
2021-03-10 00:05:25 +05:30
|
|
|
async loadVideo(blob) {
|
|
|
|
return VideoHandle.fromBlob(blob);
|
|
|
|
}
|
|
|
|
|
2020-11-12 18:20:06 +05:30
|
|
|
hasReadPixelPermission() {
|
|
|
|
return hasReadPixelPermission();
|
|
|
|
}
|
2020-11-12 18:20:32 +05:30
|
|
|
|
|
|
|
get devicePixelRatio() {
|
|
|
|
return window.devicePixelRatio || 1;
|
|
|
|
}
|
2021-03-15 21:25:14 +05:30
|
|
|
|
|
|
|
get version() {
|
2021-12-09 21:07:31 +05:30
|
|
|
return DEFINE_VERSION;
|
2021-03-15 21:25:14 +05:30
|
|
|
}
|
2021-03-17 00:04:34 +05:30
|
|
|
|
2022-05-11 14:58:14 +05:30
|
|
|
get themeLoader() {
|
|
|
|
return this._themeLoader;
|
2022-04-25 14:29:31 +05:30
|
|
|
}
|
|
|
|
|
2022-05-11 14:58:14 +05:30
|
|
|
replaceStylesheet(newPath) {
|
2022-04-25 16:33:31 +05:30
|
|
|
const head = document.querySelector("head");
|
2022-04-25 14:29:31 +05:30
|
|
|
// remove default theme
|
2022-04-25 16:33:31 +05:30
|
|
|
document.querySelectorAll(".theme").forEach(e => e.remove());
|
2022-04-25 14:29:31 +05:30
|
|
|
// add new theme
|
|
|
|
const styleTag = document.createElement("link");
|
|
|
|
styleTag.href = `./${newPath}`;
|
|
|
|
styleTag.rel = "stylesheet";
|
|
|
|
styleTag.type = "text/css";
|
2022-04-25 16:33:31 +05:30
|
|
|
styleTag.className = "theme";
|
2022-04-25 14:29:31 +05:30
|
|
|
head.appendChild(styleTag);
|
|
|
|
}
|
|
|
|
|
2022-06-15 14:43:46 +05:30
|
|
|
get description() {
|
|
|
|
return navigator.userAgent ?? "<unknown>";
|
|
|
|
}
|
|
|
|
|
2021-03-17 00:04:34 +05:30
|
|
|
dispose() {
|
|
|
|
this._disposables.dispose();
|
|
|
|
}
|
2020-10-26 20:14:11 +05:30
|
|
|
}
|
2021-11-30 13:28:28 +05:30
|
|
|
|
|
|
|
import {LogItem} from "../../logging/LogItem";
|
|
|
|
export function tests() {
|
|
|
|
return {
|
|
|
|
"loginToken should not be in logs": (assert) => {
|
2022-05-09 18:20:52 +05:30
|
|
|
const logPersister = Object.create(IDBLogPersister.prototype);
|
|
|
|
logPersister._queuedItems = [];
|
|
|
|
logPersister.options = {
|
|
|
|
serializedTransformer: (item) => {
|
|
|
|
if (item.e?.stack) {
|
|
|
|
item.e.stack = item.e.stack.replace(/(?<=\/\?loginToken=).+/, "<snip>");
|
|
|
|
}
|
|
|
|
return item;
|
2021-11-30 13:28:28 +05:30
|
|
|
}
|
|
|
|
};
|
2022-05-09 18:20:52 +05:30
|
|
|
const logger = { _now() {return 5;} };
|
2021-11-30 13:28:28 +05:30
|
|
|
const logItem = new LogItem("test", 1, logger);
|
|
|
|
logItem.error = new Error();
|
|
|
|
logItem.error.stack = "main http://localhost:3000/src/main.js:55\n<anonymous> http://localhost:3000/?loginToken=secret:26"
|
2022-05-09 18:20:52 +05:30
|
|
|
logPersister.reportItem(logItem, null, false);
|
|
|
|
const item = logPersister._queuedItems.pop();
|
2021-11-30 13:28:28 +05:30
|
|
|
assert.strictEqual(item.json.search("secret"), -1);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|