Skip to content

Commit

Permalink
Use new proxy for DDB content, otherwise, dont
Browse files Browse the repository at this point in the history
  • Loading branch information
MrPrimate committed Apr 6, 2021
1 parent bf77604 commit 5c8e392
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ export function init() {
type: Number,
default: 400,
});

game.settings.register("vtta-tokenizer", "proxy", {
scope: "world",
config: false,
type: String,
default: "https://london.drop.mrprimate.co.uk/",
});
}

export function ready() {
Expand Down
23 changes: 21 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,31 @@ export default class Utils {
});
}

/**
* Should the image use the proxy?
* @param {*} url
*/
static useProxy(url) {
if (
url.toLowerCase().startsWith("https://www.dndbeyond.com/") ||
url.toLowerCase().startsWith("https://dndbeyond.com/") ||
url.toLowerCase().startsWith("https://media-waterdeep.cursecdn.com/")
) {
return true;
} else {
return false;
}
}

/**
* Downloads an image from a given URL
* @param {String} url URL of the image that we try to download
*/
static download(url) {
static async download(url) {
if (!url) url = "icons/mystery-man.png";
const proxy = await game.settings.get("vtta-tokenizer", "proxy");
const useProxy = Utils.useProxy(url);
console.log(`Proxy for ${img}: ${useProxy}`);
return new Promise((resolve, reject) => {
let img = new Image();
img.crossOrigin = "Anonymous";
Expand All @@ -65,7 +84,7 @@ export default class Utils {
img.addEventListener("error", event => {
reject(event);
});
let imgSrc = url.toLowerCase().indexOf("http") === 0 ? "https://proxy.iungimus.de/get/" + url : url;
let imgSrc = useProxy ? proxy + url : url;
img.src = imgSrc;
});
}
Expand Down

0 comments on commit 5c8e392

Please sign in to comment.