@@ -282,8 +308,11 @@ export function ArchiveRoute(props) {
];
return
-
-
-
+
+
+
+
+
+
}
diff --git a/app/src/components/Common.js b/app/src/components/Common.js
index d4ec311b..af6d255a 100644
--- a/app/src/components/Common.js
+++ b/app/src/components/Common.js
@@ -4,6 +4,7 @@ import {
Checkbox,
Container,
Form,
+ Header,
Icon,
Image,
Input,
@@ -714,6 +715,17 @@ export function HelpPopup({icon, size, content, position}) {
/>
}
+export function HelpHeader({icon, headerSize, iconSize, headerContent, popupContent}) {
+ return (
+
+
+
+
+
+
+ )
+}
+
export function minutesToTimestamp(minutes) {
minutes = Math.round(minutes);
const hours = String(Math.floor(minutes / 60)).padStart(1, '0');
diff --git a/app/src/hooks/customHooks.js b/app/src/hooks/customHooks.js
index c3fb1485..cc6ef3b3 100644
--- a/app/src/hooks/customHooks.js
+++ b/app/src/hooks/customHooks.js
@@ -3,6 +3,7 @@ import {
fetchDomains,
filesSearch,
getAPIStatus,
+ getArchive,
getDownloaders,
getFiles,
getHotspotStatus,
@@ -152,6 +153,28 @@ export const useArchives = ({defaultLimit = 20}) => {
};
}
+export const useArchive = (archiveId) => {
+ const [archive, setArchive] = useState(null);
+ const [alternatives, setAlternatives] = useState(null);
+
+ const fetchArchive = async () => {
+ try {
+ const [a, alt] = await getArchive(archiveId);
+ setArchive(a);
+ setAlternatives(alt);
+ } catch (e) {
+ console.error(e);
+ setArchive(undefined);
+ }
+ }
+
+ useEffect(() => {
+ fetchArchive();
+ }, [archiveId]);
+
+ return [archive, alternatives];
+}
+
export const useVersion = () => {
const [version, setVersion] = useState('');
diff --git a/app/src/static/wrolpi.css b/app/src/static/wrolpi.css
index 6fd0b1e5..99d090af 100644
--- a/app/src/static/wrolpi.css
+++ b/app/src/static/wrolpi.css
@@ -2,3 +2,27 @@ textarea.otp {
width: 100%;
color: #333;
}
+
+.inline-header h1 {
+ display: inline-block;
+}
+
+.inline-header h2 {
+ display: inline-block;
+}
+
+.inline-header h3 {
+ display: inline-block;
+}
+
+.inline-header h4 {
+ display: inline-block;
+}
+
+.inline-header h5 {
+ display: inline-block;
+}
+
+.inline-header span {
+ margin-left: 1em;
+}
diff --git a/modules/archive/__init__.py b/modules/archive/__init__.py
index 981561a6..db9d3aff 100644
--- a/modules/archive/__init__.py
+++ b/modules/archive/__init__.py
@@ -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.
diff --git a/modules/archive/api.py b/modules/archive/api.py
index c58a882c..b8a62e28 100644
--- a/modules/archive/api.py
+++ b/modules/archive/api.py
@@ -18,6 +18,15 @@ bp = get_blueprint('Archive', '/api/archive')
logger = logger.getChild(__name__)
+@bp.get('/
')
+@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('/')
@openapi.description('Delete an individual archive')
@openapi.response(HTTPStatus.NOT_FOUND, JSONErrorResponse)
diff --git a/modules/archive/lib.py b/modules/archive/lib.py
index 16379707..170151fe 100644
--- a/modules/archive/lib.py
+++ b/modules/archive/lib.py
@@ -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:
diff --git a/modules/archive/models.py b/modules/archive/models.py
index 908afa7a..78779ec7 100644
--- a/modules/archive/models.py
+++ b/modules/archive/models.py
@@ -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
diff --git a/modules/videos/channel/test/test_api.py b/modules/videos/channel/test/test_api.py
index 1c77df11..55d27888 100644
--- a/modules/videos/channel/test/test_api.py
+++ b/modules/videos/channel/test/test_api.py
@@ -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):
diff --git a/modules/videos/models.py b/modules/videos/models.py
index 31b93f47..9edc1243 100644
--- a/modules/videos/models.py
+++ b/modules/videos/models.py
@@ -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)