Fix issue where we return EPUB content reader for items marked as book in metadata

If we parse a page with <meta property="og:type" content="book"> in
it now, we incorrectly set this to ContentReader.EPUB, which then
causes syncing issues on iOS which doesn't have an EPUB reader
type defined in its GraphQL schema yet.
This commit is contained in:
Jackson Harper 2023-06-05 14:44:47 +08:00
parent 815f93ca94
commit e53cc28683
4 changed files with 21 additions and 12 deletions

View file

@ -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,

View file

@ -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[] },

View file

@ -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

View file

@ -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