From f6f8d3200a6825b0bd3c58fec8b37c49d65d5f0e Mon Sep 17 00:00:00 2001 From: Matchu Date: Thu, 11 Mar 2021 06:38:03 -0800 Subject: [PATCH] Handle ?v= at the end of canvas library URL --- src/server/types/AppearanceLayer.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/server/types/AppearanceLayer.js b/src/server/types/AppearanceLayer.js index a4f2476..e453460 100644 --- a/src/server/types/AppearanceLayer.js +++ b/src/server/types/AppearanceLayer.js @@ -1,3 +1,5 @@ +import * as path from "path"; + import { gql } from "apollo-server"; import { loadAssetManifest } from "../neopets-assets"; @@ -203,15 +205,23 @@ const resolvers = { return null; } - const jsAssetDatum = asset.assetData.find((ad) => - ad.path.endsWith(".js") + const assetUrls = asset.assetData.map( + (ad) => new URL(ad.path, "http://images.neopets.com") ); - if (!jsAssetDatum) { + + const jsAssetUrl = assetUrls.find( + // NOTE: Sometimes the path ends with a ?v= query string, so we need + // to use `extname` to find the real extension! + // TODO: There's a file_ext field in the full manifest, but it's not + // included in our cached copy. That would probably be more + // reliable! + (url) => path.extname(url.pathname) === ".js" + ); + if (!jsAssetUrl) { return null; } - const url = new URL(jsAssetDatum.path, "http://images.neopets.com"); - return url.toString(); + return jsAssetUrl.toString(); }, item: async ({ id }, _, { db }) => { // TODO: If this becomes a popular request, we'll definitely need to