Skip to content

Commit

Permalink
Merge pull request #68 from leozqin/delete-stuff
Browse files Browse the repository at this point in the history
Delete stuff
  • Loading branch information
leozqin authored Sep 29, 2024
2 parents c5ea26c + 906aa46 commit 11424f3
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 4 deletions.
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ RUN uv pip install .

FROM nikolaik/python-nodejs:python3.11-nodejs22-slim as web

LABEL org.opencontainers.image.title="Precis"
LABEL org.opencontainers.image.authors="[email protected]"
LABEL org.opencontainers.image.source="https://github.com/leozqin/precis"
LABEL org.opencontainers.image.url="https://github.com/leozqin/precis"
LABEL org.opencontainers.image.description="An extensible self-hosted AI-enabled RSS reader with a focus on notifications and support for theming"
LABEL org.opencontainers.image.licenses=MIT

WORKDIR /app
ENV IS_DOCKER=True

Expand Down
11 changes: 11 additions & 0 deletions app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,17 @@ async def refresh_feed(feed_id: str, request: Request):
)


@app.get("/api/delete_feed/{feed_id}", status_code=status.HTTP_200_OK)
async def delete_feed(feed_id: str, request: Request):

await bk.delete_feed(feed_id=feed_id)

return RedirectResponse(
request.url_for("feeds"),
status_code=status.HTTP_303_SEE_OTHER,
)


