Skip to content

Commit

Permalink
[lastfm] remove use of webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowsink committed Apr 25, 2024
1 parent a716cde commit 64db941
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 12 deletions.
52 changes: 51 additions & 1 deletion plugins/lastfm/assets.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,55 @@
import { webpackChunk, createApi } from "@cumjar/websmack";
import { DISCORD_APP_ID } from "./cfg";

/*
example exchange made by the real fetchAssetIds function:
###
POST https://discord.com/api/v9/applications/1107251687984472144/external-assets HTTP/2
> Content-Type: application/json
> headers: go here
{"urls":["https://coverartarchive.org/release/d131c1ab-ffe1-4f68-941d-c1c238a91f50/front"]}
###
HTTP/2 200
> headers: go here
[
{
"url": "https://coverartarchive.org/release/d131c1ab-ffe1-4f68-941d-c1c238a91f50/front",
"external_asset_path": "external/BXbyYaCdwy2DMWxTRmsvqVHDvXgf6LQmzgTwVRIBass/https/coverartarchive.org/release/d131c1ab-ffe1-4f68-941d-c1c238a91f50/front"
}
]
*/

const { post } = shelter.http;

const cache = new Map<string, string | undefined>();

export async function getAsset(url: string) {
if (cache.has(url)) {
return cache.get(url);
}

const res = await post({
url: `/applications/${DISCORD_APP_ID}/external-assets`,
body: JSON.stringify({ urls: [url] }),
oldFormErrors: false,
headers: {
"Content-Type": "application/json",
},
});

if (res.ok) {
const path = JSON.parse(res.body)[0].external_asset_path;
cache.set(url, path);
return path;
}
cache.set(url, undefined);
}

/*import { webpackChunk, createApi } from "@cumjar/websmack";
const modules = webpackChunk();
const api = modules && createApi([undefined, ...modules]);
Expand All @@ -15,3 +64,4 @@ export const getAsset = (url: string): Promise<string> =>
!mod.fetchAssetIds
? undefined
: mod.fetchAssetIds(DISCORD_APP_ID, [url, undefined]).then((v) => v[0]);
*/
1 change: 0 additions & 1 deletion plugins/lastfm/package.json

This file was deleted.

10 changes: 0 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 64db941

Please sign in to comment.