move to folder api will create a task to fetch content if content not exists

This commit is contained in:
Hongbo Wu
2023-12-14 19:20:03 +08:00
parent 83e0982457
commit b86ee139e0
5 changed files with 43 additions and 27 deletions

View File

@ -415,7 +415,6 @@ export const getArticleResolver = authorized<
deletedAt: IsNull(),
},
relations: {
labels: true,
highlights: {
user: true,
labels: true,
@ -912,7 +911,7 @@ export const moveToFolderResolver = authorized<
MoveToFolderSuccess,
MoveToFolderError,
MutationMoveToFolderArgs
>(async (_, { id, folder }, { authTrx, pubsub, uid }) => {
>(async (_, { id, folder }, { authTrx, log, pubsub, uid }) => {
analytics.track({
userId: uid,
event: 'move_to_folder',
@ -945,24 +944,6 @@ export const moveToFolderResolver = authorized<
const savedAt = new Date()
// // if the content is not fetched yet, create a page save request
// if (!item.readableContent) {
// const articleSavingRequest = await createPageSaveRequest({
// userId: uid,
// url: item.originalUrl,
// articleSavingRequestId: id,
// priority: 'high',
// publishedAt: item.publishedAt || undefined,
// savedAt,
// pubsub,
// })
// return {
// __typename: 'MoveToFolderSuccess',
// articleSavingRequest,
// }
// }
await updateLibraryItem(
item.id,
{
@ -973,8 +954,29 @@ export const moveToFolderResolver = authorized<
pubsub
)
// if the content is not fetched yet, create a page save request
if (!item.readableContent) {
try {
await createPageSaveRequest({
userId: uid,
url: item.originalUrl,
articleSavingRequestId: id,
priority: 'high',
publishedAt: item.publishedAt || undefined,
savedAt,
folder,
pubsub,
})
} catch (error) {
log.error('moveToFolderResolver error', error)
return {
errorCodes: [MoveToFolderErrorCode.BadRequest],
}
}
}
return {
__typename: 'MoveToFolderSuccess',
success: true,
}
})

View File

@ -319,6 +319,19 @@ export const functionResolvers = {
if (article.wordCount) return article.wordCount
return article.content ? wordsCount(article.content) : undefined
},
async labels(
article: { id: string; labels?: Label[]; labelNames?: string[] | null },
_: unknown,
ctx: WithDataSourcesContext
) {
if (article.labels) return article.labels
if (article.labelNames && article.labelNames.length > 0) {
return findLabelsByLibraryItemId(article.id, ctx.uid)
}
return []
},
},
Highlight: {
// async reactions(
@ -518,4 +531,5 @@ export const functionResolvers = {
...resultResolveTypeResolver('UpdateSubscription'),
...resultResolveTypeResolver('UpdateEmail'),
...resultResolveTypeResolver('ScanFeeds'),
...resultResolveTypeResolver('MoveToFolder'),
}

View File

@ -41,7 +41,7 @@ export const createNewsletterEmailResolver = authorized<
const newsletterEmail = await createNewsletterEmail(
claims.uid,
undefined,
input?.folder || undefined,
input?.folder || 'following',
input?.name || undefined,
input?.description || undefined
)

View File

@ -241,8 +241,8 @@ export const subscribeResolver = authorized<
// limit number of rss subscriptions to max
const results = (await getRepository(Subscription).query(
`insert into omnivore.subscriptions (name, url, description, type, user_id, icon, auto_add_to_library, is_private)
select $1, $2, $3, $4, $5, $6, $7, $8, $9, $10 from omnivore.subscriptions
`insert into omnivore.subscriptions (name, url, description, type, user_id, icon, is_private, fetch_content, folder)
select $1, $2, $3, $4, $5, $6, $7, $8, $9 from omnivore.subscriptions
where user_id = $5 and type = 'RSS' and status = 'ACTIVE'
having count(*) < $10
returning *;`,
@ -254,8 +254,8 @@ export const subscribeResolver = authorized<
uid,
feed.thumbnail,
input.isPrivate,
input.fetchContent,
input.folder,
input.fetchContent ?? true,
input.folder ?? 'following',
MAX_RSS_SUBSCRIPTIONS,
]
)) as any[]

View File

@ -34,7 +34,7 @@ export type SaveEmailInput = {
unsubHttpUrl?: string
newsletterEmailId?: string
receivedEmailId: string
folder: string
folder?: string
}
const isStubUrl = (url: string): boolean => {