Skip to content

Commit

Permalink
Improved UUID and share link search
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrumpis committed Jul 29, 2023
1 parent 2e6bc11 commit 027e560
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/endpoints/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
}
Expand Down
21 changes: 15 additions & 6 deletions src/utils/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}

Expand Down

0 comments on commit 027e560

Please sign in to comment.