mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
lowercase username before comparing
This commit is contained in:
parent
41f0c5b3a3
commit
a5ddc9aced
1 changed files with 16 additions and 5 deletions
|
|
@ -133,17 +133,20 @@ export class NitterHandler extends ContentHandler {
|
|||
function parseTweet(tweet: Element): Tweet | null {
|
||||
const header = tweet.querySelector('.tweet-header')
|
||||
if (!header) {
|
||||
console.error('no header found', tweet)
|
||||
return null
|
||||
}
|
||||
const author = authorParser(header)
|
||||
|
||||
const body = tweet.querySelector('.tweet-body')
|
||||
if (!body) {
|
||||
console.error('no body found', tweet)
|
||||
return null
|
||||
}
|
||||
|
||||
const tweetDateElement = body.querySelector('.tweet-date a')
|
||||
if (!tweetDateElement) {
|
||||
console.error('no tweet date found', tweet)
|
||||
return null
|
||||
}
|
||||
const createdAt = dateParser(tweetDateElement)
|
||||
|
|
@ -151,6 +154,7 @@ export class NitterHandler extends ContentHandler {
|
|||
|
||||
const content = body.querySelector('.tweet-content')
|
||||
if (!content) {
|
||||
console.error('no content found', tweet)
|
||||
return null
|
||||
}
|
||||
const text = content.textContent ?? ''
|
||||
|
|
@ -195,7 +199,6 @@ export class NitterHandler extends ContentHandler {
|
|||
console.debug('latency', latency)
|
||||
|
||||
html = response.data as string
|
||||
console.debug('html', html)
|
||||
this.instance = instance
|
||||
|
||||
await this.incrementInstanceScore(redisClient, instance, latency)
|
||||
|
|
@ -215,6 +218,7 @@ export class NitterHandler extends ContentHandler {
|
|||
}
|
||||
}
|
||||
if (!this.instance || !html) {
|
||||
console.error('no instance or html found')
|
||||
return []
|
||||
}
|
||||
|
||||
|
|
@ -223,11 +227,16 @@ export class NitterHandler extends ContentHandler {
|
|||
// get the main thread including tweets and threads
|
||||
const mainThread = document.querySelector('.main-thread')
|
||||
if (!mainThread) {
|
||||
console.error('no main thread found')
|
||||
return []
|
||||
}
|
||||
const timelineItems = Array.from(
|
||||
mainThread.querySelectorAll('.timeline-item')
|
||||
)
|
||||
if (timelineItems.length === 0) {
|
||||
console.error('no timeline items found')
|
||||
return []
|
||||
}
|
||||
for (let i = 0; i < timelineItems.length; i++) {
|
||||
const item = timelineItems[i]
|
||||
const classList = item.classList
|
||||
|
|
@ -236,13 +245,14 @@ export class NitterHandler extends ContentHandler {
|
|||
classList.contains('unavailable') ||
|
||||
classList.contains('earlier-replies')
|
||||
) {
|
||||
console.debug('skip unavailable tweets and earlier replies', item)
|
||||
console.info('skip unavailable tweets and earlier replies')
|
||||
continue
|
||||
}
|
||||
// if there are more replies, get them
|
||||
if (classList.contains('more-replies')) {
|
||||
const newUrl = item.querySelector('a')?.getAttribute('href')
|
||||
if (!newUrl) {
|
||||
console.error('new url', newUrl)
|
||||
break
|
||||
}
|
||||
|
||||
|
|
@ -256,13 +266,14 @@ export class NitterHandler extends ContentHandler {
|
|||
|
||||
html = response.data as string
|
||||
} catch (error) {
|
||||
console.info('Error parsing html', error)
|
||||
console.error('Error getting tweets', error)
|
||||
break
|
||||
}
|
||||
|
||||
const document = parseHTML(html).document
|
||||
const nextThread = document.querySelector('.main-thread .after-tweet')
|
||||
if (!nextThread) {
|
||||
console.error('no next thread found')
|
||||
break
|
||||
}
|
||||
|
||||
|
|
@ -277,7 +288,7 @@ export class NitterHandler extends ContentHandler {
|
|||
|
||||
const tweet = parseTweet(item)
|
||||
// filter out replies
|
||||
if (tweet && tweet.author.username === username) {
|
||||
if (tweet && tweet.author.username.toLowerCase() === username) {
|
||||
tweets.push(tweet)
|
||||
}
|
||||
}
|
||||
|
|
@ -338,7 +349,7 @@ export class NitterHandler extends ContentHandler {
|
|||
)}`
|
||||
const description = _.escape(tweet.text)
|
||||
const imageDomain =
|
||||
domain === 'twitter.com'
|
||||
domain.toLowerCase() === 'twitter.com'
|
||||
? 'https://pbs.twimg.com'
|
||||
: 'https://nitter.net/pic'
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue