Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try loading preset map from our domain #972

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions demo/js/butterchurnOptions.ts
Original file line number Diff line number Diff line change
@@ -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$/,
Expand All @@ -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 {
Expand All @@ -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");
Expand Down Expand Up @@ -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/[email protected]/weeks/week1/presets.json"

const presetMap = await import(
/* webpackChunkName: "milkdrop-presets-weekly" */
"butterchurn-presets-weekly/weeks/week1/presets.json"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets take this change to point to "week" 2 : weeks/week2/presets.json

);
return restructureButterchurnPresetMap(presetMap.default);
},
butterchurnOpen: !startWithMilkdropHidden,
};
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down