mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
default filter is in:all
This commit is contained in:
parent
c551d9fe6b
commit
88d6455222
7 changed files with 66 additions and 76 deletions
|
|
@ -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
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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<Highlight> & HighlightEvent
|
||||
type UpdateHighlightEvent = QueryDeepPartialEntity<Highlight> & HighlightEvent
|
||||
export type HighlightEvent = Omit<
|
||||
DeepPartial<Highlight>,
|
||||
'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<UpdateItemEvent>(
|
||||
await pubsub.entityCreated<ItemEvent>(
|
||||
EntityType.HIGHLIGHT,
|
||||
{ id: libraryItemId, highlights: [newHighlight], userId },
|
||||
userId,
|
||||
|
|
@ -105,7 +106,7 @@ export const mergeHighlights = async (
|
|||
})
|
||||
})
|
||||
|
||||
await pubsub.entityCreated<UpdateItemEvent>(
|
||||
await pubsub.entityCreated<ItemEvent>(
|
||||
EntityType.HIGHLIGHT,
|
||||
{ id: libraryItemId, highlights: [newHighlight], userId },
|
||||
userId,
|
||||
|
|
@ -140,9 +141,9 @@ export const updateHighlight = async (
|
|||
})
|
||||
|
||||
const libraryItemId = updatedHighlight.libraryItem.id
|
||||
await pubsub.entityUpdated<UpdateItemEvent>(
|
||||
await pubsub.entityUpdated<ItemEvent>(
|
||||
EntityType.HIGHLIGHT,
|
||||
{ id: libraryItemId, highlights: [highlight], userId },
|
||||
{ id: libraryItemId, highlights: [highlight], userId } as ItemEvent,
|
||||
userId,
|
||||
libraryItemId
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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<Label>[]
|
||||
source?: LabelSource
|
||||
}
|
||||
type AddLabelsToHighlightEvent = {
|
||||
highlightId: string
|
||||
labels: DeepPartial<Label>[]
|
||||
}
|
||||
export type LabelEvent = Omit<DeepPartial<Label>, 'description' | 'createdAt'>
|
||||
|
||||
// const batchGetLabelsFromLinkIds = async (
|
||||
// linkIds: readonly string[]
|
||||
|
|
@ -144,7 +136,7 @@ export const saveLabelsInLibraryItem = async (
|
|||
|
||||
if (source === 'user') {
|
||||
// create pubsub event
|
||||
await pubsub.entityCreated<UpdateItemEvent>(
|
||||
await pubsub.entityCreated<ItemEvent>(
|
||||
EntityType.LABEL,
|
||||
{ id: libraryItemId, labels, userId },
|
||||
userId,
|
||||
|
|
@ -215,7 +207,7 @@ export const saveLabelsInHighlight = async (
|
|||
|
||||
const libraryItemId = highlight.libraryItemId
|
||||
// create pubsub event
|
||||
await pubsub.entityCreated<UpdateItemEvent>(
|
||||
await pubsub.entityCreated<ItemEvent>(
|
||||
EntityType.LABEL,
|
||||
{ id: libraryItemId, highlights: [{ id: highlightId, labels }], userId },
|
||||
userId,
|
||||
|
|
|
|||
|
|
@ -28,7 +28,8 @@ import { Merge } from '../util'
|
|||
import { setRecentlySavedItemInRedis } from '../utils/helpers'
|
||||
import { logger } from '../utils/logger'
|
||||
import { parseSearchQuery } from '../utils/search'
|
||||
import { addLabelsToLibraryItem } from './labels'
|
||||
import { HighlightEvent } from './highlights'
|
||||
import { addLabelsToLibraryItem, LabelEvent } from './labels'
|
||||
|
||||
type IgnoredFields =
|
||||
| 'user'
|
||||
|
|
@ -36,15 +37,14 @@ type IgnoredFields =
|
|||
| 'previewContentType'
|
||||
| 'links'
|
||||
| 'textContentHash'
|
||||
export type ItemEvent = CreateItemEvent | UpdateItemEvent
|
||||
export type CreateItemEvent = Merge<
|
||||
type ItemBaseEvent = Merge<
|
||||
Omit<DeepPartial<LibraryItem>, IgnoredFields>,
|
||||
BaseEntityEvent
|
||||
>
|
||||
export type UpdateItemEvent = Merge<
|
||||
Omit<QueryDeepPartialEntity<LibraryItem>, IgnoredFields>,
|
||||
BaseEntityEvent
|
||||
{
|
||||
labels?: LabelEvent[]
|
||||
highlights?: HighlightEvent[]
|
||||
}
|
||||
>
|
||||
export type ItemEvent = Merge<ItemBaseEvent, BaseEntityEvent>
|
||||
|
||||
export class RequiresSearchQueryError extends Error {
|
||||
constructor() {
|
||||
|
|
@ -885,7 +885,7 @@ export const updateLibraryItem = async (
|
|||
|
||||
if (libraryItem.state === LibraryItemState.Succeeded) {
|
||||
// send create event if the item was created
|
||||
await pubsub.entityCreated<CreateItemEvent>(
|
||||
await pubsub.entityCreated<ItemEvent>(
|
||||
EntityType.ITEM,
|
||||
{ ...updatedLibraryItem, userId },
|
||||
userId,
|
||||
|
|
@ -895,9 +895,9 @@ export const updateLibraryItem = async (
|
|||
return updatedLibraryItem
|
||||
}
|
||||
|
||||
await pubsub.entityUpdated<UpdateItemEvent>(
|
||||
await pubsub.entityUpdated<ItemEvent>(
|
||||
EntityType.ITEM,
|
||||
{ ...libraryItem, id, userId },
|
||||
{ ...libraryItem, id, userId } as ItemEvent,
|
||||
userId,
|
||||
id
|
||||
)
|
||||
|
|
@ -958,7 +958,7 @@ export const updateLibraryItemReadingProgress = async (
|
|||
}
|
||||
|
||||
const updatedItem = result[0][0]
|
||||
await pubsub.entityUpdated<UpdateItemEvent>(
|
||||
await pubsub.entityUpdated<ItemEvent>(
|
||||
EntityType.ITEM,
|
||||
{ ...updatedItem, id, userId },
|
||||
userId,
|
||||
|
|
@ -1059,7 +1059,7 @@ export const createOrUpdateLibraryItem = async (
|
|||
return newLibraryItem
|
||||
}
|
||||
|
||||
await pubsub.entityCreated<CreateItemEvent>(
|
||||
await pubsub.entityCreated<ItemEvent>(
|
||||
EntityType.ITEM,
|
||||
{ ...newLibraryItem, userId },
|
||||
userId,
|
||||
|
|
@ -1422,7 +1422,7 @@ export const filterItemEvents = (
|
|||
}
|
||||
}
|
||||
case 'type': {
|
||||
return event.itemType?.toString()?.toLowerCase() === lowercasedValue
|
||||
return event.itemType?.toLowerCase() === lowercasedValue
|
||||
}
|
||||
case 'label': {
|
||||
const labels = event.labelNames as string[] | undefined
|
||||
|
|
@ -1497,7 +1497,7 @@ export const filterItemEvents = (
|
|||
// get camel case column name
|
||||
const key = camelCase(columnName) as 'subscription' | 'itemLanguage'
|
||||
|
||||
return event[key]?.toString()?.toLowerCase() === lowercasedValue
|
||||
return event[key]?.toLowerCase() === lowercasedValue
|
||||
}
|
||||
// match filters
|
||||
case 'note':
|
||||
|
|
@ -1513,7 +1513,7 @@ export const filterItemEvents = (
|
|||
const keys = ['siteName', 'originalUrl'] as const
|
||||
|
||||
return keys.some((key) => {
|
||||
return event[key]?.toString()?.toLowerCase().includes(lowercasedValue)
|
||||
return event[key]?.toLowerCase().includes(lowercasedValue)
|
||||
})
|
||||
}
|
||||
case 'includes': {
|
||||
|
|
@ -1522,7 +1522,7 @@ export const filterItemEvents = (
|
|||
throw new Error('Expected ids')
|
||||
}
|
||||
|
||||
return event.id && ids.includes(event.id.toString())
|
||||
return event.id && ids.includes(event.id)
|
||||
}
|
||||
case 'recommendedby': {
|
||||
if (!event.recommenderNames) {
|
||||
|
|
|
|||
|
|
@ -13,11 +13,14 @@ export enum RuleActionType {
|
|||
MarkAsRead = 'MARK_AS_READ',
|
||||
Delete = 'DELETE',
|
||||
SendNotification = 'SEND_NOTIFICATION',
|
||||
Webhook = 'WEBHOOK',
|
||||
}
|
||||
|
||||
export enum RuleEventType {
|
||||
PAGE_CREATED = 'PAGE_CREATED',
|
||||
PAGE_UPDATED = 'PAGE_UPDATED',
|
||||
LABEL_CREATED = 'LABEL_CREATED',
|
||||
HIGHLIGHT_CREATED = 'HIGHLIGHT_CREATED',
|
||||
}
|
||||
|
||||
export interface Rule {
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ const CreateRuleModal = (props: CreateRuleModalProps): JSX.Element => {
|
|||
|
||||
const onOk = async (values: any) => {
|
||||
const name = form.getFieldValue('name')
|
||||
const filter = form.getFieldValue('filter')
|
||||
const filter = form.getFieldValue('filter') || 'in:all'
|
||||
const eventTypes = form.getFieldValue('eventTypes')
|
||||
try {
|
||||
await setRuleMutation({
|
||||
|
|
@ -81,11 +81,7 @@ const CreateRuleModal = (props: CreateRuleModalProps): JSX.Element => {
|
|||
<Input />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="Filter"
|
||||
name="filter"
|
||||
rules={[{ required: true, message: 'Please enter the rule filter' }]}
|
||||
>
|
||||
<Form.Item label="Filter" name="filter">
|
||||
<Input />
|
||||
</Form.Item>
|
||||
|
||||
|
|
@ -131,8 +127,13 @@ const CreateActionModal = (props: CreateActionModalProps): JSX.Element => {
|
|||
|
||||
const onOk = async (values: any) => {
|
||||
const actionType = form.getFieldValue('actionType') as RuleActionType
|
||||
const params =
|
||||
actionType == RuleActionType.AddLabel ? form.getFieldValue('labels') : []
|
||||
let params = []
|
||||
if (actionType == RuleActionType.AddLabel) {
|
||||
params = form.getFieldValue('labels')
|
||||
} else if (actionType == RuleActionType.Webhook) {
|
||||
params = [form.getFieldValue('url')]
|
||||
}
|
||||
|
||||
if (props.rule) {
|
||||
await setRuleMutation({
|
||||
id: props.rule.id,
|
||||
|
|
@ -155,8 +156,9 @@ const CreateActionModal = (props: CreateActionModalProps): JSX.Element => {
|
|||
}
|
||||
}
|
||||
|
||||
const [actionType, setActionType] =
|
||||
useState<RuleActionType | undefined>(undefined)
|
||||
const [actionType, setActionType] = useState<RuleActionType | undefined>(
|
||||
undefined
|
||||
)
|
||||
|
||||
return (
|
||||
<Modal
|
||||
|
|
@ -215,6 +217,18 @@ const CreateActionModal = (props: CreateActionModalProps): JSX.Element => {
|
|||
</Select>
|
||||
</Form.Item>
|
||||
)}
|
||||
|
||||
{actionType == RuleActionType.Webhook && (
|
||||
<Form.Item
|
||||
label="URL"
|
||||
name="url"
|
||||
rules={[
|
||||
{ required: true, message: 'Please key in your webhook url' },
|
||||
]}
|
||||
>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
)}
|
||||
</Form>
|
||||
</Modal>
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue