mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Merge pull request #2206 from omnivore-app/fix/csv-importer
Fix a bug of importing untagged pocket items
This commit is contained in:
commit
ac61c4e380
5 changed files with 23 additions and 8 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
|
|
|||
|
|
@ -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'],
|
||||
},
|
||||
])
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,2 +1,3 @@
|
|||
"https://omnivore.app",ARCHIVED,"[test]"
|
||||
"https://google.com",SUCCEEDED,"[test,development]"
|
||||
https://test.com,SUCCEEDED,"[test, development]"
|
||||
|
|
|
|||
|
Loading…
Reference in a new issue