remove feeds table

This commit is contained in:
Hongbo Wu
2023-11-14 15:27:58 +08:00
parent 05b386ad79
commit 3d84108202
4 changed files with 15 additions and 58 deletions

View File

@ -1,6 +1,5 @@
import Parser from 'rss-parser'
import { Brackets } from 'typeorm'
import { Feed } from '../../entity/feed'
import { Subscription } from '../../entity/subscription'
import { env } from '../../env'
import {
@ -227,44 +226,25 @@ export const subscribeResolver = authorized<
// validate rss feed
const feed = await parser.parseURL(input.url)
const results = await authTrx(async (t) => {
if (!input.isPrivate) {
await t.getRepository(Feed).upsert(
{
url: feed.feedUrl,
title: feed.title,
description: feed.description,
image: feed.image?.url,
},
{
conflictPaths: ['url'],
skipUpdateIfNoValuesChanged: true,
}
)
}
// limit number of rss subscriptions to 150
const results = (await t.getRepository(Subscription).query(
`insert into omnivore.subscriptions (name, url, description, type, user_id, icon, auto_add_to_library, is_private)
// limit number of rss subscriptions to 150
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 from omnivore.subscriptions
where user_id = $5 and type = 'RSS' and status = 'ACTIVE'
having count(*) < $9
returning *;`,
[
feed.title,
feed.feedUrl,
feed.description || null,
SubscriptionType.Rss,
uid,
feed.image?.url || null,
input.autoAddToLibrary ?? null,
input.isPrivate ?? null,
MAX_RSS_SUBSCRIPTIONS,
]
)) as Subscription[]
return results
})
[
feed.title,
feed.feedUrl,
feed.description || null,
SubscriptionType.Rss,
uid,
feed.image?.url || null,
input.autoAddToLibrary ?? null,
input.isPrivate ?? null,
MAX_RSS_SUBSCRIPTIONS,
]
)) as Subscription[]
if (results.length === 0) {
return {

View File

@ -3,7 +3,6 @@ import 'mocha'
import Parser from 'rss-parser'
import sinon from 'sinon'
import sinonChai from 'sinon-chai'
import { Feed } from '../../src/entity/feed'
import { NewsletterEmail } from '../../src/entity/newsletter_email'
import { Subscription } from '../../src/entity/subscription'
import { User } from '../../src/entity/user'
@ -406,7 +405,6 @@ describe('Subscriptions API', () => {
after(async () => {
await deleteSubscription(existingSubscription.id)
await getRepository(Feed).delete({ url: existingSubscription.url })
})
it('returns an error', async () => {

View File

@ -22,23 +22,4 @@ CREATE POLICY library_item_admin_policy on omnivore.library_item
TO omnivore_admin
USING (true);
CREATE TABLE omnivore.feed (
id uuid PRIMARY KEY DEFAULT uuid_generate_v1mc(),
title text NOT NULL,
url text NOT NULL,
author text,
description text,
image text,
created_at timestamptz NOT NULL DEFAULT current_timestamp,
updated_at timestamptz NOT NULL DEFAULT current_timestamp,
published_at timestamptz,
UNIQUE(url)
);
CREATE INDEX feed_title_idx ON omnivore.feed(title);
CREATE TRIGGER update_feed_modtime BEFORE UPDATE ON omnivore.feed FOR EACH ROW EXECUTE PROCEDURE update_updated_at_column();
GRANT SELECT, INSERT, UPDATE, DELETE ON omnivore.feed TO omnivore_user;
COMMIT;

View File

@ -4,8 +4,6 @@
BEGIN;
DROP TABLE omnivore.feed;
DROP policy library_item_admin_policy ON omnivore.library_item;
ALTER TABLE omnivore.library_item