From 88d6455222963e8819eef303702f2dc575a8b522 Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Thu, 21 Mar 2024 19:51:31 +0800 Subject: [PATCH] default filter is in:all --- packages/api/src/jobs/trigger_rule.ts | 21 +++++------- packages/api/src/pubsub.ts | 17 +--------- packages/api/src/services/highlights.ts | 17 +++++----- packages/api/src/services/labels.ts | 16 +++------ packages/api/src/services/library_item.ts | 34 +++++++++---------- .../networking/queries/useGetRulesQuery.tsx | 3 ++ packages/web/pages/settings/rules.tsx | 34 +++++++++++++------ 7 files changed, 66 insertions(+), 76 deletions(-) diff --git a/packages/api/src/jobs/trigger_rule.ts b/packages/api/src/jobs/trigger_rule.ts index 132218ebb..88cc65144 100644 --- a/packages/api/src/jobs/trigger_rule.ts +++ b/packages/api/src/jobs/trigger_rule.ts @@ -1,5 +1,5 @@ import { LiqeQuery } from '@omnivore/liqe' -import axios, { Method } from 'axios' +import axios from 'axios' import { ReadingProgressDataSource } from '../datasources/reading_progress_data_source' import { LibraryItem, LibraryItemState } from '../entity/library_item' import { Rule, RuleAction, RuleActionType, RuleEventType } from '../entity/rule' @@ -89,24 +89,19 @@ const sendNotification = async (obj: RuleActionObj) => { } const sendToWebhook = async (obj: RuleActionObj) => { - const [url, method, contentType] = obj.action.params - const [type, action] = obj.ruleEventType.split('_') + const [url] = obj.action.params - const body = { - action, - userId: obj.userId, - [type]: obj.data, + const data = { + event: obj.ruleEventType, + data: obj.data, } - logger.info('triggering webhook', { url, method }) + logger.info(`triggering webhook: ${url}`) - return axios.request({ - url, - method: method as Method, + return axios.post(url, data, { headers: { - 'Content-Type': contentType, + 'Content-Type': 'application/json', }, - data: body, timeout: 5000, // 5s }) } diff --git a/packages/api/src/pubsub.ts b/packages/api/src/pubsub.ts index d340f520b..55da4e7c9 100644 --- a/packages/api/src/pubsub.ts +++ b/packages/api/src/pubsub.ts @@ -7,7 +7,6 @@ import { enqueueExportItem, enqueueProcessYouTubeVideo, enqueueTriggerRuleJob, - enqueueWebhookJob, } from './utils/createTask' import { buildLogger } from './utils/logger' import { isYouTubeVideoURL } from './utils/youtube' @@ -67,14 +66,7 @@ export const createPubSubClient = (): PubsubClient => { libraryItemIds: [libraryItemId], }) - await enqueueWebhookJob({ - userId, - type, - action: 'created', - data, - }) - - if (type === EntityType.PAGE) { + if (type === EntityType.ITEM) { // if (await findGrantedFeatureByName(FeatureName.AISummaries, userId)) { // await enqueueAISummarizeJob({ // userId, @@ -113,13 +105,6 @@ export const createPubSubClient = (): PubsubClient => { userId, libraryItemIds: [libraryItemId], }) - - await enqueueWebhookJob({ - userId, - type, - action: 'updated', - data, - }) }, entityDeleted: async ( type: EntityType, diff --git a/packages/api/src/services/highlights.ts b/packages/api/src/services/highlights.ts index 8cc10ad0b..624c5b2da 100644 --- a/packages/api/src/services/highlights.ts +++ b/packages/api/src/services/highlights.ts @@ -9,11 +9,12 @@ import { createPubSubClient, EntityType } from '../pubsub' import { authTrx } from '../repository' import { highlightRepository } from '../repository/highlight' import { enqueueUpdateHighlight } from '../utils/createTask' -import { UpdateItemEvent } from './library_item' +import { ItemEvent } from './library_item' -type HighlightEvent = { id: string; pageId: string } -type CreateHighlightEvent = DeepPartial & HighlightEvent -type UpdateHighlightEvent = QueryDeepPartialEntity & HighlightEvent +export type HighlightEvent = Omit< + DeepPartial, + 'user' | 'userId' | 'sharedAt' +> export const getHighlightLocation = (patch: string): number | undefined => { const dmp = new diff_match_patch() @@ -57,7 +58,7 @@ export const createHighlight = async ( userId ) - await pubsub.entityCreated( + await pubsub.entityCreated( EntityType.HIGHLIGHT, { id: libraryItemId, highlights: [newHighlight], userId }, userId, @@ -105,7 +106,7 @@ export const mergeHighlights = async ( }) }) - await pubsub.entityCreated( + await pubsub.entityCreated( EntityType.HIGHLIGHT, { id: libraryItemId, highlights: [newHighlight], userId }, userId, @@ -140,9 +141,9 @@ export const updateHighlight = async ( }) const libraryItemId = updatedHighlight.libraryItem.id - await pubsub.entityUpdated( + await pubsub.entityUpdated( EntityType.HIGHLIGHT, - { id: libraryItemId, highlights: [highlight], userId }, + { id: libraryItemId, highlights: [highlight], userId } as ItemEvent, userId, libraryItemId ) diff --git a/packages/api/src/services/labels.ts b/packages/api/src/services/labels.ts index 1f05d14c1..4a23f30c0 100644 --- a/packages/api/src/services/labels.ts +++ b/packages/api/src/services/labels.ts @@ -8,17 +8,9 @@ import { CreateLabelInput, labelRepository } from '../repository/label' import { bulkEnqueueUpdateLabels } from '../utils/createTask' import { logger } from '../utils/logger' import { findHighlightById } from './highlights' -import { findLibraryItemIdsByLabelId, UpdateItemEvent } from './library_item' +import { findLibraryItemIdsByLabelId, ItemEvent } from './library_item' -type AddLabelsToLibraryItemEvent = { - pageId: string - labels: DeepPartial