Send/app/ui/download.js
Dylan Derr 2f491fac86 Added the following ENVIRONMENT VARIABLES > send.ftl - if not set it will use translate().
CUSTOM_INTRO_TITLE > introTitle
CUSTOM_INTRO_DESCRIPTION: > introDescription
CUSTOM_DOWNLOAD_DESCRIPTION: downloadDescription
CUSTOM_TRY_SEND_DESCRIPTION: trySendDescription
CUSTOM_SEND_YOUR_FILES_LINK: sendYourFilesLink

CUSTOM_INTRO_TITLE: "Secure & Simple"
CUSTOM_INTRO_DESCRIPTION: "Share files with end-to-end encryption and a link that expires."
CUSTOM_DOWNLOAD_DESCRIPTION: "Shared with end-to-end encryption and a link that expires."
CUSTOM_TRY_SEND_DESCRIPTION: "Secure, Simple file sharing"
CUSTOM_SEND_YOUR_FILES_LINK: "Upload Files"
2025-02-08 12:37:18 -06:00

99 lines
2.6 KiB
JavaScript

/* global downloadMetadata */
const html = require('choo/html');
const archiveTile = require('./archiveTile');
const modal = require('./modal');
const noStreams = require('./noStreams');
const notFound = require('./notFound');
const downloadPassword = require('./downloadPassword');
const downloadCompleted = require('./downloadCompleted');
const BIG_SIZE = 1024 * 1024 * 256;
function createFileInfo(state) {
return {
id: state.params.id,
secretKey: state.params.key,
nonce: downloadMetadata.nonce,
requiresPassword: downloadMetadata.pwd
};
}
function downloading(state, emit) {
return html`
<div
class="flex flex-col w-full h-full items-center md:justify-center md:-mt-8"
>
<h1 class="text-3xl font-bold mb-4">
${state.translate('downloadingTitle')}
</h1>
${archiveTile.downloading(state, emit)}
</div>
`;
}
function preview(state, emit) {
if (!state.capabilities.streamDownload && state.fileInfo.size > BIG_SIZE) {
return noStreams(state, emit);
}
const downloadDescription =
state.WEB_UI.CUSTOM_DOWNLOAD_DESCRIPTION ||
state.translate('downloadDescription');
return html`
<div
class="flex flex-col w-full max-w-md h-full mx-auto items-center justify-center"
>
<h1 class="text-3xl font-bold mb-4">
${state.translate('downloadTitle')}
</h1>
<p
class="w-full text-grey-80 text-center leading-normal dark:text-grey-40"
>
${downloadDescription}
</p>
${archiveTile.preview(state, emit)}
</div>
`;
}
module.exports = function(state, emit) {
let content = '';
if (!state.fileInfo) {
state.fileInfo = createFileInfo(state);
if (downloadMetadata.status === 404) {
return notFound(state);
}
if (!state.fileInfo.nonce) {
// coming from something like the browser back button
return location.reload();
}
}
if (!state.transfer && !state.fileInfo.requiresPassword) {
emit('getMetadata');
}
if (state.transfer) {
switch (state.transfer.state) {
case 'downloading':
case 'decrypting':
content = downloading(state, emit);
break;
case 'complete':
content = downloadCompleted(state);
break;
default:
content = preview(state, emit);
}
} else if (state.fileInfo.requiresPassword && !state.fileInfo.password) {
content = downloadPassword(state, emit);
}
return html`
<main class="main">
${state.modal && modal(state, emit)}
<section
class="relative h-full w-full p-6 md:p-8 md:rounded-xl md:shadow-big"
>
${content}
</section>
</main>
`;
};