Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove ts fragments from webxdc.js #2669

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 2 additions & 13 deletions res/raw/webxdc.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,13 @@ window.webxdc = (() => {
if (!message.file && !message.text) {
return Promise.reject("sendToChat() error: file or text missing");
}
/** @type {(file: Blob) => Promise<string>} */

const blobToBase64 = (file) => {
const dataStart = ";base64,";
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => {
/** @type {string} */
//@ts-ignore
let data = reader.result;
resolve(data.slice(data.indexOf(dataStart) + dataStart.length));
};
Expand All @@ -64,7 +62,6 @@ window.webxdc = (() => {
data.text = message.text;
}

/** @type {{file_name: string, file_message: string} | null} */
if (message.file) {
let base64content;
if (!message.file.name) {
Expand All @@ -78,20 +75,12 @@ window.webxdc = (() => {
return Promise.reject("sendToChat() error: only one of blob, base64 or plainText allowed");
}

// @ts-ignore - needed because typescript imagines that blob would not exist
if (message.file.blob instanceof Blob) {
// @ts-ignore - needed because typescript imagines that blob would not exist
base64content = await blobToBase64(message.file.blob);
// @ts-ignore - needed because typescript imagines that base64 would not exist
} else if (typeof message.file.base64 === "string") {
// @ts-ignore - needed because typescript imagines that base64 would not exist
base64content = message.file.base64;
// @ts-ignore - needed because typescript imagines that plainText would not exist
} else if (typeof message.file.plainText === "string") {
base64content = await blobToBase64(
// @ts-ignore - needed because typescript imagines that plainText would not exist
new Blob([message.file.plainText])
);
base64content = await blobToBase64(new Blob([message.file.plainText]));
} else {
return Promise.reject("sendToChat() error: none of blob, base64 or plainText set correctly");
}
Expand Down
Loading