2022-01-03 15:13:02 -07:00
|
|
|
import React, {useState} from "react";
|
2022-05-16 17:56:55 -06:00
|
|
|
import {Card, Confirm, Container, Header, Image, Loader, Placeholder, Segment} from "semantic-ui-react";
|
2022-02-02 08:24:34 -07:00
|
|
|
import {
|
2022-01-31 09:53:17 -07:00
|
|
|
CardGroupCentered,
|
2022-01-29 21:24:39 -07:00
|
|
|
ClearButton,
|
2022-05-16 17:56:55 -06:00
|
|
|
HelpHeader,
|
2022-02-02 14:02:51 -07:00
|
|
|
PageContainer,
|
|
|
|
|
Paginator,
|
2022-01-29 21:24:39 -07:00
|
|
|
SearchInput,
|
2022-01-29 22:25:35 -07:00
|
|
|
TabLinks,
|
2022-01-29 21:24:39 -07:00
|
|
|
textEllipsis,
|
|
|
|
|
uploadDate,
|
|
|
|
|
WROLModeMessage
|
|
|
|
|
} from "./Common";
|
2022-01-03 15:13:02 -07:00
|
|
|
import {deleteArchive, postDownload, refreshArchives} from "../api";
|
2021-11-01 16:42:52 -06:00
|
|
|
import Button from "semantic-ui-react/dist/commonjs/elements/Button";
|
2022-05-16 17:56:55 -06:00
|
|
|
import {Link, Route, Switch, useHistory} from "react-router-dom";
|
2021-11-01 16:42:52 -06:00
|
|
|
import {ArchivePlaceholder} from "./Placeholder";
|
2022-01-03 15:13:02 -07:00
|
|
|
import Table from "semantic-ui-react/dist/commonjs/collections/Table";
|
2022-01-15 18:05:51 -07:00
|
|
|
import Message from "semantic-ui-react/dist/commonjs/collections/Message";
|
2022-05-16 17:56:55 -06:00
|
|
|
import {useArchive, useArchives, useDomains} from "../hooks/customHooks";
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2022-05-16 17:56:55 -06:00
|
|
|
function ArchivePage(props) {
|
2022-01-03 15:13:02 -07:00
|
|
|
const [deleteOpen, setDeleteOpen] = useState(false);
|
2022-05-16 17:56:55 -06:00
|
|
|
const [syncOpen, setSyncOpen] = useState(false);
|
|
|
|
|
const history = useHistory();
|
|
|
|
|
const archiveId = props.match.params.archive_id;
|
|
|
|
|
const [archive, alternatives] = useArchive(archiveId);
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2022-05-16 17:56:55 -06:00
|
|
|
if (archive === null) {
|
|
|
|
|
return <Segment><Loader active/></Segment>;
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
2022-05-16 17:56:55 -06:00
|
|
|
if (archive === undefined) {
|
|
|
|
|
return <>
|
|
|
|
|
<Header as='h2'>Unknown archive</Header>
|
|
|
|
|
This archive does not exist
|
|
|
|
|
</>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const singlefileUrl = archive.singlefile_path ? `/media/${encodeURIComponent(archive.singlefile_path)}` : null;
|
|
|
|
|
const screenshotUrl = archive.screenshot_path ? `/media/${encodeURIComponent(archive.screenshot_path)}` : null;
|
|
|
|
|
const readabilityUrl = archive.readability_path ? `/media/${encodeURIComponent(archive.readability_path)}` : null;
|
|
|
|
|
|
|
|
|
|
const singlefileButton = <a href={singlefileUrl} target='_blank'>
|
|
|
|
|
<Button content='View' color='blue'/>
|
|
|
|
|
</a>;
|
|
|
|
|
|
|
|
|
|
const readabilityLink = readabilityUrl ?
|
|
|
|
|
<a href={readabilityUrl} target='_blank'><Button content='Article'/></a> :
|
|
|
|
|
<Button disabled content='Article'/>;
|
|
|
|
|
|
|
|
|
|
const screenshot = screenshotUrl ?
|
|
|
|
|
<Image src={screenshotUrl} size='large' style={{marginTop: '1em', marginBottom: '1em'}}/> :
|
|
|
|
|
null;
|
|
|
|
|
|
2022-01-03 15:13:02 -07:00
|
|
|
const localDeleteArchive = async () => {
|
|
|
|
|
setDeleteOpen(false);
|
|
|
|
|
await deleteArchive(archive.id);
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
2022-05-16 17:56:55 -06:00
|
|
|
const localSyncArchive = async () => {
|
|
|
|
|
setSyncOpen(false);
|
|
|
|
|
await postDownload(archive.url, 'archive');
|
|
|
|
|
}
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2022-05-16 17:56:55 -06:00
|
|
|
const syncButton = (<>
|
|
|
|
|
<Button color='yellow' onClick={() => setSyncOpen(true)} content='Sync'/>
|
|
|
|
|
<Confirm
|
|
|
|
|
open={syncOpen}
|
|
|
|
|
content='Download the latest version of this URL?'
|
|
|
|
|
confirmButton='Sync'
|
|
|
|
|
onCancel={() => setSyncOpen(false)}
|
|
|
|
|
onConfirm={localSyncArchive}
|
|
|
|
|
/>
|
|
|
|
|
</>);
|
|
|
|
|
const deleteButton = (<>
|
|
|
|
|
<Button color='red' onClick={() => setDeleteOpen(true)} content='Delete' aria-label='Delete'/>
|
|
|
|
|
<Confirm
|
|
|
|
|
open={deleteOpen}
|
|
|
|
|
content='Are you sure you want to delete this archive? All files will be deleted'
|
|
|
|
|
confirmButton='Delete'
|
|
|
|
|
onCancel={() => setDeleteOpen(false)}
|
|
|
|
|
onConfirm={localDeleteArchive}
|
|
|
|
|
/>
|
|
|
|
|
</>);
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2022-05-16 17:56:55 -06:00
|
|
|
let alternativesList = <Loader active/>;
|
|
|
|
|
if (alternatives && alternatives.length > 0) {
|
|
|
|
|
alternativesList = <ArchivesList archives={alternatives}/>;
|
|
|
|
|
} else if (alternatives && alternatives.length === 0) {
|
|
|
|
|
alternativesList = <p>No alternatives available</p>;
|
2022-01-03 15:13:02 -07:00
|
|
|
}
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2022-05-16 17:56:55 -06:00
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<Button icon='arrow left' content='Back' onClick={() => history.goBack()}/>
|
|
|
|
|
|
|
|
|
|
<Segment>
|
|
|
|
|
{screenshot}
|
|
|
|
|
<a href={singlefileUrl} target='_blank' className='no-link-underscore card-link'>
|
|
|
|
|
<Header as='h2'>{textEllipsis(archive.title || archive.url, 100)}</Header>
|
|
|
|
|
</a>
|
|
|
|
|
<Header as='h3'>{uploadDate(archive.archive_datetime)}</Header>
|
|
|
|
|
<p><a href={archive.url} target='_blank'>{textEllipsis(archive.url, 100)}</a></p>
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2022-05-16 17:56:55 -06:00
|
|
|
{singlefileButton}
|
|
|
|
|
{readabilityLink}
|
|
|
|
|
{syncButton}
|
|
|
|
|
{deleteButton}
|
|
|
|
|
</Segment>
|
|
|
|
|
|
|
|
|
|
<Segment>
|
|
|
|
|
<HelpHeader
|
|
|
|
|
headerContent='Alternatives'
|
|
|
|
|
popupContent='Alternative archives are archives that have the same URL.'
|
2021-11-01 16:42:52 -06:00
|
|
|
/>
|
2022-05-16 17:56:55 -06:00
|
|
|
{alternativesList}
|
|
|
|
|
</Segment>
|
|
|
|
|
</>
|
|
|
|
|
)
|
|
|
|
|
}
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2022-05-16 17:56:55 -06:00
|
|
|
function ArchiveCard({archive, setDomain}) {
|
|
|
|
|
|
|
|
|
|
const imageSrc = archive.screenshot_path ? `/media/${encodeURIComponent(archive.screenshot_path)}` : null;
|
|
|
|
|
const singlefileUrl = archive.singlefile_path ? `/media/${encodeURIComponent(archive.singlefile_path)}` : null;
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2022-01-30 16:27:06 -07:00
|
|
|
const domain = archive.domain.domain;
|
|
|
|
|
|
2022-01-03 15:13:02 -07:00
|
|
|
return (
|
|
|
|
|
<Card>
|
2022-03-12 09:50:16 -07:00
|
|
|
<a href={singlefileUrl} target='_blank' className='no-link-underscore card-link'>
|
2022-01-03 15:13:02 -07:00
|
|
|
<Image src={imageSrc} wrapped style={{position: 'relative', width: '100%'}}/>
|
2022-03-12 09:50:16 -07:00
|
|
|
</a>
|
2022-01-03 15:13:02 -07:00
|
|
|
<Card.Content>
|
|
|
|
|
<Card.Header>
|
|
|
|
|
<Container textAlign='left'>
|
2022-03-12 09:50:16 -07:00
|
|
|
<a href={singlefileUrl} target='_blank' className='no-link-underscore card-link'>
|
2022-01-14 16:27:16 -07:00
|
|
|
<p>{textEllipsis(archive.title || archive.url, 100)}</p>
|
2022-03-12 09:50:16 -07:00
|
|
|
</a>
|
2022-01-03 15:13:02 -07:00
|
|
|
</Container>
|
|
|
|
|
</Card.Header>
|
2022-05-16 17:56:55 -06:00
|
|
|
{setDomain &&
|
|
|
|
|
<a onClick={() => setDomain(domain)} className="no-link-underscore card-link">
|
|
|
|
|
{textEllipsis(domain, 40)}
|
|
|
|
|
</a>
|
|
|
|
|
}
|
2022-01-03 15:13:02 -07:00
|
|
|
<Card.Meta>
|
2022-01-30 16:27:06 -07:00
|
|
|
<p>
|
|
|
|
|
{uploadDate(archive.archive_datetime)}
|
|
|
|
|
</p>
|
2022-01-03 15:13:02 -07:00
|
|
|
</Card.Meta>
|
|
|
|
|
<Card.Description>
|
2022-05-16 17:56:55 -06:00
|
|
|
<Link to={`/archive/${archive.id}`}>
|
|
|
|
|
<Button icon='file alternate' content='Details'
|
|
|
|
|
labelPosition='left'/>
|
|
|
|
|
</Link>
|
|
|
|
|
<Button icon='external' href={archive.url} target='_blank' rel='noopener noreferrer'/>
|
2022-01-03 15:13:02 -07:00
|
|
|
</Card.Description>
|
|
|
|
|
</Card.Content>
|
|
|
|
|
</Card>
|
|
|
|
|
)
|
|
|
|
|
}
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2022-05-16 17:56:55 -06:00
|
|
|
function ArchiveCards({archives, setDomain}) {
|
2022-01-03 15:13:02 -07:00
|
|
|
return (
|
2022-01-31 09:53:17 -07:00
|
|
|
<CardGroupCentered>
|
2022-01-03 15:13:02 -07:00
|
|
|
{archives.map((i) => {
|
2022-01-30 16:27:06 -07:00
|
|
|
return <ArchiveCard
|
|
|
|
|
key={i['id']}
|
|
|
|
|
archive={i}
|
|
|
|
|
setDomain={setDomain}
|
|
|
|
|
/>
|
2022-01-03 15:13:02 -07:00
|
|
|
})}
|
2022-01-31 09:53:17 -07:00
|
|
|
</CardGroupCentered>
|
2022-01-03 15:13:02 -07:00
|
|
|
)
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
2022-05-16 17:56:55 -06:00
|
|
|
export function ArchivesList({archives, searchStr, setDomain}) {
|
2022-01-03 15:13:02 -07:00
|
|
|
if (archives === null || archives === undefined) {
|
|
|
|
|
// Fetching archives.
|
|
|
|
|
return <ArchivePlaceholder/>;
|
|
|
|
|
} else if (archives.length === 0 && searchStr) {
|
|
|
|
|
// Search with no results.
|
|
|
|
|
return <p>No archives found! Is your search too restrictive?</p>;
|
|
|
|
|
} else if (archives.length === 0) {
|
|
|
|
|
// No archives fetched.
|
2022-01-15 18:05:51 -07:00
|
|
|
return <Message>
|
|
|
|
|
<Message.Header>No archives</Message.Header>
|
|
|
|
|
<Message.Content>Have you archived any webpages?</Message.Content>
|
|
|
|
|
</Message>;
|
2022-01-03 15:13:02 -07:00
|
|
|
} else {
|
|
|
|
|
// Archives fetched successfully!
|
2022-01-30 16:27:06 -07:00
|
|
|
return <ArchiveCards
|
|
|
|
|
archives={archives}
|
|
|
|
|
setDomain={setDomain}
|
|
|
|
|
/>;
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-03 15:13:02 -07:00
|
|
|
export function Archives() {
|
2022-02-02 14:02:51 -07:00
|
|
|
const {archives, setPage, totalPages, searchStr, activePage, setSearchStr, domain, setDomain, search} =
|
|
|
|
|
useArchives(20);
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2022-01-03 15:13:02 -07:00
|
|
|
let domainClearButton = null;
|
|
|
|
|
if (domain) {
|
|
|
|
|
domainClearButton = <ClearButton
|
|
|
|
|
onClick={() => setDomain(null)}
|
|
|
|
|
style={{marginBottom: '1em'}}
|
|
|
|
|
label={`Domain: ${domain}`}
|
|
|
|
|
/>;
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
2022-01-03 15:13:02 -07:00
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<SearchInput initValue={searchStr} onSubmit={setSearchStr}/>
|
|
|
|
|
{domainClearButton}
|
|
|
|
|
<ArchivesList
|
|
|
|
|
archives={archives}
|
|
|
|
|
searchStr={searchStr}
|
2022-01-30 16:27:06 -07:00
|
|
|
setDomain={setDomain}
|
2022-01-03 15:13:02 -07:00
|
|
|
/>
|
|
|
|
|
<div style={{marginTop: '3em', textAlign: 'center'}}>
|
2022-02-02 14:02:51 -07:00
|
|
|
<Paginator activePage={activePage} totalPages={totalPages} onPageChange={setPage}/>
|
2022-01-03 15:13:02 -07:00
|
|
|
</div>
|
|
|
|
|
</>
|
|
|
|
|
)
|
|
|
|
|
}
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2022-01-03 15:13:02 -07:00
|
|
|
class ManageArchives extends React.Component {
|
|
|
|
|
async refresh() {
|
|
|
|
|
await refreshArchives();
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
2022-01-03 15:13:02 -07:00
|
|
|
return (<>
|
2022-01-15 18:15:23 -07:00
|
|
|
<WROLModeMessage content='Cannot modify Archives'/>
|
2022-01-03 15:13:02 -07:00
|
|
|
<Button secondary
|
2022-01-31 16:52:22 -07:00
|
|
|
id='refresh_archives'
|
2022-01-03 15:13:02 -07:00
|
|
|
onClick={this.refresh}>
|
|
|
|
|
Refresh Archive Files
|
|
|
|
|
</Button>
|
2022-01-31 16:52:22 -07:00
|
|
|
<label htmlFor='refresh_archives'>
|
|
|
|
|
Find any new archive files. Remove Archives which no longer have files.
|
|
|
|
|
</label>
|
2022-01-03 15:13:02 -07:00
|
|
|
</>)
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-03 15:13:02 -07:00
|
|
|
function Domains() {
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2022-01-03 15:13:02 -07:00
|
|
|
const [domains] = useDomains();
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2022-01-03 15:13:02 -07:00
|
|
|
const row = (domain) => {
|
2021-11-01 16:42:52 -06:00
|
|
|
return <Table.Row key={domain['domain']}>
|
|
|
|
|
<Table.Cell>
|
|
|
|
|
<Link to={`/archive?domain=${domain['domain']}`}>
|
|
|
|
|
{domain['domain']}
|
|
|
|
|
</Link>
|
|
|
|
|
</Table.Cell>
|
|
|
|
|
<Table.Cell>{domain['url_count']}</Table.Cell>
|
|
|
|
|
</Table.Row>
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-15 18:05:51 -07:00
|
|
|
if (domains && domains.length > 0) {
|
2021-11-01 16:42:52 -06:00
|
|
|
return (
|
|
|
|
|
<>
|
2022-01-03 15:13:02 -07:00
|
|
|
<Table celled>
|
|
|
|
|
<Table.Header>
|
|
|
|
|
<Table.Row>
|
|
|
|
|
<Table.HeaderCell>Domain</Table.HeaderCell>
|
2022-01-15 18:05:51 -07:00
|
|
|
<Table.HeaderCell>Archives</Table.HeaderCell>
|
2022-01-03 15:13:02 -07:00
|
|
|
</Table.Row>
|
|
|
|
|
</Table.Header>
|
|
|
|
|
|
|
|
|
|
<Table.Body>
|
|
|
|
|
{domains.map(row)}
|
|
|
|
|
</Table.Body>
|
|
|
|
|
</Table>
|
2021-11-01 16:42:52 -06:00
|
|
|
</>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-15 18:05:51 -07:00
|
|
|
if (domains === null) {
|
|
|
|
|
return (<>
|
|
|
|
|
<Placeholder>
|
|
|
|
|
<Placeholder.Header>
|
|
|
|
|
<Placeholder.Line/>
|
|
|
|
|
<Placeholder.Line/>
|
|
|
|
|
</Placeholder.Header>
|
|
|
|
|
</Placeholder>
|
|
|
|
|
</>)
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-03 15:13:02 -07:00
|
|
|
return (<>
|
2022-01-15 18:05:51 -07:00
|
|
|
<Message>
|
|
|
|
|
<Message.Header>No domains yet.</Message.Header>
|
|
|
|
|
<Message.Content>Archive some webpages!</Message.Content>
|
|
|
|
|
</Message>
|
2022-01-03 15:13:02 -07:00
|
|
|
</>)
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
2022-01-03 15:13:02 -07:00
|
|
|
|
2022-01-29 21:24:39 -07:00
|
|
|
export function ArchiveRoute(props) {
|
2022-01-29 22:25:35 -07:00
|
|
|
const links = [
|
2022-02-02 14:02:51 -07:00
|
|
|
{text: 'Archives', to: '/archive', exact: true, key: 'archive'},
|
|
|
|
|
{text: 'Domains', to: '/archive/domains', key: 'domains'},
|
|
|
|
|
{text: 'Manage', to: '/archive/manage', key: 'manage'},
|
2022-01-29 21:24:39 -07:00
|
|
|
];
|
2022-01-31 09:32:06 -07:00
|
|
|
return <PageContainer>
|
2022-01-29 22:25:35 -07:00
|
|
|
<TabLinks links={links}/>
|
2022-05-16 17:56:55 -06:00
|
|
|
<Switch>
|
|
|
|
|
<Route path='/archive/domains' exact component={Domains}/>
|
|
|
|
|
<Route path='/archive/manage' exact component={ManageArchives}/>
|
|
|
|
|
<Route path='/archive/:archive_id' exact component={ArchivePage}/>
|
|
|
|
|
<Route path='/archive' exact component={Archives}/>
|
|
|
|
|
</Switch>
|
2022-01-31 09:32:06 -07:00
|
|
|
</PageContainer>
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|