Add state and labels to savePageInput
This commit is contained in:
@ -13,7 +13,14 @@ import { Readability } from '@omnivore/readability'
|
||||
|
||||
import * as Sentry from '@sentry/serverless'
|
||||
|
||||
export type RetrievedDataState = 'archived' | 'saved' | 'deleted'
|
||||
export enum ArticleSavingRequestStatus {
|
||||
Failed = 'FAILED',
|
||||
Processing = 'PROCESSING',
|
||||
Succeeded = 'SUCCEEDED',
|
||||
Deleted = 'DELETED',
|
||||
|
||||
Archived = 'ARCHIVED',
|
||||
}
|
||||
|
||||
Sentry.GCPFunction.init({
|
||||
dsn: process.env.SENTRY_DSN,
|
||||
@ -29,7 +36,7 @@ const CONTENT_TYPES = ['text/csv', 'application/zip']
|
||||
export type UrlHandler = (
|
||||
ctx: ImportContext,
|
||||
url: URL,
|
||||
state?: RetrievedDataState,
|
||||
state?: ArticleSavingRequestStatus,
|
||||
labels?: string[]
|
||||
) => Promise<void>
|
||||
export type ContentHandler = (
|
||||
@ -74,7 +81,7 @@ const importURL = async (
|
||||
userId: string,
|
||||
url: URL,
|
||||
source: string,
|
||||
state?: RetrievedDataState,
|
||||
state?: ArticleSavingRequestStatus,
|
||||
labels?: string[]
|
||||
): Promise<string | undefined> => {
|
||||
return createCloudTask(CONTENT_FETCH_URL, {
|
||||
@ -136,7 +143,7 @@ const handlerForFile = (name: string): importHandlerFunc | undefined => {
|
||||
const urlHandler = async (
|
||||
ctx: ImportContext,
|
||||
url: URL,
|
||||
state?: RetrievedDataState,
|
||||
state?: ArticleSavingRequestStatus,
|
||||
labels?: string[]
|
||||
): Promise<void> => {
|
||||
try {
|
||||
|
||||
@ -4,7 +4,7 @@ import { expect } from 'chai'
|
||||
import chaiString from 'chai-string'
|
||||
import * as fs from 'fs'
|
||||
import { importCsv } from '../../src/csv'
|
||||
import { ImportContext, RetrievedDataState } from '../../src'
|
||||
import { ArticleSavingRequestStatus, ImportContext } from '../../src'
|
||||
import { stubImportCtx } from '../util'
|
||||
|
||||
chai.use(chaiString)
|
||||
@ -33,7 +33,7 @@ describe('Load a complex CSV file', () => {
|
||||
it('should call the handler for each URL, state and labels', async () => {
|
||||
const results: {
|
||||
url: URL
|
||||
state?: RetrievedDataState
|
||||
state?: ArticleSavingRequestStatus
|
||||
labels?: string[]
|
||||
}[] = []
|
||||
const stream = fs.createReadStream('./test/csv/data/complex.csv')
|
||||
@ -58,12 +58,12 @@ describe('Load a complex CSV file', () => {
|
||||
expect(results).to.eql([
|
||||
{
|
||||
url: new URL('https://omnivore.app'),
|
||||
state: 'archived',
|
||||
state: 'ARCHIVED',
|
||||
labels: ['test'],
|
||||
},
|
||||
{
|
||||
url: new URL('https://google.com'),
|
||||
state: 'saved',
|
||||
state: 'SUCCEEDED',
|
||||
labels: ['test', 'development'],
|
||||
},
|
||||
])
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
"https://omnivore.app",archived,"[test]"
|
||||
"https://google.com",saved,"[test,development]"
|
||||
"https://omnivore.app",ARCHIVED,"[test]"
|
||||
"https://google.com",SUCCEEDED,"[test,development]"
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { Readability } from '@omnivore/readability'
|
||||
import { ImportContext, RetrievedDataState } from '../src'
|
||||
import { ArticleSavingRequestStatus, ImportContext } from '../src'
|
||||
|
||||
export const stubImportCtx = () => {
|
||||
return {
|
||||
@ -9,7 +9,7 @@ export const stubImportCtx = () => {
|
||||
urlHandler: (
|
||||
ctx: ImportContext,
|
||||
url: URL,
|
||||
state?: RetrievedDataState,
|
||||
state?: ArticleSavingRequestStatus,
|
||||
labels?: string[]
|
||||
): Promise<void> => {
|
||||
return Promise.resolve()
|
||||
|
||||
Reference in New Issue
Block a user