mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
add fetchContent api
This commit is contained in:
parent
07b96c46d5
commit
92aa11b98e
5 changed files with 130 additions and 1 deletions
|
|
@ -820,6 +820,23 @@ export type FeedsSuccess = {
|
|||
pageInfo: PageInfo;
|
||||
};
|
||||
|
||||
export type FetchContentError = {
|
||||
__typename?: 'FetchContentError';
|
||||
errorCodes: Array<FetchContentErrorCode>;
|
||||
};
|
||||
|
||||
export enum FetchContentErrorCode {
|
||||
BadRequest = 'BAD_REQUEST',
|
||||
Unauthorized = 'UNAUTHORIZED'
|
||||
}
|
||||
|
||||
export type FetchContentResult = FetchContentError | FetchContentSuccess;
|
||||
|
||||
export type FetchContentSuccess = {
|
||||
__typename?: 'FetchContentSuccess';
|
||||
success: Scalars['Boolean'];
|
||||
};
|
||||
|
||||
export type Filter = {
|
||||
__typename?: 'Filter';
|
||||
category?: Maybe<Scalars['String']>;
|
||||
|
|
@ -1335,6 +1352,7 @@ export type Mutation = {
|
|||
deleteNewsletterEmail: DeleteNewsletterEmailResult;
|
||||
deleteRule: DeleteRuleResult;
|
||||
deleteWebhook: DeleteWebhookResult;
|
||||
fetchContent: FetchContentResult;
|
||||
generateApiKey: GenerateApiKeyResult;
|
||||
googleLogin: LoginResult;
|
||||
googleSignup: GoogleSignupResult;
|
||||
|
|
@ -1467,6 +1485,11 @@ export type MutationDeleteWebhookArgs = {
|
|||
};
|
||||
|
||||
|
||||
export type MutationFetchContentArgs = {
|
||||
id: Scalars['ID'];
|
||||
};
|
||||
|
||||
|
||||
export type MutationGenerateApiKeyArgs = {
|
||||
input: GenerateApiKeyInput;
|
||||
};
|
||||
|
|
@ -3624,6 +3647,10 @@ export type ResolversTypes = {
|
|||
FeedsInput: FeedsInput;
|
||||
FeedsResult: ResolversTypes['FeedsError'] | ResolversTypes['FeedsSuccess'];
|
||||
FeedsSuccess: ResolverTypeWrapper<FeedsSuccess>;
|
||||
FetchContentError: ResolverTypeWrapper<FetchContentError>;
|
||||
FetchContentErrorCode: FetchContentErrorCode;
|
||||
FetchContentResult: ResolversTypes['FetchContentError'] | ResolversTypes['FetchContentSuccess'];
|
||||
FetchContentSuccess: ResolverTypeWrapper<FetchContentSuccess>;
|
||||
Filter: ResolverTypeWrapper<Filter>;
|
||||
FiltersError: ResolverTypeWrapper<FiltersError>;
|
||||
FiltersErrorCode: FiltersErrorCode;
|
||||
|
|
@ -4119,6 +4146,9 @@ export type ResolversParentTypes = {
|
|||
FeedsInput: FeedsInput;
|
||||
FeedsResult: ResolversParentTypes['FeedsError'] | ResolversParentTypes['FeedsSuccess'];
|
||||
FeedsSuccess: FeedsSuccess;
|
||||
FetchContentError: FetchContentError;
|
||||
FetchContentResult: ResolversParentTypes['FetchContentError'] | ResolversParentTypes['FetchContentSuccess'];
|
||||
FetchContentSuccess: FetchContentSuccess;
|
||||
Filter: Filter;
|
||||
FiltersError: FiltersError;
|
||||
FiltersResult: ResolversParentTypes['FiltersError'] | ResolversParentTypes['FiltersSuccess'];
|
||||
|
|
@ -4987,6 +5017,20 @@ export type FeedsSuccessResolvers<ContextType = ResolverContext, ParentType exte
|
|||
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
|
||||
};
|
||||
|
||||
export type FetchContentErrorResolvers<ContextType = ResolverContext, ParentType extends ResolversParentTypes['FetchContentError'] = ResolversParentTypes['FetchContentError']> = {
|
||||
errorCodes?: Resolver<Array<ResolversTypes['FetchContentErrorCode']>, ParentType, ContextType>;
|
||||
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
|
||||
};
|
||||
|
||||
export type FetchContentResultResolvers<ContextType = ResolverContext, ParentType extends ResolversParentTypes['FetchContentResult'] = ResolversParentTypes['FetchContentResult']> = {
|
||||
__resolveType: TypeResolveFn<'FetchContentError' | 'FetchContentSuccess', ParentType, ContextType>;
|
||||
};
|
||||
|
||||
export type FetchContentSuccessResolvers<ContextType = ResolverContext, ParentType extends ResolversParentTypes['FetchContentSuccess'] = ResolversParentTypes['FetchContentSuccess']> = {
|
||||
success?: Resolver<ResolversTypes['Boolean'], ParentType, ContextType>;
|
||||
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
|
||||
};
|
||||
|
||||
export type FilterResolvers<ContextType = ResolverContext, ParentType extends ResolversParentTypes['Filter'] = ResolversParentTypes['Filter']> = {
|
||||
category?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
|
||||
createdAt?: Resolver<ResolversTypes['Date'], ParentType, ContextType>;
|
||||
|
|
@ -5377,6 +5421,7 @@ export type MutationResolvers<ContextType = ResolverContext, ParentType extends
|
|||
deleteNewsletterEmail?: Resolver<ResolversTypes['DeleteNewsletterEmailResult'], ParentType, ContextType, RequireFields<MutationDeleteNewsletterEmailArgs, 'newsletterEmailId'>>;
|
||||
deleteRule?: Resolver<ResolversTypes['DeleteRuleResult'], ParentType, ContextType, RequireFields<MutationDeleteRuleArgs, 'id'>>;
|
||||
deleteWebhook?: Resolver<ResolversTypes['DeleteWebhookResult'], ParentType, ContextType, RequireFields<MutationDeleteWebhookArgs, 'id'>>;
|
||||
fetchContent?: Resolver<ResolversTypes['FetchContentResult'], ParentType, ContextType, RequireFields<MutationFetchContentArgs, 'id'>>;
|
||||
generateApiKey?: Resolver<ResolversTypes['GenerateApiKeyResult'], ParentType, ContextType, RequireFields<MutationGenerateApiKeyArgs, 'input'>>;
|
||||
googleLogin?: Resolver<ResolversTypes['LoginResult'], ParentType, ContextType, RequireFields<MutationGoogleLoginArgs, 'input'>>;
|
||||
googleSignup?: Resolver<ResolversTypes['GoogleSignupResult'], ParentType, ContextType, RequireFields<MutationGoogleSignupArgs, 'input'>>;
|
||||
|
|
@ -6559,6 +6604,9 @@ export type Resolvers<ContextType = ResolverContext> = {
|
|||
FeedsError?: FeedsErrorResolvers<ContextType>;
|
||||
FeedsResult?: FeedsResultResolvers<ContextType>;
|
||||
FeedsSuccess?: FeedsSuccessResolvers<ContextType>;
|
||||
FetchContentError?: FetchContentErrorResolvers<ContextType>;
|
||||
FetchContentResult?: FetchContentResultResolvers<ContextType>;
|
||||
FetchContentSuccess?: FetchContentSuccessResolvers<ContextType>;
|
||||
Filter?: FilterResolvers<ContextType>;
|
||||
FiltersError?: FiltersErrorResolvers<ContextType>;
|
||||
FiltersResult?: FiltersResultResolvers<ContextType>;
|
||||
|
|
|
|||
|
|
@ -728,6 +728,21 @@ type FeedsSuccess {
|
|||
pageInfo: PageInfo!
|
||||
}
|
||||
|
||||
type FetchContentError {
|
||||
errorCodes: [FetchContentErrorCode!]!
|
||||
}
|
||||
|
||||
enum FetchContentErrorCode {
|
||||
BAD_REQUEST
|
||||
UNAUTHORIZED
|
||||
}
|
||||
|
||||
union FetchContentResult = FetchContentError | FetchContentSuccess
|
||||
|
||||
type FetchContentSuccess {
|
||||
success: Boolean!
|
||||
}
|
||||
|
||||
type Filter {
|
||||
category: String
|
||||
createdAt: Date!
|
||||
|
|
@ -1198,6 +1213,7 @@ type Mutation {
|
|||
deleteNewsletterEmail(newsletterEmailId: ID!): DeleteNewsletterEmailResult!
|
||||
deleteRule(id: ID!): DeleteRuleResult!
|
||||
deleteWebhook(id: ID!): DeleteWebhookResult!
|
||||
fetchContent(id: ID!): FetchContentResult!
|
||||
generateApiKey(input: GenerateApiKeyInput!): GenerateApiKeyResult!
|
||||
googleLogin(input: GoogleLoginInput!): LoginResult!
|
||||
googleSignup(input: GoogleSignupInput!): GoogleSignupResult!
|
||||
|
|
|
|||
|
|
@ -21,11 +21,15 @@ import {
|
|||
CreateArticleError,
|
||||
CreateArticleErrorCode,
|
||||
CreateArticleSuccess,
|
||||
FetchContentError,
|
||||
FetchContentErrorCode,
|
||||
FetchContentSuccess,
|
||||
MoveToFolderError,
|
||||
MoveToFolderErrorCode,
|
||||
MoveToFolderSuccess,
|
||||
MutationBulkActionArgs,
|
||||
MutationCreateArticleArgs,
|
||||
MutationFetchContentArgs,
|
||||
MutationMoveToFolderArgs,
|
||||
MutationSaveArticleReadingProgressArgs,
|
||||
MutationSetBookmarkArticleArgs,
|
||||
|
|
@ -67,6 +71,7 @@ import {
|
|||
} from '../../services/labels'
|
||||
import {
|
||||
createLibraryItem,
|
||||
findLibraryItemById,
|
||||
findLibraryItemByUrl,
|
||||
findLibraryItemsByPrefix,
|
||||
searchLibraryItems,
|
||||
|
|
@ -981,6 +986,50 @@ export const moveToFolderResolver = authorized<
|
|||
}
|
||||
})
|
||||
|
||||
export const fetchContentResolver = authorized<
|
||||
FetchContentSuccess,
|
||||
FetchContentError,
|
||||
MutationFetchContentArgs
|
||||
>(async (_, { id }, { uid, log, pubsub }) => {
|
||||
analytics.track({
|
||||
userId: uid,
|
||||
event: 'fetch_content',
|
||||
properties: {
|
||||
id,
|
||||
},
|
||||
})
|
||||
|
||||
const item = await findLibraryItemById(id, uid)
|
||||
if (!item) {
|
||||
return {
|
||||
errorCodes: [FetchContentErrorCode.Unauthorized],
|
||||
}
|
||||
}
|
||||
|
||||
// if the content is not fetched yet, create a page save request
|
||||
if (item.state === LibraryItemState.ContentNotFetched) {
|
||||
try {
|
||||
await createPageSaveRequest({
|
||||
userId: uid,
|
||||
url: item.originalUrl,
|
||||
articleSavingRequestId: id,
|
||||
priority: 'high',
|
||||
pubsub,
|
||||
})
|
||||
} catch (error) {
|
||||
log.error('fetchContentResolver error', error)
|
||||
|
||||
return {
|
||||
errorCodes: [FetchContentErrorCode.BadRequest],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
}
|
||||
})
|
||||
|
||||
const getUpdateReason = (libraryItem: LibraryItem, since: Date) => {
|
||||
if (libraryItem.deletedAt) {
|
||||
return UpdateReason.Deleted
|
||||
|
|
|
|||
|
|
@ -2722,6 +2722,21 @@ const schema = gql`
|
|||
BAD_REQUEST
|
||||
}
|
||||
|
||||
union FetchContentResult = FetchContentSuccess | FetchContentError
|
||||
|
||||
type FetchContentSuccess {
|
||||
success: Boolean!
|
||||
}
|
||||
|
||||
type FetchContentError {
|
||||
errorCodes: [FetchContentErrorCode!]!
|
||||
}
|
||||
|
||||
enum FetchContentErrorCode {
|
||||
UNAUTHORIZED
|
||||
BAD_REQUEST
|
||||
}
|
||||
|
||||
# Mutations
|
||||
type Mutation {
|
||||
googleLogin(input: GoogleLoginInput!): LoginResult!
|
||||
|
|
@ -2829,6 +2844,7 @@ const schema = gql`
|
|||
input: UpdateSubscriptionInput!
|
||||
): UpdateSubscriptionResult!
|
||||
moveToFolder(id: ID!, folder: String!): MoveToFolderResult!
|
||||
fetchContent(id: ID!): FetchContentResult!
|
||||
}
|
||||
|
||||
# FIXME: remove sort from feedArticles after all cached tabs are closed
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ export const createPageSaveRequest = async ({
|
|||
pubsub
|
||||
)
|
||||
}
|
||||
// reset state to processing if not in following
|
||||
// reset state to processing
|
||||
if (libraryItem.state !== LibraryItemState.Processing) {
|
||||
libraryItem = await updateLibraryItem(
|
||||
libraryItem.id,
|
||||
|
|
|
|||
Loading…
Reference in a new issue