@app.post("/api/update_settings/", status_code=status.HTTP_200_OK)
async def update_settings(
theme: Annotated[str, Form()],
Expand Down
11 changes: 11 additions & 0 deletions app/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,17 @@ async def update_handler(self, handler: str, config: str):
handler_obj = self.db.reconfigure_handler(id=handler, config=config_dict)
self.db.upsert_handler(handler=handler_obj)

async def delete_feed(self, feed_id: str):

feed = self.db.get_feed(id=feed_id)

entries = self.db.get_entries(feed=feed)
for entry_dict in entries:
entry: FeedEntry = entry_dict.get("entry")
self.db.delete_feed_entry(feed_entry=entry)

self.db.delete_feed(feed=feed)

@staticmethod
async def list_content_handler_choices():
from app.content import content_retrieval_handlers
Expand Down
18 changes: 17 additions & 1 deletion app/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ def upsert_feed_entry(self, feed: Feed, entry: FeedEntry) -> None:
pass

@abstractmethod
def get_entries(self, feed: Feed = None, after: int = 0) -> List[Mapping[str, str]]:
def get_entries(
self, feed: Feed = None, after: int = 0
) -> List[Mapping[str, FeedEntry]]:
"""
Given a feed, retrieve the entries for that feed and return a list of
dicts, where each dict has key entry = FeedEntry object, feed_id = the
Expand Down Expand Up @@ -273,6 +275,20 @@ def upsert_settings(self, settings: GlobalSettings) -> None:
"""
pass

@abstractmethod
def delete_feed(self, feed: Feed) -> None:
"""
Given a feed, delete the feed from the database.
"""
pass

@abstractmethod
def delete_feed_entry(self, feed_entry: FeedEntry) -> None:
"""
Given a feed entry, delete the entry from the database.
"""
pass

@staticmethod
async def get_entry_html(url: str, settings: GlobalSettings) -> str:
return await settings.content_retrieval_handler.get_content(url)
Expand Down
30 changes: 30 additions & 0 deletions app/storage/lmdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,33 @@ def upsert_settings(self, settings: GlobalSettings) -> None:
self.upsert_handler(settings.notification_handler)
self.upsert_handler(settings.summarization_handler)
self.upsert_handler(settings.content_retrieval_handler)

def delete_feed(self, feed: Feed) -> None:

with self.db.begin(db=self._db(Named.feed), write=True) as txn:
txn.delete(self._serialize(feed.id))

with self.db.begin(db=self._db(Named.si_feed_entry), write=True) as txn:
txn.delete(self._serialize(feed.id))

with self.db.begin(db=self._db(Named.poll), write=True) as txn:
txn.delete(self._serialize(feed.id))

with self.db.begin(db=self._db(Named.feed_start), write=True) as txn:
txn.delete(self._serialize(feed.id))

def delete_feed_entry(self, feed_entry: FeedEntry) -> None:

with self.db.begin(db=self._db(Named.entry_content), write=True) as txn:
txn.delete(self._serialize(feed_entry.id))

with self.db.begin(db=self._db(Named.entry), write=True) as txn:
txn.delete(self._serialize(feed_entry.id))

with self.db.begin(db=self._db(Named.si_feed_entry), write=True) as txn:
value = txn.get(self._serialize(feed_entry.feed_id))

entries: List[str] = self._deserialize(value)
entries.remove(feed_entry.id)

txn.replace(self._serialize(feed_entry.feed_id), self._serialize(entries))
19 changes: 19 additions & 0 deletions app/storage/tinydb.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,22 @@ def upsert_settings(self, settings: GlobalSettings) -> None:
self.upsert_handler(settings.notification_handler)
self.upsert_handler(settings.summarization_handler)
self.upsert_handler(settings.content_retrieval_handler)

def delete_feed(self, feed: Feed) -> None:
feeds = self.db.table("feeds")
query = Query().id.matches(feed.id)
feeds.remove(query)

feed_start = self.db.table("feed_start")
feed_start.remove(query)

poll = self.db.table("poll")
poll.remove(query)

def delete_feed_entry(self, feed_entry: FeedEntry) -> None:
entry_contents = self.db.table("entry_contents")
query = Query().id.matches(feed_entry.id)
entry_contents.remove(query)

entries = self.db.table("entries")
entries.remove(query)
13 changes: 11 additions & 2 deletions app/templates/feed_config.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,16 @@ <h2 class="text-4xl lg:text-2xl my-5 justify-center flex">
</label>
<label class="label cursor-pointer gap-2">
<span class="label-text text-2xl lg:text-xl">Send Notifications</span>
<input name="notify" type="checkbox" class="toggle" {% if feed.notify != False %} checked {% endif %} />
<input name="notify" type="checkbox" class="toggle" {% if feed.notify !=False %} checked {% endif %} />
</label>
<label class="label cursor-pointer gap-2">
<span class="label-text text-2xl lg:text-xl">Preview Only (No Summary)</span>
<input name="preview_only" type="checkbox" class="toggle" {% if feed.preview_only %} checked {% endif %} />
</label>
<label class="label cursor-pointer gap-2">
<span class="label-text text-2xl lg:text-xl">Refresh Enabled</span>
<input name="refresh_enabled" type="checkbox" class="toggle" {% if feed.refresh_enabled != False %} checked {% endif %} />
<input name="refresh_enabled" type="checkbox" class="toggle" {% if feed.refresh_enabled !=False %} checked {%
endif %} />
</label>
</div>
<div>
Expand All @@ -99,6 +100,14 @@ <h2 class="text-4xl lg:text-2xl my-5 justify-center flex">
{% if update_status %} &#9989 {% endif %}
{% if update_exception %} &#10060 {% endif %}
</button>
{% if feed.url %}
<a href="{{ url_for('delete_feed', feed_id=feed.id) }}">
<button type="button"
class="btn btn-outline w-1/2 lg:w-2/5 mx-auto flex justify-center my-5 text-3xl lg:text-xl">
Delete Feed
</button>
</a>
{% endif %}
{% if update_exception %}
<div role="alert" class="alert alert-error">
<svg xmlns="http://www.w3.org/2000/svg" class="stroke-current shrink-0 h-6 w-6" fill="none"
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "precis"
version = "0.2.9"
version = "0.3.0"
description = "A framework for automating your media diet"
requires-python = ">=3.11"
license = {file = "LICENSE"}
Expand Down

0 comments on commit 11424f3

Please sign in to comment.