mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
fix pocket paginated api
This commit is contained in:
parent
fab9064696
commit
0d8a3f7346
3 changed files with 28 additions and 9 deletions
|
|
@ -228,16 +228,19 @@ export function integrationsServiceRouter() {
|
|||
})
|
||||
stringifier.pipe(writeStream)
|
||||
|
||||
let hasMore = true
|
||||
let offset = 0
|
||||
let since = integration.syncedAt?.getTime() || 0
|
||||
while (hasMore) {
|
||||
const since = integration.syncedAt?.getTime() || 0
|
||||
let syncedAt = since
|
||||
// eslint-disable-next-line no-constant-condition
|
||||
while (true) {
|
||||
// get pages from integration
|
||||
const retrieved = await integrationService.retrieve({
|
||||
token: integration.token,
|
||||
since,
|
||||
offset: offset,
|
||||
offset,
|
||||
})
|
||||
syncedAt = retrieved.since || Date.now()
|
||||
|
||||
const retrievedData = retrieved.data
|
||||
if (retrievedData.length === 0) {
|
||||
break
|
||||
|
|
@ -245,13 +248,15 @@ export function integrationsServiceRouter() {
|
|||
// write the list of urls, state and labels to the stream
|
||||
retrievedData.forEach((row) => stringifier.write(row))
|
||||
|
||||
hasMore = !!retrieved.hasMore
|
||||
offset += retrievedData.length
|
||||
since = retrieved.since || Date.now()
|
||||
console.debug('retrieved data', {
|
||||
total: offset,
|
||||
size: retrievedData.length,
|
||||
})
|
||||
}
|
||||
// update the integration's syncedAt
|
||||
await getRepository(Integration).update(integration.id, {
|
||||
syncedAt: new Date(since),
|
||||
syncedAt: new Date(syncedAt),
|
||||
})
|
||||
} catch (err) {
|
||||
logger.error('import pages from integration failed', err)
|
||||
|
|
|
|||
|
|
@ -135,9 +135,13 @@ export class PocketIntegration extends IntegrationService {
|
|||
: undefined,
|
||||
state: statusToState[item.status],
|
||||
}))
|
||||
|
||||
if (pocketData.error) {
|
||||
throw new Error(`Error retrieving pocket data: ${pocketData.error}`)
|
||||
}
|
||||
|
||||
return {
|
||||
data,
|
||||
hasMore: pocketData.complete !== 1,
|
||||
since: pocketData.since * 1000,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -480,7 +480,17 @@ export const enqueueImportFromIntegration = async (
|
|||
}
|
||||
// If there is no Google Cloud Project Id exposed, it means that we are in local environment
|
||||
if (env.dev.isLocal || !GOOGLE_CLOUD_PROJECT) {
|
||||
return nanoid()
|
||||
// Calling the handler function directly.
|
||||
setTimeout(() => {
|
||||
axios
|
||||
.post(`${env.queue.integrationTaskHandlerUrl}/import`, payload, {
|
||||
headers,
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error)
|
||||
})
|
||||
}, 0)
|
||||
return ''
|
||||
}
|
||||
|
||||
const createdTasks = await createHttpTaskWithToken({
|
||||
|
|
|
|||
Loading…
Reference in a new issue