Merge pull request #2307 from omnivore-app/fix/book-content-reader
Fix incorrectly setting epub content reader type
This commit is contained in:
@ -100,7 +100,7 @@ import {
|
||||
} from '../../utils/parser'
|
||||
import { parseSearchQuery, SortBy, SortOrder } from '../../utils/search'
|
||||
import {
|
||||
contentReaderForPageType,
|
||||
contentReaderForPage,
|
||||
getStorageFileDetails,
|
||||
makeStorageFilePublic,
|
||||
} from '../../utils/uploads'
|
||||
@ -963,7 +963,7 @@ export const searchResolver = authorized<
|
||||
...r,
|
||||
image: r.image && createImageProxyUrl(r.image, 260, 260),
|
||||
isArchived: !!r.archivedAt,
|
||||
contentReader: contentReaderForPageType(r.pageType),
|
||||
contentReader: contentReaderForPage(r.pageType, r.uploadFileId),
|
||||
originalArticleUrl: r.url,
|
||||
publishedAt: validatedDate(r.publishedAt),
|
||||
ownedByViewer: r.userId === claims.uid,
|
||||
@ -1007,7 +1007,7 @@ export const typeaheadSearchResolver = authorized<
|
||||
const results = await searchAsYouType(claims.uid, query, first || undefined)
|
||||
const items: TypeaheadSearchItem[] = results.map((r) => ({
|
||||
...r,
|
||||
contentReader: contentReaderForPageType(r.pageType),
|
||||
contentReader: contentReaderForPage(r.pageType, r.uploadFileId),
|
||||
}))
|
||||
|
||||
return { items }
|
||||
@ -1072,7 +1072,7 @@ export const updatesSinceResolver = authorized<
|
||||
...p,
|
||||
image: p.image && createImageProxyUrl(p.image, 260, 260),
|
||||
isArchived: !!p.archivedAt,
|
||||
contentReader: contentReaderForPageType(p.pageType),
|
||||
contentReader: contentReaderForPage(p.pageType, p.uploadFileId),
|
||||
} as SearchItem,
|
||||
cursor: endCursor,
|
||||
itemID: p.id,
|
||||
|
||||
@ -19,7 +19,7 @@ import {
|
||||
import { userDataToUser, validatedDate, wordsCount } from '../utils/helpers'
|
||||
import { createImageProxyUrl } from '../utils/imageproxy'
|
||||
import {
|
||||
contentReaderForPageType,
|
||||
contentReaderForPage,
|
||||
generateDownloadSignedUrl,
|
||||
generateUploadFilePathName,
|
||||
} from '../utils/uploads'
|
||||
@ -468,8 +468,11 @@ export const functionResolvers = {
|
||||
})
|
||||
return !!page?.archivedAt || false
|
||||
},
|
||||
contentReader(article: { pageType: PageType }) {
|
||||
return contentReaderForPageType(article.pageType)
|
||||
contentReader(article: {
|
||||
pageType: PageType
|
||||
uploadFileId: string | undefined
|
||||
}) {
|
||||
return contentReaderForPage(article.pageType, article.uploadFileId)
|
||||
},
|
||||
highlights(
|
||||
article: { id: string; userId?: string; highlights?: Highlight[] },
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { Page, PageType } from '../elastic/types'
|
||||
import { Page } from '../elastic/types'
|
||||
import { ContentReader } from '../generated/graphql'
|
||||
import { contentReaderForPageType } from '../utils/uploads'
|
||||
import { contentReaderForPage } from '../utils/uploads'
|
||||
import { FeatureName, isOptedIn } from './features'
|
||||
|
||||
/*
|
||||
@ -11,7 +11,8 @@ export const shouldSynthesize = async (
|
||||
page: Page
|
||||
): Promise<boolean> => {
|
||||
if (
|
||||
contentReaderForPageType(page.pageType) !== ContentReader.Web ||
|
||||
contentReaderForPage(page.pageType, page.uploadFileId) !==
|
||||
ContentReader.Web ||
|
||||
!page.content
|
||||
) {
|
||||
// we don't synthesize files for now
|
||||
|
||||
@ -4,8 +4,13 @@ import { File, GetSignedUrlConfig, Storage } from '@google-cloud/storage'
|
||||
import { env } from '../env'
|
||||
import { ContentReader, PageType } from '../generated/graphql'
|
||||
|
||||
export const contentReaderForPageType = (pageType: PageType) => {
|
||||
console.log('getting content reader: ', pageType)
|
||||
export const contentReaderForPage = (
|
||||
pageType: PageType,
|
||||
uploadFileId: string | null | undefined
|
||||
) => {
|
||||
if (!uploadFileId) {
|
||||
return ContentReader.Web
|
||||
}
|
||||
switch (pageType) {
|
||||
case PageType.Book:
|
||||
return ContentReader.Epub
|
||||
|
||||
20
packages/api/test/utils/uploads.test.ts
Normal file
20
packages/api/test/utils/uploads.test.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import 'mocha'
|
||||
import { expect } from 'chai'
|
||||
import 'chai/register-should'
|
||||
import { contentReaderForPage } from '../../src/utils/uploads'
|
||||
import { ContentReader, PageType } from '../../src/generated/graphql'
|
||||
|
||||
describe('contentReaderForPage', () => {
|
||||
it('returns web if there is no uploadFileId', () => {
|
||||
const result = contentReaderForPage(PageType.Book, undefined)
|
||||
expect(result).to.eq(ContentReader.Web)
|
||||
})
|
||||
it('returns Epub if there is an uploadFileId and type is book', () => {
|
||||
const result = contentReaderForPage(PageType.Book, 'fakeUploadFileId')
|
||||
expect(result).to.eq(ContentReader.Epub)
|
||||
})
|
||||
it('returns PDF if there is an uploadFileId and type is File', () => {
|
||||
const result = contentReaderForPage(PageType.File, 'fakeUploadFileId')
|
||||
expect(result).to.eq(ContentReader.Pdf)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user