diff --git a/Library/0BDFDB.plugin.js b/Library/0BDFDB.plugin.js index aeb1bb3310..8582b961ec 100644 --- a/Library/0BDFDB.plugin.js +++ b/Library/0BDFDB.plugin.js @@ -2,7 +2,7 @@ * @name BDFDB * @author DevilBro * @authorId 278543574059057154 - * @version 3.5.1 + * @version 3.5.2 * @description Required Library for DevilBro's Plugins * @invite Jx3TjNS * @donate https://www.paypal.me/MircoWittrien @@ -27,7 +27,9 @@ module.exports = (_ => { BDFDB = { started: true, changeLog: { - + fixed: { + "Special Characters": "Fixed an Issue, which caused downloaded Files (for example Plugins downloaded via Plugin Repo) to have their special characters (polish, chinese, etc. letters) get corrupted" + } } }; @@ -154,9 +156,9 @@ module.exports = (_ => { }; const requestFunction = function (...args) { - let {url, uIndex} = args[0] && typeof args[0] == "string" ? {url: args[0], uIndex: 0} : (args[1] && typeof args[1] == "object" && typeof args[1].url == "string" ? {url: args[1], uIndex: 1} : {url: null, uIndex: -1}); - if (!url || typeof url != "string") return; - let {callback, cIndex} = args[1] && typeof args[1] == "function" ? {callback: args[1], cIndex: 1} : (args[2] && typeof args[2] == "function" ? {callback: args[2], cIndex: 2} : {callback: null, cIndex: -1}); + let url = typeof args[0] == "string" && args[0]; + if (!url) return; + let callback = typeof args[1] == "function" && args[1] || typeof args[2] == "function" && args[2]; if (typeof callback != "function") return; if (url.indexOf("data:") == 0) callback(null, { aborted: false, @@ -170,15 +172,14 @@ module.exports = (_ => { url: "" }, url); else { - let config = args[0] && typeof args[0] == "object" ? args[0] : (args[1] && typeof args[1] == "object" && args[1]); + let config = 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") { + if (!isNaN(parseInt(config.timeout)) && config.timeout > 0) timeout = config.timeout; + if (config.form && typeof config.form == "object") { let query = Object.entries(config.form).map(n => n[0] + "=" + n[1]).join("&"); 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(); + if (config.method) config.method = config.method.toUpperCase(); let killed = false, timeoutObj = BDFDB.TimeUtils.timeout(_ => { killed = true; BDFDB.TimeUtils.clear(timeoutObj); @@ -194,9 +195,10 @@ module.exports = (_ => { url: "" }, null); }, timeout); - let response = null; - return (config && config.bdVersion && BdApi && BdApi.Net && BdApi.Net.fetch ? BdApi.Net.fetch : fetch)(url, Object.assign({}, config, {timeout: 60000})).catch(error => { - callback(new Error(error), { + let response = null, isFallback = false; + return (config.bdVersion && BdApi && BdApi.Net && BdApi.Net.fetch ? BdApi.Net.fetch : fetch)(url, config).catch(error => { + if (!config.bdVersion) requestFunction(url, Object.assign({}, config, {bdVersion: true}), callback); + else callback(new Error(error), { aborted: false, complete: true, end: undefined, @@ -213,7 +215,7 @@ module.exports = (_ => { response.statusCode = response.status; if (response.headers) response.headers["content-type"] = response.headers.get("content-type"); BDFDB.TimeUtils.clear(timeoutObj); - return response.text(); + return config.toBuffer ? response.arrayBuffer() : response.text(); }).then(body => { if (!killed && response) callback(response.status != 200 ? new Error(response.statusText || "Fetch Failed") : null, response, body); }); @@ -4261,151 +4263,6 @@ module.exports = (_ => { }; BDFDB.DiscordUtils = {}; - var getFileData = (...args) => { - var p = function (e, t, n, r, i, o, a) { - try { - var s = e[o](a), - u = s.value; - } catch (e) { - n(e); - return; - } - s.done ? t(u) : Promise.resolve(u).then(r, i); - }; - var E = function (e) { - return function () { - var t = this, - n = arguments; - return new Promise((function (r, i) { - var o = e.apply(t, n); - function a(e) { - p(o, r, i, a, s, "next", e); - } - function s(e) { - p(o, r, i, a, s, "throw", e); - } - a(void 0); - })); - }; - }; - return E(function (e) { - const v = function (e, t) { - var s = function (o) { - return function (s) { - return function (o) { - if (n) throw new TypeError("Generator is already executing."); - for (; a; ) try { - if (n = 1, r && (i = 2 & o[0] ? r.return : o[0] ? r.throw || ((i = r.return) && i.call(r), 0) : r.next) && !(i = i.call(r, o[1])).done) return i; - (r = 0, i) && (o = [2 & o[0], i.value]); - switch (o[0]) { - case 0: - case 1: - i = o; - break; - case 4: - a.label++; - return { - value: o[1], - done: !1 - }; - case 5: - a.label++; - r = o[1]; - o = [0]; - continue; - case 7: - o = a.ops.pop(); - a.trys.pop(); - continue; - default: - if (!(i = a.trys, i = i.length > 0 && i[i.length - 1]) && (6 === o[0] || 2 === o[0])) { - a = 0; - continue; - } - if (3 === o[0] && (!i || o[1] > i[0] && o[1] < i[3])) { - a.label = o[1]; - break; - } - if (6 === o[0] && a.label < i[1]) { - a.label = i[1]; - i = o; - break; - } - if (i && a.label < i[2]) { - a.label = i[2]; - a.ops.push(o); - break; - } - i[2] && a.ops.pop(); - a.trys.pop(); - continue; - } - o = t.call(e, a); - } catch (e) { - o = [6, e]; - r = 0; - } finally { - n = i = 0; - } - if (5 & o[0]) throw o[1]; - return { - value: o[0] ? o[1] : void 0, - done: !0 - } - }([o, s]) - } - } - - var n, r, i, o; - var a = { - label: 0, - sent: function () { - if (1 & i[0]) - throw i[1]; - return i[1] - }, - trys: [], - ops: [] - }; - return o = { - next: s(0), - throw : s(1), - return : s(2) - }, "function" == typeof Symbol && (o[Symbol.iterator] = function () { - return this - }), o; - }; - return v(this, (function (r) { - var t, n; - switch (r.label) { - case 0: - return [4, fetch(new Request(e, { - method: "GET", - mode: "cors" - }))]; - case 1: - t = r.sent(); - return [4, t.arrayBuffer()]; - case 2: - n = r.sent(); - return [2, n] - } - })); - }).apply(this, args); - }; - BDFDB.DiscordUtils.requestFileData = function (...args) { - let {url, uIndex} = args[0] && typeof args[0] == "string" ? {url: args[0], uIndex: 0} : (args[1] && typeof args[1] == "object" && typeof args[1].url == "string" ? {url: args[1], uIndex: 1} : {url: null, uIndex: -1}); - if (!url || typeof url != "string") return; - let {callback, cIndex} = args[1] && typeof args[1] == "function" ? {callback: args[1], cIndex: 1} : (args[2] && typeof args[2] == "function" ? {callback: args[2], cIndex: 2} : {callback: null, cIndex: -1}); - if (typeof callback != "function") return; - getFileData(url).then(buffer => callback(null, buffer)).catch(error => callback(error, null)); - }; - BDFDB.DiscordUtils.bufferToString = function (u8a) { - u8a = new Uint8Array(u8a); - let CHUNK_SZ = 0x8000, c = []; - for (let i = 0; i < u8a.length; i += CHUNK_SZ) c.push(String.fromCharCode.apply(null, u8a.subarray(i, i + CHUNK_SZ))); - return c.join(""); - }; BDFDB.DiscordUtils.getSetting = function (category, key) { if (!category || !key) return; return BDFDB.LibraryStores.UserSettingsProtoStore && BDFDB.LibraryStores.UserSettingsProtoStore.settings[category] && BDFDB.LibraryStores.UserSettingsProtoStore.settings[category][key] && BDFDB.LibraryStores.UserSettingsProtoStore.settings[category][key].value; diff --git a/Plugins/ImageUtilities/ImageUtilities.plugin.js b/Plugins/ImageUtilities/ImageUtilities.plugin.js index a3dd39d815..4e0f78be6b 100644 --- a/Plugins/ImageUtilities/ImageUtilities.plugin.js +++ b/Plugins/ImageUtilities/ImageUtilities.plugin.js @@ -2,7 +2,7 @@ * @name ImageUtilities * @author DevilBro * @authorId 278543574059057154 - * @version 5.3.1 + * @version 5.3.3 * @description Adds several Utilities for Images/Videos (Gallery, Download, Reverse Search, Zoom, Copy, etc.) * @invite Jx3TjNS * @donate https://www.paypal.me/MircoWittrien @@ -1497,18 +1497,10 @@ module.exports = (_ => { let isResized = !config.orignalSizeChecked && (url.indexOf("?width=") > -1 || url.indexOf("?height=") > -1 || url.indexOf("?size=") > -1); url = isResized ? this.removeSizeInUrl(url) : url; url = url.indexOf("discordapp.com/avatars/") > 0 || url.indexOf("discordapp.com/icons/") > 0 ? `${url}?size=4096` : url; - if (!config.fallbackToRequest) BDFDB.DiscordUtils.requestFileData(url, (error, buffer) => { - if (error || !buffer) { - if (isResized) this.requestFile(urls, onLoad, onError, {orignalSizeChecked: true}); - else if (urls.fallbackUrl && urls.url != urls.fallbackUrl) this.requestFile({url: urls.fallbackUrl, oldUrl: urls.url}, onLoad, onError); - else this.requestFile({url: urls.oldUrl || urls.url, fallbackUrl: urls.oldUrl ? urls.url : undefined}, onLoad, onError, {fallbackToRequest: true}); - } - else onLoad(url, buffer); - }); - else BDFDB.LibraryRequires.request(url, {agentOptions: {rejectUnauthorized: false}, headers: {"Content-Type": "application/json"}}, (error, response, buffer) => { + BDFDB.LibraryRequires.request(url, {toBuffer: true}, (error, response, buffer) => { if (error || response.statusCode != 200 || response.headers["content-type"].indexOf("text/html") > -1) { - if (isResized) this.requestFile(urls, onLoad, onError, {orignalSizeChecked: true, fallbackToRequest: true}); - else if (urls.fallbackUrl && urls.url != urls.fallbackUrl) this.requestFile({url: urls.fallbackUrl}, onLoad, onError, {fallbackToRequest: true}); + if (isResized) this.requestFile(urls, onLoad, onError, {orignalSizeChecked: true}); + else if (urls.fallbackUrl && urls.url != urls.fallbackUrl) this.requestFile({url: urls.fallbackUrl}, onLoad, onError); else if (typeof onError == "function") onError(); } else onLoad(url, buffer); @@ -1540,7 +1532,7 @@ module.exports = (_ => { } copyFile (urls) { - this.requestFile(urls, (url, buffer) => { + this.requestFile(urls, url => { let type = this.isValid(url, "video") ? BDFDB.LanguageUtils.LanguageStrings.VIDEO : BDFDB.LanguageUtils.LanguageStrings.IMAGE; BDFDB.LibraryModules.WindowUtils.copyImage(url); BDFDB.NotificationUtils.toast(this.labels.toast_copy_success.replace("{{var0}}", type), {type: "success"}); diff --git a/Plugins/PluginRepo/PluginRepo.plugin.js b/Plugins/PluginRepo/PluginRepo.plugin.js index 5285b8715d..09da84f6b1 100644 --- a/Plugins/PluginRepo/PluginRepo.plugin.js +++ b/Plugins/PluginRepo/PluginRepo.plugin.js @@ -2,7 +2,7 @@ * @name PluginRepo * @author DevilBro * @authorId 278543574059057154 - * @version 2.5.3 + * @version 2.5.4 * @description Allows you to download all Plugins from BD's Website within Discord * @invite Jx3TjNS * @donate https://www.paypal.me/MircoWittrien @@ -14,9 +14,7 @@ module.exports = (_ => { const changeLog = { - "fixed": { - "Outdated for broken Plugins": "No longer shows broken Plugins as outdated" - } + }; return !window.BDFDB_Global || (!window.BDFDB_Global.loaded && !window.BDFDB_Global.started) ? class { @@ -486,13 +484,13 @@ module.exports = (_ => { this.props.downloading = true; let loadingToast = BDFDB.NotificationUtils.toast(`${BDFDB.LanguageUtils.LibraryStringsFormat("loading", this.props.data.name)} - ${BDFDB.LanguageUtils.LibraryStrings.please_wait}`, {timeout: 0, ellipsis: true}); let autoloadKey = this.props.data.state == pluginStates.OUTDATED ? "startUpdated" : "startDownloaded"; - BDFDB.DiscordUtils.requestFileData(this.props.data.rawSourceUrl, (error, buffer) => { - if (error || !buffer) { + BDFDB.LibraryRequires.request(this.props.data.rawSourceUrl, (error, response, body) => { + if (error || !body) { delete this.props.downloading; 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()), BDFDB.DiscordUtils.bufferToString(buffer), error2 => { + else BDFDB.LibraryRequires.fs.writeFile(BDFDB.LibraryRequires.path.join(BDFDB.BDUtils.getPluginsFolder(), this.props.data.rawSourceUrl.split("/").pop()), body, error2 => { delete this.props.downloading; loadingToast.close(); if (error2) BDFDB.NotificationUtils.toast(BDFDB.LanguageUtils.LibraryStringsFormat("save_fail", `Plugin "${this.props.data.name}"`), {type: "danger"}); @@ -758,20 +756,17 @@ module.exports = (_ => { delete plugin.release_date; delete plugin.latest_source_url; delete plugin.thumbnail_url; - BDFDB.DiscordUtils.requestFileData(plugin.rawSourceUrl, (error, buffer) => { - if (error || !buffer) plugin.failed = true; + BDFDB.LibraryRequires.request(plugin.rawSourceUrl, (error, response, body) => { + if (error || !body || body.indexOf("404: Not Found") == 0) plugin.failed = true; else { - let body = BDFDB.DiscordUtils.bufferToString(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 || ""); - plugin.authorname = (/@author\s+(.+)|\/\/\**META.*["']author["']\s*:\s*["'](.+?)["']/i.exec(META) || []).filter(n => n)[1] || plugin.author.display_name || plugin.author; - const version = (/@version\s+(.+)|\/\/\**META.*["']version["']\s*:\s*["'](.+?)["']/i.exec(META) || []).filter(n => n)[1]; - if (version) { - plugin.version = version; - const installedPlugin = this.getInstalledPlugin(plugin); - if (installedPlugin && this.compareVersions(version, this.getString(installedPlugin.plugin && installedPlugin.plugin.version || installedPlugin.version))) outdatedEntries++; - } + 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 || ""); + plugin.authorname = (/@author\s+(.+)|\/\/\**META.*["']author["']\s*:\s*["'](.+?)["']/i.exec(META) || []).filter(n => n)[1] || plugin.author.display_name || plugin.author; + const version = (/@version\s+(.+)|\/\/\**META.*["']version["']\s*:\s*["'](.+?)["']/i.exec(META) || []).filter(n => n)[1]; + if (version) { + plugin.version = version; + const installedPlugin = this.getInstalledPlugin(plugin); + if (installedPlugin && this.compareVersions(version, this.getString(installedPlugin.plugin && installedPlugin.plugin.version || installedPlugin.version))) outdatedEntries++; } if (!cachedPlugins.includes(plugin.id)) newEntries++; } diff --git a/Plugins/ThemeRepo/ThemeRepo.plugin.js b/Plugins/ThemeRepo/ThemeRepo.plugin.js index cc887a3a62..25b101ab09 100644 --- a/Plugins/ThemeRepo/ThemeRepo.plugin.js +++ b/Plugins/ThemeRepo/ThemeRepo.plugin.js @@ -2,7 +2,7 @@ * @name ThemeRepo * @author DevilBro * @authorId 278543574059057154 - * @version 2.5.2 + * @version 2.5.4s * @description Allows you to download all Themes from BD's Website within Discord * @invite Jx3TjNS * @donate https://www.paypal.me/MircoWittrien @@ -632,13 +632,13 @@ module.exports = (_ => { this.props.downloading = true; let loadingToast = BDFDB.NotificationUtils.toast(`${BDFDB.LanguageUtils.LibraryStringsFormat("loading", this.props.data.name)} - ${BDFDB.LanguageUtils.LibraryStrings.please_wait}`, {timeout: 0, ellipsis: true}); let autoloadKey = this.props.data.state == themeStates ? "startUpdated" : "startDownloaded"; - BDFDB.DiscordUtils.requestFileData(this.props.data.rawSourceUrl, (error, buffer) => { - if (error || !buffer) { + BDFDB.LibraryRequires.request(this.props.data.rawSourceUrl, (error, response, body) => { + if (error || !body) { delete this.props.downloading; 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(), BDFDB.DiscordUtils.bufferToString(buffer), autoloadKey).then(error2 => { + else list.createThemeFile(this.props.data.name, this.props.data.rawSourceUrl.split("/").pop(), body, autoloadKey).then(error2 => { delete this.props.downloading; loadingToast.close(); if (!error2) { @@ -885,16 +885,15 @@ module.exports = (_ => { }); } - BDFDB.DiscordUtils.requestFileData("https://mwittrien.github.io/BetterDiscordAddons/Plugins/ThemeRepo/_res/GeneratorList.txt", (error, buffer) => { - let body = !error && buffer && BDFDB.DiscordUtils.bufferToString(buffer); - if (body) for (let id of body.replace(/[\r\t]/g, "").split(" ").map(n => parseInt(n)).filter(n => n != null)) { + BDFDB.LibraryRequires.request("https://mwittrien.github.io/BetterDiscordAddons/Plugins/ThemeRepo/_res/GeneratorList.txt", (error, response, body) => { + if (!error && 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); } }); - BDFDB.DiscordUtils.requestFileData(document.querySelector("head link[rel='stylesheet'][integrity]").href, (error, buffer) => { - let nativeCSS = !error && buffer && BDFDB.DiscordUtils.bufferToString(buffer); + BDFDB.LibraryRequires.request(document.querySelector("head link[rel='stylesheet'][href*='assets/app.'], body link[rel='stylesheet'][href*='assets/app.']").href, (error, response, body) => { + let nativeCSS = !error && body; if (nativeCSS) { let theme = BDFDB.DiscordUtils.getTheme(); let vars = (nativeCSS.split(`.${theme}{`)[1] || "").split("}")[0]; @@ -919,41 +918,38 @@ module.exports = (_ => { delete theme.release_date; delete theme.latest_source_url; delete theme.thumbnail_url; - BDFDB.DiscordUtils.requestFileData(theme.rawSourceUrl, (error, buffer) => { - if (error || !buffer) theme.failed = true; + BDFDB.LibraryRequires.request(theme.rawSourceUrl, (error, response, body) => { + if (error || !body || body.indexOf("404: Not Found") == 0) theme.failed = true; else { - let body = BDFDB.DiscordUtils.bufferToString(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 || ""); - theme.authorname = (/@author\s+(.+)|\/\/\**META.*["']author["']\s*:\s*["'](.+?)["']/i.exec(META) || []).filter(n => n)[1] || theme.author.display_name || theme.author; - const version = (/@version\s+(.+)|\/\/\**META.*["']version["']\s*:\s*["'](.+?)["']/i.exec(META) || []).filter(n => n)[1]; - if (version) theme.version = version; - if (theme.version) { - const installedTheme = this.getInstalledTheme(theme); - if (installedTheme && this.compareVersions(version, this.getString(installedTheme.version))) outdatedEntries++; - } - let text = body.trim(); - let hasMETAline = text.replace(/\s/g, "").indexOf("//META{"), newMeta = ""; - if (hasMETAline < 20 && hasMETAline > -1) { - let i = 0, j = 0, metaString = ""; - try { - for (let c of `{${text.split("{").slice(1).join("{")}`) { - metaString += c; - if (c == "{") i++; - else if (c == "}") j++; - if (i > 0 && i == j) break; - } - let metaObj = JSON.parse(metaString); - newMeta = "/**\n"; - for (let key in metaObj) newMeta += ` * @${key} ${metaObj[key]}\n`; - newMeta += "*/"; - } - catch (err) {newMeta = "";} - } - theme.fullCSS = [newMeta, newMeta ? text.split("\n").slice(1).join("\n") : text].filter(n => n).join("\n"); - theme.css = (hasMETAline < 20 && hasMETAline > -1 ? text.split("\n").slice(1).join("\n") : text).replace(/[\r|\n|\t]/g, ""); + 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 || ""); + theme.authorname = (/@author\s+(.+)|\/\/\**META.*["']author["']\s*:\s*["'](.+?)["']/i.exec(META) || []).filter(n => n)[1] || theme.author.display_name || theme.author; + const version = (/@version\s+(.+)|\/\/\**META.*["']version["']\s*:\s*["'](.+?)["']/i.exec(META) || []).filter(n => n)[1]; + if (version) theme.version = version; + if (theme.version) { + const installedTheme = this.getInstalledTheme(theme); + if (installedTheme && this.compareVersions(version, this.getString(installedTheme.version))) outdatedEntries++; } + let text = body.trim(); + let hasMETAline = text.replace(/\s/g, "").indexOf("//META{"), newMeta = ""; + if (hasMETAline < 20 && hasMETAline > -1) { + let i = 0, j = 0, metaString = ""; + try { + for (let c of `{${text.split("{").slice(1).join("{")}`) { + metaString += c; + if (c == "{") i++; + else if (c == "}") j++; + if (i > 0 && i == j) break; + } + let metaObj = JSON.parse(metaString); + newMeta = "/**\n"; + for (let key in metaObj) newMeta += ` * @${key} ${metaObj[key]}\n`; + newMeta += "*/"; + } + catch (err) {newMeta = "";} + } + theme.fullCSS = [newMeta, newMeta ? text.split("\n").slice(1).join("\n") : text].filter(n => n).join("\n"); + theme.css = (hasMETAline < 20 && hasMETAline > -1 ? text.split("\n").slice(1).join("\n") : text).replace(/[\r|\n|\t]/g, ""); if (!cachedThemes.includes(theme.id)) newEntries++; }