Try loading preset map from our domain

Sentry has lots (~200) of security errors where it looks like this (and
other) requests to third party domains fail. For some reason this one
appears more frequently than any others so I figured I'd try switching
it.

I'm not sure why. Maybe some overzealous security plugins have
distrusted unpkg?

I don't think this is a real fix, but I'm curious to see if it helps.
This commit is contained in:
Jordan Eldredge 2020-03-02 06:54:28 -08:00
parent ebd3eb56b6
commit 28062e3d09
3 changed files with 22 additions and 8 deletions

View file

@ -1,4 +1,4 @@
import { ButterchurnOptions } from "../../js/types";
import { ButterchurnOptions, Preset } from "../../js/types";
const KNOWN_PRESET_URLS_REGEXES = [
/^https:\/\/unpkg\.com\/butterchurn-presets\/.*\.json$/,
@ -20,14 +20,20 @@ function presetNameFromURL(url: string) {
}
}
async function loadButterchurnPresetMapURL(url: string) {
const resp = await fetch(url);
const namesToPresetUrls = await resp.json();
function restructureButterchurnPresetMap(namesToPresetUrls: {
[key: string]: string;
}): Preset[] {
return Object.keys(namesToPresetUrls).map((name: string) => {
return { name, butterchurnPresetUrl: namesToPresetUrls[name] };
});
}
async function loadButterchurnPresetMapURL(url: string) {
const resp = await fetch(url);
const namesToPresetUrls = await resp.json();
return restructureButterchurnPresetMap(namesToPresetUrls);
}
export function getButterchurnOptions(
startWithMilkdropHidden: boolean
): ButterchurnOptions {
@ -48,7 +54,7 @@ export function getButterchurnOptions(
},
presetConverterEndpoint:
"https://p2tpeb5v8b.execute-api.us-east-2.amazonaws.com/default/milkdropShaderConverter",
getPresets: async () => {
getPresets: async (): Promise<Preset[]> => {
if ("URLSearchParams" in window) {
const params = new URLSearchParams(location.search);
const butterchurnPresetUrlParam = params.get("butterchurnPresetUrl");
@ -89,10 +95,12 @@ export function getButterchurnOptions(
throw new Error("We still need to implement this");
}
}
// TODO: Fallback to some other presets?
return loadButterchurnPresetMapURL(
"https://unpkg.com/butterchurn-presets-weekly@0.0.2/weeks/week1/presets.json"
const presetMap = await import(
/* webpackChunkName: "milkdrop-presets-weekly" */
"butterchurn-presets-weekly/weeks/week1/presets.json"
);
return restructureButterchurnPresetMap(presetMap.default);
},
butterchurnOpen: !startWithMilkdropHidden,
};

View file

@ -152,6 +152,7 @@
"trailingComma": "es5"
},
"dependencies": {
"butterchurn-presets-weekly": "^0.0.4",
"eslint-plugin-react-hooks": "^2.1.2",
"fscreen": "^1.0.2",
"react-dropzone": "^10.1.7",

View file

@ -2734,6 +2734,11 @@ builtin-status-codes@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/builtin-status-codes/-/builtin-status-codes-3.0.0.tgz#85982878e21b98e1c66425e03d0174788f569ee8"
butterchurn-presets-weekly@^0.0.4:
version "0.0.4"
resolved "https://registry.yarnpkg.com/butterchurn-presets-weekly/-/butterchurn-presets-weekly-0.0.4.tgz#2ab8b8bc1f90269c8d6861ea734d27e2e6e52184"
integrity sha512-vEc7PgNSOOsYU4G72riAMCy3RidImgfsAYQJLchOI1bugVhXdkAqZzyLqh0aEqoZ7xTZC1xBQFHqLm6NbKfZjg==
butterchurn@^2.6.7:
version "2.6.7"
resolved "https://registry.yarnpkg.com/butterchurn/-/butterchurn-2.6.7.tgz#1ff0c1365731a4fb7ada7bb16ae1c6f09a110c12"