Revert "feat: import config from old domain"

This reverts commit 8d734dd876.
This commit is contained in:
Shusui MOYATANI
2024-01-08 19:30:50 +09:00
parent ccfe1d4adb
commit 69823cb412
9 changed files with 0 additions and 261 deletions

View File

@@ -1,53 +0,0 @@
import {
ok,
notFound,
internalPeerError,
type InterWindowRequestWithId,
type RequestHandler,
} from '@/interWindow';
(() => {
const acceptableOrigins = [
window.location.origin,
'http://localhost:3000',
'http://localhost:12345',
'https://rabbit.syusui.net',
];
const rawMessageHandler = (handler: RequestHandler) => (event: MessageEvent) => {
console.log('transfer-config: received request', event.data, event.origin);
if (!acceptableOrigins.includes(event.origin)) return;
const { origin, source } = event;
if (typeof event.data !== 'string') return;
const request = JSON.parse(event.data) as InterWindowRequestWithId;
let responseObj;
try {
responseObj = handler(request);
} catch (e) {
responseObj = internalPeerError(undefined);
}
const response = JSON.stringify({ requestId: request.requestId, ...responseObj });
// @ts-expect-error postMessage
source?.postMessage(response, origin);
};
window.addEventListener(
'message',
rawMessageHandler((request) => {
switch (request.type) {
case 'GET_CONFIG': {
const value = window.localStorage.getItem('RabbitConfig') ?? '';
return ok(value);
}
default:
return notFound();
}
}),
false,
);
console.log('transfer-config: mounted');
})();