From 027e5604361548c24c2f7779f5c4c0def47ee1a0 Mon Sep 17 00:00:00 2001 From: Patrick Trumpis Date: Sat, 29 Jul 2023 23:53:20 +0200 Subject: [PATCH] Improved UUID and share link search --- src/endpoints/search.js | 2 +- src/utils/helper.js | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/endpoints/search.js b/src/endpoints/search.js index cc9e7b4..7c3e071 100644 --- a/src/endpoints/search.js +++ b/src/endpoints/search.js @@ -23,7 +23,7 @@ router.post('/', async function (req, res, next) { searchResults = Util.modifyResponseURLs(searchResults); // hashtag search (not supported by relay or web) - if (searchTerm.startsWith('#') && searchResults.length) { + if (searchTerm.startsWith('#')) { return res.json({ "lenses": searchResults }); } } diff --git a/src/utils/helper.js b/src/utils/helper.js index 6151f44..4c9f6bc 100644 --- a/src/utils/helper.js +++ b/src/utils/helper.js @@ -178,21 +178,30 @@ function parseLensUuid(str) { if (typeof str === "string") { let uuid = ''; try { + // try to extract from known urls + // otherwise use global extraction attempt below if (str.startsWith("https://lens.snapchat.com/")) { let webUrl = new URL(str); uuid = webUrl.pathname.replace(/^\/+/, ''); } else if (str.startsWith("https://www.snapchat.com/unlock/?")) { - let deeplinkURL = new URL(str); - uuid = deeplinkURL.searchParams.get('uuid') + let deeplinkURL = new URL(str.replaceAll('\u0026', '&')); // json encoding fix + if (deeplinkURL.searchParams.has('uuid')) { + uuid = deeplinkURL.searchParams.get('uuid') + } + } + + if (uuid) { + return parseLensUuid(uuid); } } catch (e) { console.error(e, str); } - // UUID's have 32 characters - const regUuid = /^[a-f0-9]{32}$/gi; - if (regUuid.test(uuid)) { - return uuid; + // global extraction attempt + // UUID's have 32 hexadecimal characters + uuid = str.match(/[a-f0-9]{32}/gi) + if (uuid && uuid[0]) { + return uuid[0]; } }