Feature/127 archive UI rework (#131)

* Archives have their own page.  Delete/etc buttons are moved into ArchivePage.

* Alternatives for an Archive are displayed in the ArchivePage.

* ArchiveDownloader returns the location.

* Removing color from Details button.

* Making Archive screenshot and title a link.

* Preserving next_download when updating a Channel.

* Removing button icons from Archive page.
This commit is contained in:
lrnselfreliance 2022-05-16 17:56:55 -06:00 • committed by Roland
parent 2314c3462f
commit 0765890b8b
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
12 changed files with 238 additions and 99 deletions

View file

@ -30,8 +30,8 @@ class ArchiveDownloader(Downloader, ABC):
if download.attempts > 3:
raise UnrecoverableDownloadError(f'Max download attempts reached for {download.url}')
lib.do_archive(download.url)
return DownloadResult(success=True)
archive = lib.do_archive(download.url)
return DownloadResult(success=True, location=f'/archive/{archive.id}')
# Archive downloader is the last downloader which should be used.

View file

@ -18,6 +18,15 @@ bp = get_blueprint('Archive', '/api/archive')
logger = logger.getChild(__name__)
@bp.get('/<archive_id:int>')
@openapi.description('Get an archive')
@openapi.response(HTTPStatus.NOT_FOUND, JSONErrorResponse)
async def get_archive(_: Request, archive_id: int):
archive = lib.get_archive(archive_id=archive_id)
alternatives = archive.alternatives
return json_response({'archive': archive, 'alternatives': alternatives})
@bp.delete('/<archive_id:int>')
@openapi.description('Delete an individual archive')
@openapi.response(HTTPStatus.NOT_FOUND, JSONErrorResponse)

View file

@ -19,7 +19,7 @@ from modules.archive.models import Domain, Archive
from wrolpi.cmd import which
from wrolpi.common import get_media_directory, logger, chunks, extract_domain, chdir, escape_file_name, walk
from wrolpi.dates import now, Seconds, local_timezone
from wrolpi.db import get_db_session, get_db_curs, get_ranked_models
from wrolpi.db import get_db_session, get_db_curs, get_ranked_models, optional_session
from wrolpi.errors import InvalidDomain, UnknownURL, InvalidArchive
from wrolpi.vars import DOCKERIZED, PYTEST
@ -330,10 +330,17 @@ def get_domain(session, domain: str) -> Domain:
return domain_
@optional_session
def get_archive(session, archive_id: int) -> Archive:
"""Get an Archive."""
archive = session.query(Archive).filter_by(id=archive_id).one_or_none()
if not archive:
raise InvalidArchive(f'Invalid archive id: {archive_id}')
return archive
def delete_archive(archive_id: int):
"""
Delete an Archive and all of it's files.
"""
"""Delete an Archive and all of it's files."""
with get_db_session(commit=True) as session:
archive: Archive = session.query(Archive).filter_by(id=archive_id).one_or_none()
if not archive:

View file

@ -90,6 +90,18 @@ class Archive(Base, ModelHelper):
if not domain_archives:
self.domain.delete()
@property
def alternatives(self):
"""
Get a list of Archives that share my URL.
"""
session = Session.object_session(self)
i = list(session.query(Archive).filter(
Archive.id != self.id,
Archive.url == self.url,
).order_by(Archive.archive_datetime))
return i
class Domain(Base, ModelHelper):
__tablename__ = 'domains' # plural to avoid conflict

View file

@ -1,6 +1,7 @@
import json
import pathlib
import tempfile
import time
from datetime import timedelta
from http import HTTPStatus
@ -171,16 +172,22 @@ def test_channel_download_crud(test_session, simple_channel):
simple_channel.update({'url': 'https://example.com'})
test_session.commit()
# Adding a frequency adds a Download.
simple_channel.update({'download_frequency': 1})
test_session.commit()
assert test_session.query(Download).count() == 1
next_download = simple_channel.get_download().next_download
assert next_download
def test_delete_channel_delete_download(download_channel, test_session):
"""Deleting a Channel deletes it's Download."""
downloads = test_session.query(Download).all()
assert downloads and all(i.url == download_channel.url for i in downloads)
# Next download isn't overwritten.
time.sleep(1)
simple_channel.update({'name': 'new name'})
test_session.commit()
assert simple_channel.get_download().next_download == next_download
delete_channel(channel_id=download_channel.id)
downloads = test_session.query(Download).all()
assert not list(downloads)
# Deleting a Channel deletes it's Download.
delete_channel(channel_id=simple_channel.id)
assert test_session.query(Download).count() == 0
def test_video_search(test_client, test_session):

View file

@ -316,7 +316,8 @@ class Channel(ModelHelper, Base):
elif download and self.download_frequency:
download.frequency = self.download_frequency
download.url = self.url
download.next_download = download_manager.get_next_download(download, session)
# Keep next_download if available.
download.next_download = download.next_download or download_manager.get_next_download(download, session)
elif not download and self.download_frequency and self.url:
download = Download(frequency=self.download_frequency, url=self.url, downloader='video_channel')
session.add(download)