Use normalized URLs when querying article saving requests

When we save pages we save the normalized URL, so if a user saves
a URL like https://foo.com/ in elastic it will be saved as
https://foo.com but the browser will redirect to this url:

https://omnivore.app/article?url=https://foo.com/ and the URL
lookup will fail.
This commit is contained in:
Jackson Harper
2023-06-16 15:15:22 +08:00
parent 1ea0291e75
commit cf7c50468e

View File

@ -1,4 +1,5 @@
/* eslint-disable prefer-const */
import normalizeUrl from 'normalize-url'
import { getPageByParam } from '../../elastic/pages'
import { User } from '../../entity/user'
import { getRepository } from '../../entity/utils'
@ -73,9 +74,17 @@ export const articleSavingRequestResolver = authorized<
if (!user) {
return { errorCodes: [ArticleSavingRequestErrorCode.Unauthorized] }
}
const normalizedUrl = url
? normalizeUrl(url, {
stripHash: true,
stripWWW: false,
})
: undefined
const params = {
_id: id || undefined,
url: url || undefined,
url: normalizedUrl,
userId: claims.uid,
state: [
ArticleSavingRequestStatus.Succeeded,