Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

802 B
Raw Blame
import { wrap, type Remote } from "comlink";
import { workerReady } from "ente-utils/worker";
import type { PasteWorker } from "./worker";

export class PasteClient {
    private constructor(private remote: Remote<PasteWorker>) {}

    static async init(apiOrigin: string) {
        const worker = new Worker(new URL("worker.ts", import.meta.url));
        const RemoteWorker = wrap<typeof PasteWorker>(worker);
        const remote = await workerReady(worker, new RemoteWorker(apiOrigin));
        return new PasteClient(remote);
    }

    create = (pasteOrigin: string, text: string, password?: string) =>
        this.remote.create(pasteOrigin, text, password);

    open = (url: string) => this.remote.open(url);

    submitPassword = (password: string) => this.remote.submitPassword(password);
}