This commit is contained in:
Mirco Wittrien 2021-09-06 18:33:41 +02:00
parent 8f0758d9c2
commit c4510b4177
2 changed files with 28 additions and 22 deletions

View File

@ -2,7 +2,7 @@
* @name ImageUtilities * @name ImageUtilities
* @author DevilBro * @author DevilBro
* @authorId 278543574059057154 * @authorId 278543574059057154
* @version 4.4.6 * @version 4.4.7
* @description Adds several Utilities for Images/Videos (Gallery, Download, Reverse Search, Zoom, Copy, etc.) * @description Adds several Utilities for Images/Videos (Gallery, Download, Reverse Search, Zoom, Copy, etc.)
* @invite Jx3TjNS * @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien * @donate https://www.paypal.me/MircoWittrien
@ -17,12 +17,12 @@ module.exports = (_ => {
"info": { "info": {
"name": "ImageUtilities", "name": "ImageUtilities",
"author": "DevilBro", "author": "DevilBro",
"version": "4.4.6", "version": "4.4.7",
"description": "Adds several Utilities for Images/Videos (Gallery, Download, Reverse Search, Zoom, Copy, etc.)" "description": "Adds several Utilities for Images/Videos (Gallery, Download, Reverse Search, Zoom, Copy, etc.)"
}, },
"changeLog": { "changeLog": {
"fixed": { "fixed": {
"Double Zoom Lens": "No longer gets the zoom lens stuck on right click" "Invalid Images (Instagram)": "Fixed Issue where some Images could not be downloaded"
} }
} }
}; };
@ -624,7 +624,7 @@ module.exports = (_ => {
BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuItem, { BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuItem, {
label: BDFDB.LanguageUtils.LanguageStrings.OPEN_LINK, label: BDFDB.LanguageUtils.LanguageStrings.OPEN_LINK,
id: BDFDB.ContextMenuUtils.createItemId(this.name, "open-link"), id: BDFDB.ContextMenuUtils.createItemId(this.name, "open-link"),
action: _ => {BDFDB.DiscordUtils.openLink(urls.original);} action: _ => BDFDB.DiscordUtils.openLink(urls.original)
}), }),
BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuItem, { BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuItem, {
label: BDFDB.LanguageUtils.LanguageStrings.COPY_LINK, label: BDFDB.LanguageUtils.LanguageStrings.COPY_LINK,
@ -686,16 +686,12 @@ module.exports = (_ => {
BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuItem, { BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuItem, {
label: this.labels.context_saveas.replace("{{var0}}", type), label: this.labels.context_saveas.replace("{{var0}}", type),
id: BDFDB.ContextMenuUtils.createItemId(this.name, "download-file-as"), id: BDFDB.ContextMenuUtils.createItemId(this.name, "download-file-as"),
action: _ => { action: _ => this.downloadFileAs(urls.file, urls.src),
this.downloadFileAs(urls.file);
},
children: locations.length && BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuGroup, { children: locations.length && BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuGroup, {
children: locations.map((name, i) => BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuItem, { children: locations.map((name, i) => BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuItem, {
id: BDFDB.ContextMenuUtils.createItemId(this.name, "download", name, i), id: BDFDB.ContextMenuUtils.createItemId(this.name, "download", name, i),
label: name, label: name,
action: _ => { action: _ => this.downloadFile(urls.file, ownLocations[name].location, urls.src)
this.downloadFile(urls.file, ownLocations[name].location);
}
})) }))
}) })
}), }),
@ -1030,11 +1026,14 @@ module.exports = (_ => {
}; };
} }
downloadFile (url, path) { downloadFile (url, path, fallbackUrl) {
url = url.startsWith("/assets") ? (window.location.origin + url) : url; url = url.startsWith("/assets") ? (window.location.origin + url) : url;
BDFDB.LibraryRequires.request(url, {encoding: null}, (error, response, body) => { BDFDB.LibraryRequires.request(url, {encoding: null}, (error, response, body) => {
let type = this.isValid(url, "video") ? BDFDB.LanguageUtils.LanguageStrings.VIDEO : BDFDB.LanguageUtils.LanguageStrings.IMAGE; let type = this.isValid(url, "video") ? BDFDB.LanguageUtils.LanguageStrings.VIDEO : BDFDB.LanguageUtils.LanguageStrings.IMAGE;
if (error) BDFDB.NotificationUtils.toast(this.labels.toast_save_failed.replace("{{var0}}", type).replace("{{var1}}", path), {type: "danger"}); if (error || response.statusCode != 200) {
if (fallbackUrl) this.downloadFile(fallbackUrl, path);
else BDFDB.NotificationUtils.toast(this.labels.toast_save_failed.replace("{{var0}}", type).replace("{{var1}}", ""), {type: "danger"});
}
else { else {
BDFDB.LibraryRequires.fs.writeFile(this.getFileName(path, url.split("/").pop().split(".").slice(0, -1).join("."), response.headers["content-type"].split("/").pop().split("+")[0], 0), body, error => { BDFDB.LibraryRequires.fs.writeFile(this.getFileName(path, url.split("/").pop().split(".").slice(0, -1).join("."), response.headers["content-type"].split("/").pop().split("+")[0], 0), body, error => {
if (error) BDFDB.NotificationUtils.toast(this.labels.toast_save_failed.replace("{{var0}}", type).replace("{{var1}}", path), {type: "danger"}); if (error) BDFDB.NotificationUtils.toast(this.labels.toast_save_failed.replace("{{var0}}", type).replace("{{var1}}", path), {type: "danger"});
@ -1044,15 +1043,22 @@ module.exports = (_ => {
}); });
} }
downloadFileAs (url) { downloadFileAs (url, fallbackUrl) {
url = url.startsWith("/assets") ? (window.location.origin + url) : url; url = url.startsWith("/assets") ? (window.location.origin + url) : url;
BDFDB.LibraryRequires.request(url, {encoding: null}, (error, response, body) => { BDFDB.LibraryRequires.request(url, {encoding: null}, (error, response, body) => {
let hrefURL = window.URL.createObjectURL(new Blob([body])); let type = this.isValid(url, "video") ? BDFDB.LanguageUtils.LanguageStrings.VIDEO : BDFDB.LanguageUtils.LanguageStrings.IMAGE;
let tempLink = document.createElement("a"); if (error || response.statusCode != 200) {
tempLink.href = hrefURL; if (fallbackUrl) this.downloadFileAs(fallbackUrl);
tempLink.download = `${url.split("/").pop().split(".").slice(0, -1).join(".") || "unknown"}.${response.headers["content-type"].split("/").pop().split("+")[0]}`; else BDFDB.NotificationUtils.toast(this.labels.toast_save_failed.replace("{{var0}}", type).replace("{{var1}}", ""), {type: "danger"});
tempLink.click(); }
window.URL.revokeObjectURL(hrefURL); else {
let hrefURL = window.URL.createObjectURL(new Blob([body]));
let tempLink = document.createElement("a");
tempLink.href = hrefURL;
tempLink.download = `${url.split("/").pop().split(".").slice(0, -1).join(".") || "unknown"}.${response.headers["content-type"].split("/").pop().split("+")[0]}`;
tempLink.click();
window.URL.revokeObjectURL(hrefURL);
}
}); });
} }
@ -1138,7 +1144,7 @@ module.exports = (_ => {
createImageWrapper (instance, imgRef, type, svgIcon) { createImageWrapper (instance, imgRef, type, svgIcon) {
return BDFDB.ReactUtils.createElement("div", { return BDFDB.ReactUtils.createElement("div", {
className: BDFDB.disCNS._imageutilitiessibling + BDFDB.disCN[`_imageutilities${type}`], className: BDFDB.disCNS._imageutilitiessibling + BDFDB.disCN[`_imageutilities${type}`],
onClick: _ => {this.switchImages(instance, type);}, onClick: _ => this.switchImages(instance, type),
children: [ children: [
imgRef, imgRef,
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SvgIcon, { BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SvgIcon, {

View File

@ -431,7 +431,7 @@ module.exports = (_ => {
case "bg": // Bulgarian case "bg": // Bulgarian
return { return {
management: "Управление", management: "Управление",
creator: "{{var0}} създател" creator: "Cъздател {{var0}}"
}; };
case "cs": // Czech case "cs": // Czech
return { return {
@ -531,7 +531,7 @@ module.exports = (_ => {
case "ru": // Russian case "ru": // Russian
return { return {
management: "Управление", management: "Управление",
creator: "{{var0}} создатель" creator: "Cоздатель {{var0}}"
}; };
case "sv": // Swedish case "sv": // Swedish
return { return {