Skip to content

Commit 027e560

Browse files
committed
Improved UUID and share link search
1 parent 2e6bc11 commit 027e560

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

src/endpoints/search.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ router.post('/', async function (req, res, next) {
2323
searchResults = Util.modifyResponseURLs(searchResults);
2424

2525
// hashtag search (not supported by relay or web)
26-
if (searchTerm.startsWith('#') && searchResults.length) {
26+
if (searchTerm.startsWith('#')) {
2727
return res.json({ "lenses": searchResults });
2828
}
2929
}

src/utils/helper.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,21 +178,30 @@ function parseLensUuid(str) {
178178
if (typeof str === "string") {
179179
let uuid = '';
180180
try {
181+
// try to extract from known urls
182+
// otherwise use global extraction attempt below
181183
if (str.startsWith("https://lens.snapchat.com/")) {
182184
let webUrl = new URL(str);
183185
uuid = webUrl.pathname.replace(/^\/+/, '');
184186
} else if (str.startsWith("https://www.snapchat.com/unlock/?")) {
185-
let deeplinkURL = new URL(str);
186-
uuid = deeplinkURL.searchParams.get('uuid')
187+
let deeplinkURL = new URL(str.replaceAll('\u0026', '&')); // json encoding fix
188+
if (deeplinkURL.searchParams.has('uuid')) {
189+
uuid = deeplinkURL.searchParams.get('uuid')
190+
}
191+
}
192+
193+
if (uuid) {
194+
return parseLensUuid(uuid);
187195
}
188196
} catch (e) {
189197
console.error(e, str);
190198
}
191199

192-
// UUID's have 32 characters
193-
const regUuid = /^[a-f0-9]{32}$/gi;
194-
if (regUuid.test(uuid)) {
195-
return uuid;
200+
// global extraction attempt
201+
// UUID's have 32 hexadecimal characters
202+
uuid = str.match(/[a-f0-9]{32}/gi)
203+
if (uuid && uuid[0]) {
204+
return uuid[0];
196205
}
197206
}
198207

0 commit comments

Comments
 (0)