ultraarchive/src/routes/+page.svelte
2023-02-19 22:48:10 -05:00

105 lines
4.1 KiB
Svelte

<script>
let ongoingMakeRequest, errorMessage, id, makeInfo = null;
let waybackEnabled = true;
let archivedotisEnabled = true;
let disableInput = false;
let url;
async function make() {
ongoingMakeRequest = {};
let data = await (await fetch(`/api/archive?url=${encodeURIComponent(url)}&wayback=${waybackEnabled}&archiveis=${archivedotisEnabled}`)).json();
if (data.success == false) {
errorMessage = data.error;
ongoingMakeRequest = null;
} else id = data.id;
followMake();
}
async function followMake() {
disableInput = true;
makeInfo = await (await fetch(`/api/archive?id=${id}`)).json();
if (makeInfo.allComplete == false) {
setTimeout(async function() {
followMake();
}, 1000);
} else {
disableInput = false;
}
}
</script>
<svelte:head>
<title>ultraarchive</title>
</svelte:head>
<div class="header">
<img src="/anim.gif" alt="">
<h1 class="header-name">ultraarchive</h1>
</div>
<div class="window" id="form-window">
<div class="title-bar"><div class="title-bar-text">UltraArchive</div></div>
<div class="window-body">
<p>
Archive to or browse archives from
<a href="https://web.archive.org/">The Wayback Machine</a>,
<a href="https://archive.is">Archive.is</a>,
and many other online archives.
</p>
<input bind:value={url} placeholder="Insert a website here." type="url" id="url" disabled={disableInput}>
<button on:click={make} disabled={disableInput}>Archive</button>
<button disabled>Explore</button>
<input type="checkbox" id="wayback" bind:checked={waybackEnabled} disabled={disableInput}>
<label for="wayback">Wayback Machine</label>
<input type="checkbox" id="archiveis" bind:checked={archivedotisEnabled} disabled={disableInput}>
<label for="archiveis">Archive.is</label>
<!--
<input type="checkbox" id="megalodon" disabled>
<label for="megalodon"><a href="https://megalodon.jp">Megalodon.jp</a></label>
<input type="checkbox" id="archivest" disabled>
<label for="archivest"><a href="https://www.archive.st/">www.archive.st</a></label>
-->
<div>
{#if ongoingMakeRequest}
<hr>
<div class="make">
<h3>Current request</h3>
<p>Request ID: {id}</p>
{#if makeInfo}
<ul>
{#if waybackEnabled}
<li>
Wayback Machine:
{#if makeInfo.status.wayback.status == "unstarted"}<progress></progress>{/if}
{#if makeInfo.status.wayback.status == "pending"}<progress></progress> {(makeInfo.status.wayback.message || makeInfo.status.wayback.status || "Unknown status")}{/if}
{#if makeInfo.status.wayback.status == "success"}<span><a href={makeInfo.status.wayback.url}>Archived</a></span>{/if}
{#if makeInfo.status.wayback.status == "error"}<span style="color: red">{(makeInfo.status.wayback.message || "Could not parse error.")}</span>{/if}
</li>
{/if}
{#if archivedotisEnabled}
<li>
Archive.is:
{#if makeInfo.status.archivedotis.status == "unstarted"}<progress></progress>{/if}
{#if makeInfo.status.archivedotis.status == "pending"}<progress></progress> {(makeInfo.status.archivedotis.message || makeInfo.status.archivedotis.status || "Unknown status")}{/if}
{#if makeInfo.status.archivedotis.status == "success"}<span><a href={makeInfo.status.archivedotis.url}>Archived</a></span>{/if}
{#if makeInfo.status.archivedotis.status == "error"}<span style="color: red">{(makeInfo.status.archivedotis.message || "Could not parse error.")}</span>{/if}
</li>
{/if}
</ul>
{/if}
</div>
{/if}
{#if errorMessage}
<hr>
<div class="error">
<h3 style="margin: 0;">Error</h3>
<p>{errorMessage}</p>
</div>
{/if}
</div>
</div>
</div>
<p class="footer"><a href="https://git.gay/a/ultraarchive">source code</a> - made with love by <a href="https://besties.house/">besties.house</a></p>