Merge pull request #2206 from omnivore-app/fix/csv-importer

Fix a bug of importing untagged pocket items
This commit is contained in:
Hongbo Wu 2023-05-16 12:24:36 +08:00 committed by GitHub
commit ac61c4e380
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 8 deletions

View file

@ -1,11 +1,11 @@
import axios from 'axios'
import { ArticleSavingRequestStatus } from '../../elastic/types'
import { env } from '../../env'
import {
IntegrationService,
RetrievedResult,
RetrieveRequest,
} from './integration'
import axios from 'axios'
import { env } from '../../env'
import { ArticleSavingRequestStatus } from '../../elastic/types'
interface PocketResponse {
status: number // 1 if success
@ -130,7 +130,9 @@ export class PocketIntegration extends IntegrationService {
}
const data = pocketItems.map((item) => ({
url: item.given_url,
labels: Object.values(item.tags ?? {}).map((tag) => tag.tag),
labels: item.tags
? Object.values(item.tags).map((tag) => tag.tag)
: undefined,
state: statusToState[item.status],
}))
return {

View file

@ -14,8 +14,15 @@ export const importCsv = async (ctx: ImportContext, stream: Stream) => {
try {
const url = new URL(row[0])
const state = row.length > 1 ? row[1] : undefined
// labels follows format: "[label1, label2]"
const labels = row.length > 2 ? row[2].slice(1, -1).split(',') : undefined
// labels follows format: "[label1,label2]"
const labels =
row.length > 2
? (row[2] as string)
.slice(1, -1)
.split(',')
.map((l) => l.trim())
.filter((l) => l !== '')
: undefined
await ctx.urlHandler(ctx, url, state, labels)
ctx.countImported += 1
} catch (error) {

View file

@ -153,7 +153,7 @@ const urlHandler = async (
url,
'csv-importer',
state,
labels
labels && labels.length > 0 ? labels : undefined
)
if (!result) {
return Promise.reject('Failed to import url')

View file

@ -68,7 +68,7 @@ describe('Load a complex CSV file', () => {
await importCsv(stub, stream)
expect(stub.countFailed).to.equal(0)
expect(stub.countImported).to.equal(2)
expect(stub.countImported).to.equal(3)
expect(results).to.eql([
{
url: new URL('https://omnivore.app'),
@ -80,6 +80,11 @@ describe('Load a complex CSV file', () => {
state: 'SUCCEEDED',
labels: ['test', 'development'],
},
{
url: new URL('https://test.com'),
state: 'SUCCEEDED',
labels: ['test', 'development'],
},
])
})
})

View file

@ -1,2 +1,3 @@
"https://omnivore.app",ARCHIVED,"[test]"
"https://google.com",SUCCEEDED,"[test,development]"
https://test.com,SUCCEEDED,"[test, development]"

1 https://omnivore.app ARCHIVED [test]
2 https://google.com SUCCEEDED [test,development]
3 https://test.com SUCCEEDED [test, development]