This commit is contained in:
Mirco Wittrien 2023-10-20 14:25:24 +02:00
parent c5aed03123
commit 0e497b57f5
8 changed files with 36 additions and 60 deletions

View File

@ -2,7 +2,7 @@
* @name BDFDB
* @author DevilBro
* @authorId 278543574059057154
* @version 3.3.8
* @version 3.3.9
* @description Required Library for DevilBro's Plugins
* @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien
@ -15,7 +15,7 @@
module.exports = (_ => {
if (window.BDFDB_Global && window.BDFDB_Global.PluginUtils && typeof window.BDFDB_Global.PluginUtils.cleanUp == "function") window.BDFDB_Global.PluginUtils.cleanUp(window.BDFDB_Global);
const request = require("request"), fs = require("fs"), path = require("path");
const fs = require("fs"), path = require("path");
var BDFDB, Internal;
var LibraryRequires = {};
@ -172,15 +172,13 @@ module.exports = (_ => {
else {
let config = args[0] && typeof args[0] == "object" ? args[0] : (args[1] && typeof args[1] == "object" && args[1]);
let timeout = 600000;
if (config && config.url) delete config.url;
if (config && config.form && typeof config.form == "object") {
let query = Object.entries(config.form).map(n => n[0] + "=" + n[1]).join("&");
if (query) {
url += `?${query}`;
if (uIndex == 0) args[0] += url;
else if (uIndex == 1) args[1].url += url;
}
if (query) url += `?${query}`;
}
if (config && !isNaN(parseInt(config.timeout)) && config.timeout > 0) timeout = config.timeout;
if (config && config.method) config.method = config.method.toUpperCase();
let killed = false, timeoutObj = BDFDB.TimeUtils.timeout(_ => {
killed = true;
BDFDB.TimeUtils.clear(timeoutObj);
@ -196,37 +194,15 @@ module.exports = (_ => {
url: ""
}, null);
}, timeout);
args[cIndex] = (...args2) => {
let response = null;
return (config && config.bdVersion && BdApi && BdApi.Net && BdApi.Net.fetch ? BdApi.Net.fetch : fetch)(url, Object.assign({}, config, {timeout: 60000})).then(r => {
response = r;
response.statusCode = response.status;
BDFDB.TimeUtils.clear(timeoutObj);
if (!killed) callback(...args2);
};
let requestError = false;
try {Buffer} catch (err) {requestError = true;}
if (!requestError || !request) return request(...args);
else {
let xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = _ => {
if (xhttp && xhttp.readyState == 4) {
BDFDB.TimeUtils.clear(timeoutObj);
let headers = {}, headersArray = (xhttp.getAllResponseHeaders && xhttp.getAllResponseHeaders() || "").split("\r\n").map(n => n.split(":")).filter(n => n);
if (headersArray && headersArray.length > 1) for (let entry of headersArray) if (entry[0] != undefined && entry[1] != undefined) headers[entry[0]] = entry[1].trim();
callback(xhttp.status != 200 ? new Error(`XML Request Failed`) : null, {
aborted: false,
complete: true,
end: undefined,
headers: {},
method: config && config.method || "get",
rawHeaders: [],
statusCode: xhttp.status,
statusMessage: "OK",
url: xhttp.responseURL
}, xhttp.status != 200 ? null : xhttp.response);
}
};
xhttp.open((config && config.method || "get").toUpperCase(), url, true);
if (config && config.headers) for (let key in config.headers) if (key != "user-agent") xhttp.setRequestHeader(key, config.headers[key]);
xhttp.send();
}
return response.text();
}).then(body => {
if (!killed) callback(response.status != 200 ? new Error(response.statusText || "Fetch Failed") : null, response, body);
});
}
};
@ -1139,7 +1115,7 @@ module.exports = (_ => {
return {backup: fs.existsSync(path) && (fs.readFileSync(path) || "").toString(), hashIsSame: libHashes[fileName] && oldLibHashes[fileName] && libHashes[fileName] == oldLibHashes[fileName]};
};
const requestLibraryHashes = tryAgain => {
requestFunction("https://api.github.com/repos/mwittrien/BetterDiscordAddons/contents/Library/_res/", {headers: {"user-agent": "node.js"}, timeout: 60000}, (e, r, b) => {
requestFunction("https://api.github.com/repos/mwittrien/BetterDiscordAddons/contents/Library/_res/", {timeout: 60000}, (e, r, b) => {
if ((e || !b || r.statusCode != 200) && tryAgain) return BDFDB.TimeUtils.timeout(_ => requestLibraryHashes(), 10000);
else {
try {

View File

@ -2,7 +2,7 @@
* @name FriendNotifications
* @author DevilBro
* @authorId 278543574059057154
* @version 1.9.4
* @version 1.9.5
* @description Shows a Notification when a Friend or a User, you choose to observe, changes their Status
* @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien
@ -692,7 +692,7 @@ module.exports = (_ => {
});
else BDFDB.LibraryRequires.fs.readFile(source, "", (error, buffer) => {
if (error) BDFDB.NotificationUtils.toast("Could not fetch File, please make sure the File exists", {type: "danger"});
else successSavedAudio(key, source, `data:audio/mpeg;base64,${Buffer.from(buffer).toString("base64")}`);
else successSavedAudio(key, source, `data:audio/mpeg;base64,${btoa((new TextDecoder()).decode(buffer))}`);
});
},
children: BDFDB.LanguageUtils.LanguageStrings.SAVE

View File

@ -2,7 +2,7 @@
* @name ImageUtilities
* @author DevilBro
* @authorId 278543574059057154
* @version 5.2.9
* @version 5.3.0
* @description Adds several Utilities for Images/Videos (Gallery, Download, Reverse Search, Zoom, Copy, etc.)
* @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien
@ -1516,7 +1516,7 @@ module.exports = (_ => {
if (!extension) BDFDB.NotificationUtils.toast(this.labels.toast_save_failed.replace("{{var0}}", BDFDB.LanguageUtils.LanguageStrings.IMAGE).replace("{{var1}}", path || "PC"), {type: "danger"});
else {
let type = fileTypes[extension].video ? BDFDB.LanguageUtils.LanguageStrings.VIDEO : BDFDB.LanguageUtils.LanguageStrings.IMAGE;
if (path) BDFDB.LibraryRequires.fs.writeFile(this.getFileName(path, (alternativeName || url.split("/").pop().split(".").slice(0, -1).join(".") || "unknown").slice(0, 35), extension, 0), Buffer.from(buffer), error => {
if (path) BDFDB.LibraryRequires.fs.writeFile(this.getFileName(path, (alternativeName || url.split("/").pop().split(".").slice(0, -1).join(".") || "unknown").slice(0, 35), extension, 0), new Uint8Array(buffer), error => {
if (error) BDFDB.NotificationUtils.toast(this.labels.toast_save_failed.replace("{{var0}}", type).replace("{{var1}}", path), {type: "danger"});
else BDFDB.NotificationUtils.toast(this.labels.toast_save_success.replace("{{var0}}", type).replace("{{var1}}", path), {type: "success"});
});

View File

@ -2,7 +2,7 @@
* @name NotificationSounds
* @author DevilBro
* @authorId 278543574059057154
* @version 3.8.2
* @version 3.8.3
* @description Allows you to replace the native Sounds with custom Sounds
* @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien
@ -437,7 +437,7 @@ module.exports = (_ => {
});
else BDFDB.LibraryRequires.fs.readFile(source, "", (error, buffer) => {
if (error) BDFDB.NotificationUtils.toast("Could not fetch file. Please make sure the file exists", {type: "danger"});
else return successSavedAudio({category, sound, source: `data:audio/mpeg;base64,${Buffer.from(buffer).toString("base64")}`});
else return successSavedAudio({category, sound, source: `data:audio/mpeg;base64,${btoa((new TextDecoder()).decode(buffer))}`});
});
},
children: BDFDB.LanguageUtils.LanguageStrings.SAVE

View File

@ -2,7 +2,7 @@
* @name PluginRepo
* @author DevilBro
* @authorId 278543574059057154
* @version 2.5.1
* @version 2.5.2
* @description Allows you to download all Plugins from BD's Website within Discord
* @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien
@ -492,7 +492,7 @@ module.exports = (_ => {
loadingToast.close();
BDFDB.NotificationUtils.toast(BDFDB.LanguageUtils.LibraryStringsFormat("download_fail", `Plugin "${this.props.data.name}"`), {type: "danger"});
}
else BDFDB.LibraryRequires.fs.writeFile(BDFDB.LibraryRequires.path.join(BDFDB.BDUtils.getPluginsFolder(), this.props.data.rawSourceUrl.split("/").pop()), Buffer.from(buffer).toString(), error2 => {
else BDFDB.LibraryRequires.fs.writeFile(BDFDB.LibraryRequires.path.join(BDFDB.BDUtils.getPluginsFolder(), this.props.data.rawSourceUrl.split("/").pop()), (new TextDecoder()).decode(buffer), error2 => {
delete this.props.downloading;
loadingToast.close();
if (error2) BDFDB.NotificationUtils.toast(BDFDB.LanguageUtils.LibraryStringsFormat("save_fail", `Plugin "${this.props.data.name}"`), {type: "danger"});
@ -761,7 +761,7 @@ module.exports = (_ => {
BDFDB.DiscordUtils.requestFileData(plugin.rawSourceUrl, (error, buffer) => {
if (error || !buffer) plugin.failed = true;
else {
let body = Buffer.from(buffer).toString();
let body = (new TextDecoder()).decode(buffer);
if (body && body.indexOf("404: Not Found") != 0) {
const META = body.split("*/")[0];
plugin.name = BDFDB.StringUtils.upperCaseFirstChar((/@name\s+([^\t^\r^\n]+)|\/\/\**META.*["']name["']\s*:\s*["'](.+?)["']/i.exec(META) || []).filter(n => n)[1] || plugin.name || "");
@ -787,7 +787,7 @@ module.exports = (_ => {
}
};
BDFDB.LibraryRequires.request("https://api.betterdiscord.app/v1/store/plugins", (error, response, body) => {
BDFDB.LibraryRequires.request("https://api.betterdiscord.app/v1/store/plugins", {bdVersion: true}, (error, response, body) => {
if (!error && body && response.statusCode == 200) try {
grabbedPlugins = BDFDB.ArrayUtils.keySort(JSON.parse(body).filter(n => n), "name");
BDFDB.DataUtils.save(BDFDB.ArrayUtils.numSort(grabbedPlugins.map(n => n.id)).join(" "), this, "cached");
@ -851,7 +851,7 @@ module.exports = (_ => {
}
checkForNewPlugins () {
BDFDB.LibraryRequires.request("https://api.betterdiscord.app/v1/store/plugins", (error, response, body) => {
BDFDB.LibraryRequires.request("https://api.betterdiscord.app/v1/store/plugins", {bdVersion: true}, (error, response, body) => {
if (!error && body) try {
if (JSON.parse(body).filter(n => n).length != grabbedPlugins.length) {
loading = {is: false, timeout: null, amount: 0};

View File

@ -2,7 +2,7 @@
* @name ServerFolders
* @author DevilBro
* @authorId 278543574059057154
* @version 7.1.7
* @version 7.1.8
* @description Changes Discord's Folders, Servers open in a new Container, also adds extra Features to more easily organize, customize and manage your Folders
* @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien
@ -318,7 +318,7 @@ module.exports = (_ => {
checkImage(base64OrUrl, callback) {
if (base64OrUrl.indexOf("https://") == 0 || base64OrUrl.indexOf("http://") == 0) BDFDB.LibraryRequires.request(base64OrUrl.trim(), {agentOptions: {rejectUnauthorized: false}, headers: {"Content-Type": "application/json"}}, (error, response, body) => {
if (response && response.headers["content-type"] && response.headers["content-type"].indexOf("image") != -1 && response.headers["content-type"] != "image/gif") {
this.resizeImage("data:" + response.headers["content-type"] + ";base64," + Buffer.from(body).toString("base64"), callback);
this.resizeImage("data:" + response.headers["content-type"] + ";base64," + btoa((new TextDecoder()).decode(body)), callback);
}
else callback(base64OrUrl);
});

View File

@ -2,7 +2,7 @@
* @name SpellCheck
* @author DevilBro
* @authorId 278543574059057154
* @version 1.6.6
* @version 1.6.7
* @description Adds a Spell Check to all Message Inputs. Select a Word and Right Click it to add it to your Dictionary
* @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien
@ -365,7 +365,7 @@ module.exports = (_ => {
};
if (this.settings.general.downloadDictionary && BDFDB.LibraryRequires.fs.existsSync(filePath)) BDFDB.LibraryRequires.fs.readFile(filePath, "", (error, buffer) => {
parse(error, buffer, Buffer.from(buffer).toString(), false);
parse(error, buffer, (new TextDecoder()).decode(buffer), false);
});
else BDFDB.LibraryRequires.request("https://mwittrien.github.io/BetterDiscordAddons/Plugins/SpellCheck/dic/" + lang + ".dic", (error, response, body) => {
parse(error, response, body, this.settings.general.downloadDictionary);

View File

@ -2,7 +2,7 @@
* @name ThemeRepo
* @author DevilBro
* @authorId 278543574059057154
* @version 2.5.0
* @version 2.5.1
* @description Allows you to download all Themes from BD's Website within Discord
* @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien
@ -638,7 +638,7 @@ module.exports = (_ => {
loadingToast.close();
BDFDB.NotificationUtils.toast(BDFDB.LanguageUtils.LibraryStringsFormat("download_fail", `Theme "${this.props.data.name}"`), {type: "danger"});
}
else list.createThemeFile(this.props.data.name, this.props.data.rawSourceUrl.split("/").pop(), Buffer.from(buffer).toString(), autoloadKey).then(error2 => {
else list.createThemeFile(this.props.data.name, this.props.data.rawSourceUrl.split("/").pop(), (new TextDecoder()).decode(buffer), autoloadKey).then(error2 => {
delete this.props.downloading;
loadingToast.close();
if (!error2) {
@ -886,7 +886,7 @@ module.exports = (_ => {
}
BDFDB.DiscordUtils.requestFileData("https://mwittrien.github.io/BetterDiscordAddons/Plugins/ThemeRepo/_res/GeneratorList.txt", (error, buffer) => {
let body = !error && buffer && Buffer.from(buffer).toString();
let body = !error && buffer && (new TextDecoder()).decode(buffer);
if (body) for (let id of body.replace(/[\r\t]/g, "").split(" ").map(n => parseInt(n)).filter(n => n != null)) {
let theme = grabbedThemes.find(t => t.id == id);
if (theme) generatorThemes.push(theme);
@ -894,7 +894,7 @@ module.exports = (_ => {
});
BDFDB.DiscordUtils.requestFileData(document.querySelector("head link[rel='stylesheet'][integrity]").href, (error, buffer) => {
let nativeCSS = !error && buffer && Buffer.from(buffer).toString();
let nativeCSS = !error && buffer && (new TextDecoder()).decode(buffer);
if (nativeCSS) {
let theme = BDFDB.DiscordUtils.getTheme();
let vars = (nativeCSS.split(`.${theme}{`)[1] || "").split("}")[0];
@ -922,7 +922,7 @@ module.exports = (_ => {
BDFDB.DiscordUtils.requestFileData(theme.rawSourceUrl, (error, buffer) => {
if (error || !buffer) theme.failed = true;
else {
let body = Buffer.from(buffer).toString();
let body = (new TextDecoder()).decode(buffer);
if (body && body.indexOf("404: Not Found") != 0) {
const META = body.split("*/")[0];
theme.name = BDFDB.StringUtils.upperCaseFirstChar((/@name\s+([^\t^\r^\n]+)|\/\/\**META.*["']name["']\s*:\s*["'](.+?)["']/i.exec(META) || []).filter(n => n)[1] || theme.name || "");
@ -968,7 +968,7 @@ module.exports = (_ => {
}
};
BDFDB.LibraryRequires.request("https://api.betterdiscord.app/v1/store/themes", (error, response, body) => {
BDFDB.LibraryRequires.request("https://api.betterdiscord.app/v1/store/themes", {bdVersion: true}, (error, response, body) => {
if (!error && body && response.statusCode == 200) try {
grabbedThemes = BDFDB.ArrayUtils.keySort(JSON.parse(body).filter(n => n), "name");
@ -1033,7 +1033,7 @@ module.exports = (_ => {
}
checkForNewThemes () {
BDFDB.LibraryRequires.request("https://api.betterdiscord.app/v1/store/themes", (error, response, body) => {
BDFDB.LibraryRequires.request("https://api.betterdiscord.app/v1/store/themes", {bdVersion: true}, (error, response, body) => {
if (!error && body) try {
if (JSON.parse(body).filter(n => n).length != grabbedThemes.length) {
loading = {is: false, timeout: null, amount: 0};