Skip to content

Commit

Permalink
Merge pull request #3272 from omnivore-app/fix/delete-feed
Browse files Browse the repository at this point in the history
fix/delete feed
  • Loading branch information
sywhb authored Dec 22, 2023
2 parents a8f04be + f6e04da commit a0f9366
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
1 change: 1 addition & 0 deletions packages/api/src/generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2790,6 +2790,7 @@ export enum SubscribeErrorCode {
AlreadySubscribed = 'ALREADY_SUBSCRIBED',
BadRequest = 'BAD_REQUEST',
ExceededMaxSubscriptions = 'EXCEEDED_MAX_SUBSCRIPTIONS',
InvalidUrl = 'INVALID_URL',
NotFound = 'NOT_FOUND',
Unauthorized = 'UNAUTHORIZED'
}
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/generated/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2190,6 +2190,7 @@ enum SubscribeErrorCode {
ALREADY_SUBSCRIBED
BAD_REQUEST
EXCEEDED_MAX_SUBSCRIPTIONS
INVALID_URL
NOT_FOUND
UNAUTHORIZED
}
Expand Down
34 changes: 23 additions & 11 deletions packages/api/src/resolvers/subscriptions/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from 'axios'
import { parseHTML } from 'linkedom'
import { Brackets } from 'typeorm'
import { Brackets, In } from 'typeorm'
import {
DEFAULT_SUBSCRIPTION_FOLDER,
Subscription,
Expand Down Expand Up @@ -193,9 +193,18 @@ export const subscribeResolver = authorized<
},
})

// validate rss feed
const feed = await parseFeed(input.url)
if (!feed) {
return {
errorCodes: [SubscribeErrorCode.NotFound],
}
}
const feedUrl = feed.url

// find existing subscription
const existingSubscription = await getRepository(Subscription).findOneBy({
url: input.url,
url: In([feedUrl, input.url]), // check both user provided url and parsed url
user: { id: uid },
type: SubscriptionType.Rss,
})
Expand All @@ -218,7 +227,7 @@ export const subscribeResolver = authorized<
// create a cloud task to fetch rss feed item for resub subscription
await enqueueRssFeedFetch({
userIds: [uid],
url: input.url,
url: feedUrl,
subscriptionIds: [updatedSubscription.id],
scheduledDates: [new Date()], // fetch immediately
fetchedDates: [updatedSubscription.lastFetchedAt || null],
Expand All @@ -232,16 +241,19 @@ export const subscribeResolver = authorized<
}
}

// create new rss subscription
const MAX_RSS_SUBSCRIPTIONS = env.subscription.feed.max
// validate rss feed
const feed = await parseFeed(input.url)
if (!feed) {
if (feedUrl !== input.url) {
log.info('feed url is different from user provided url', {
feedUrl,
inputUrl: input.url,
})
return {
errorCodes: [SubscribeErrorCode.NotFound],
errorCodes: [SubscribeErrorCode.InvalidUrl],
}
}

// create new rss subscription
const MAX_RSS_SUBSCRIPTIONS = env.subscription.feed.max

// limit number of rss subscriptions to max
const results = (await getRepository(Subscription).query(
`insert into omnivore.subscriptions (name, url, description, type, user_id, icon, is_private, fetch_content, folder)
Expand All @@ -251,7 +263,7 @@ export const subscribeResolver = authorized<
returning *;`,
[
feed.title,
feed.url,
feedUrl,
feed.description,
SubscriptionType.Rss,
uid,
Expand All @@ -275,7 +287,7 @@ export const subscribeResolver = authorized<
// create a cloud task to fetch rss feed item for the new subscription
await enqueueRssFeedFetch({
userIds: [uid],
url: feed.url,
url: feedUrl,
subscriptionIds: [newSubscription.id],
scheduledDates: [new Date()], // fetch immediately
fetchedDates: [null],
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1737,6 +1737,7 @@ const schema = gql`
NOT_FOUND
ALREADY_SUBSCRIBED
EXCEEDED_MAX_SUBSCRIPTIONS
INVALID_URL
}
union AddPopularReadResult = AddPopularReadSuccess | AddPopularReadError
Expand Down

1 comment on commit a0f9366

@vercel
Copy link

@vercel vercel bot commented on a0f9366 Dec 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.