mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 19:01:39 -04:00
Changing Archive Sync to Update and Alternatives to History.
This commit is contained in:
parent
a17eb6559e
commit
11bd59cec0
7 changed files with 51 additions and 53 deletions
|
|
@ -411,7 +411,7 @@ export async function getArchive(archiveId) {
|
|||
const response = await apiGet(`${ARCHIVES_API}/${archiveId}`);
|
||||
if (response.status === 200) {
|
||||
const data = await response.json();
|
||||
return [data['file'], data['alternatives']];
|
||||
return [data['file'], data['history']];
|
||||
} else {
|
||||
toast({
|
||||
type: 'error', title: 'Archive Error', description: 'Unable to get Archive. See server logs.', time: 5000,
|
||||
|
|
|
|||
|
|
@ -41,10 +41,10 @@ import {Button, CardIcon, Header, Loader, Placeholder, Segment, Table} from "./T
|
|||
|
||||
function ArchivePage() {
|
||||
const [deleteOpen, setDeleteOpen] = useState(false);
|
||||
const [syncOpen, setSyncOpen] = useState(false);
|
||||
const [updateOpen, setUpdateOpen] = useState(false);
|
||||
const navigate = useNavigate();
|
||||
const {archiveId} = useParams();
|
||||
const {archiveFile, alternatives} = useArchive(archiveId);
|
||||
const {archiveFile, history} = useArchive(archiveId);
|
||||
|
||||
let title;
|
||||
if (archiveFile && archiveFile.archive) {
|
||||
|
|
@ -85,19 +85,19 @@ function ArchivePage() {
|
|||
await deleteArchives([archive.id]);
|
||||
navigate(-1);
|
||||
}
|
||||
const localSyncArchive = async () => {
|
||||
setSyncOpen(false);
|
||||
const localUpdateArchive = async () => {
|
||||
setUpdateOpen(false);
|
||||
await postDownload(archive.url, 'archive');
|
||||
}
|
||||
|
||||
const syncButton = (<>
|
||||
<Button color='yellow' onClick={() => setSyncOpen(true)} content='Sync'/>
|
||||
const updateButton = (<>
|
||||
<Button color='yellow' onClick={() => setUpdateOpen(true)} content='Update'/>
|
||||
<Confirm
|
||||
open={syncOpen}
|
||||
open={updateOpen}
|
||||
content='Download the latest version of this URL?'
|
||||
confirmButton='Sync'
|
||||
onCancel={() => setSyncOpen(false)}
|
||||
onConfirm={localSyncArchive}
|
||||
confirmButton='Update'
|
||||
onCancel={() => setUpdateOpen(false)}
|
||||
onConfirm={localUpdateArchive}
|
||||
/>
|
||||
</>);
|
||||
const deleteButton = (<>
|
||||
|
|
@ -111,11 +111,11 @@ function ArchivePage() {
|
|||
/>
|
||||
</>);
|
||||
|
||||
let alternativesList = <Loader active/>;
|
||||
if (!isEmpty(alternatives)) {
|
||||
alternativesList = <FileCards files={alternatives}/>;
|
||||
} else if (isEmpty(alternatives)) {
|
||||
alternativesList = <p>No alternatives available</p>;
|
||||
let historyList = <Loader active/>;
|
||||
if (!isEmpty(history)) {
|
||||
historyList = <FileCards files={history}/>;
|
||||
} else if (isEmpty(history)) {
|
||||
historyList = <p>No history available</p>;
|
||||
}
|
||||
|
||||
const domain = archive.domain ? archive.domain.domain : null;
|
||||
|
|
@ -153,16 +153,16 @@ function ArchivePage() {
|
|||
|
||||
{singlefileButton}
|
||||
{readabilityLink}
|
||||
{syncButton}
|
||||
{updateButton}
|
||||
{deleteButton}
|
||||
</Segment>
|
||||
|
||||
<Segment>
|
||||
<HelpHeader
|
||||
headerContent='Alternatives'
|
||||
popupContent='Alternative archives are archives that have the same URL.'
|
||||
headerContent='History'
|
||||
popupContent='Other archives of this URL created at different times.'
|
||||
/>
|
||||
{alternativesList}
|
||||
{historyList}
|
||||
</Segment>
|
||||
</>
|
||||
)
|
||||
|
|
|
|||
|
|
@ -81,13 +81,13 @@ export const useDomains = () => {
|
|||
|
||||
export const useArchive = (archiveId) => {
|
||||
const [archiveFile, setArchiveFile] = useState(null);
|
||||
const [alternatives, setAlternatives] = useState(null);
|
||||
const [history, setHistory] = useState(null);
|
||||
|
||||
const fetchArchive = async () => {
|
||||
try {
|
||||
const [file, alt] = await getArchive(archiveId);
|
||||
const [file, history] = await getArchive(archiveId);
|
||||
setArchiveFile(file);
|
||||
setAlternatives(alt);
|
||||
setHistory(history);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
setArchiveFile(undefined);
|
||||
|
|
@ -98,7 +98,7 @@ export const useArchive = (archiveId) => {
|
|||
fetchArchive();
|
||||
}, [archiveId]);
|
||||
|
||||
return {archiveFile, alternatives};
|
||||
return {archiveFile, history};
|
||||
}
|
||||
|
||||
export const useQuery = () => {
|
||||
|
|
|
|||
|
|
@ -23,8 +23,8 @@ logger = logger.getChild(__name__)
|
|||
async def get_archive(_: Request, archive_id: int):
|
||||
archive = lib.get_archive(archive_id=archive_id)
|
||||
archive_file = archive.singlefile_file.__json__()
|
||||
alternatives = [i.singlefile_file.__json__() for i in archive.alternatives]
|
||||
return json_response({'file': archive_file, 'alternatives': alternatives})
|
||||
history = [i.singlefile_file.__json__() for i in archive.history]
|
||||
return json_response({'file': archive_file, 'history': history})
|
||||
|
||||
|
||||
@bp.delete('/<archive_ids:int>')
|
||||
|
|
|
|||
|
|
@ -129,17 +129,15 @@ class Archive(Base, ModelHelper):
|
|||
self.domain.delete()
|
||||
|
||||
@property
|
||||
def alternatives(self) -> Iterable[Base]:
|
||||
"""
|
||||
Get a list of Archives that share my URL.
|
||||
"""
|
||||
def history(self) -> Iterable[Base]:
|
||||
"""Get a list of Archives that share my URL."""
|
||||
session = Session.object_session(self)
|
||||
alternatives = list(session.query(Archive).filter(
|
||||
history = list(session.query(Archive).filter(
|
||||
Archive.id != self.id,
|
||||
Archive.url == self.url,
|
||||
Archive.url != None,
|
||||
Archive.url != None, # noqa
|
||||
).order_by(Archive.archive_datetime))
|
||||
return alternatives
|
||||
return history
|
||||
|
||||
def read_singlefile_data(self):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -118,17 +118,17 @@ def test_archive_and_domain_crud(test_session, test_client, archive_factory):
|
|||
archive2 = archive_factory(domain='example.com', url='https://example.com/1')
|
||||
test_session.commit()
|
||||
|
||||
# Archive1 has Archive2 as alternative.
|
||||
# Archive1 has Archive2 as history.
|
||||
request, response = test_client.get(f'/api/archive/{archive1.id}')
|
||||
assert response.status_code == HTTPStatus.OK
|
||||
assert response.json['file']['archive']['id'] == archive1.id
|
||||
assert response.json['alternatives'][0]['archive']['id'] == archive2.id
|
||||
assert response.json['history'][0]['archive']['id'] == archive2.id
|
||||
|
||||
# Archive2 has Archive1 as alternative.
|
||||
# Archive2 has Archive1 as history.
|
||||
request, response = test_client.get(f'/api/archive/{archive2.id}')
|
||||
assert response.status_code == HTTPStatus.OK
|
||||
assert archive2.id == response.json['file']['archive']['id']
|
||||
assert response.json['alternatives'][0]['archive']['id'] == archive1.id
|
||||
assert response.json['history'][0]['archive']['id'] == archive1.id
|
||||
|
||||
# Only one domain.
|
||||
request, response = test_client.get(f'/api/archive/domains')
|
||||
|
|
@ -147,11 +147,11 @@ def test_archive_and_domain_crud(test_session, test_client, archive_factory):
|
|||
request, response = test_client.get(f'/api/archive/{archive1.id}')
|
||||
assert response.status_code == HTTPStatus.NOT_FOUND
|
||||
|
||||
# Archive2 no longer has alternatives.
|
||||
# Archive2 no longer has history.
|
||||
request, response = test_client.get(f'/api/archive/{archive2.id}')
|
||||
assert response.status_code == HTTPStatus.OK
|
||||
assert response.json['file']['archive']['id'] == archive2.id
|
||||
assert response.json['alternatives'] == []
|
||||
assert response.json['history'] == []
|
||||
|
||||
# No Archives, no Domains.
|
||||
request, response = test_client.delete(f'/api/archive/{archive2.id}')
|
||||
|
|
|
|||
|
|
@ -688,8 +688,8 @@ async def test_archive_download_index(test_session, test_directory, image_file):
|
|||
and archive.screenshot_file.associated, 'Archive files must be associated'
|
||||
|
||||
|
||||
def test_archive_alternatives(test_session, archive_factory):
|
||||
"""Archive's that share a URL are alternatives.
|
||||
def test_archive_history(test_session, archive_factory):
|
||||
"""Archive's can have a history of other archives.
|
||||
|
||||
Archive's with an empty URL are not associated."""
|
||||
archive1 = archive_factory(url='https://example.com/1')
|
||||
|
|
@ -698,18 +698,18 @@ def test_archive_alternatives(test_session, archive_factory):
|
|||
archive4 = archive_factory()
|
||||
archive5 = archive_factory()
|
||||
|
||||
assert archive1 in archive2.alternatives, 'archive1 is an alternative for archive2'
|
||||
assert archive2 in archive1.alternatives, 'archive2 is an alternative for archive2'
|
||||
assert archive3 not in archive1.alternatives and archive3 not in archive2.alternatives, 'archive3 is unique'
|
||||
assert not archive3.alternatives, 'archive3 has no alternatives'
|
||||
assert not archive4.alternatives, 'archive4 has no alternatives'
|
||||
assert not archive5.alternatives, 'archive5 has no alternatives'
|
||||
assert archive1 in archive2.history, 'archive1 is a history for archive2'
|
||||
assert archive2 in archive1.history, 'archive2 is a history for archive2'
|
||||
assert archive3 not in archive1.history and archive3 not in archive2.history, 'archive3 is unique'
|
||||
assert not archive3.history, 'archive3 has no history'
|
||||
assert not archive4.history, 'archive4 has no history'
|
||||
assert not archive5.history, 'archive5 has no history'
|
||||
|
||||
test_session.commit()
|
||||
|
||||
assert archive1 in archive2.alternatives, 'archive1 is an alternative for archive2'
|
||||
assert archive2 in archive1.alternatives, 'archive2 is an alternative for archive2'
|
||||
assert archive3 not in archive1.alternatives and archive3 not in archive2.alternatives, 'archive3 is unique'
|
||||
assert not archive3.alternatives, 'archive3 has no alternatives'
|
||||
assert not archive4.alternatives, 'archive4 has no alternatives'
|
||||
assert not archive5.alternatives, 'archive5 has no alternatives'
|
||||
assert archive1 in archive2.history, 'archive1 is a history for archive2'
|
||||
assert archive2 in archive1.history, 'archive2 is a history for archive2'
|
||||
assert archive3 not in archive1.history and archive3 not in archive2.history, 'archive3 is unique'
|
||||
assert not archive3.history, 'archive3 has no history'
|
||||
assert not archive4.history, 'archive4 has no history'
|
||||
assert not archive5.history, 'archive5 has no history'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue