2017-08-24 21:54:02 +00:00
|
|
|
const html = require('choo/html');
|
2018-02-13 19:32:59 +00:00
|
|
|
const number = require('../../utils').number;
|
2018-07-31 18:09:18 +00:00
|
|
|
const bytes = require('../../utils').bytes;
|
|
|
|
const fileIcon = require('../fileIcon');
|
2017-08-24 21:54:02 +00:00
|
|
|
|
2018-07-31 18:09:18 +00:00
|
|
|
module.exports = function(file, state) {
|
2017-08-24 21:54:02 +00:00
|
|
|
const ttl = file.expiresAt - Date.now();
|
2018-01-24 18:23:13 +00:00
|
|
|
const remainingTime =
|
|
|
|
timeLeft(ttl, state) || state.translate('linkExpiredAlt');
|
2018-01-23 02:11:48 +00:00
|
|
|
const downloadLimit = file.dlimit || 1;
|
|
|
|
const totalDownloads = file.dtotal || 0;
|
2018-07-31 18:09:18 +00:00
|
|
|
|
|
|
|
const multiFiles = file.manifest.files;
|
|
|
|
const fileName =
|
|
|
|
multiFiles.length > 1
|
|
|
|
? `${multiFiles[0].name} + ${state.translate('fileCount', {
|
|
|
|
num: multiFiles.length - 1
|
|
|
|
})}`
|
|
|
|
: file.name;
|
|
|
|
|
|
|
|
const activeClass = isOnSharePage() ? 'fileToast--active' : '';
|
2018-02-16 20:56:53 +00:00
|
|
|
return html`
|
2018-08-09 00:24:58 +00:00
|
|
|
<li id="${file.id}">
|
|
|
|
<a class="fileToast ${activeClass}" href=${toastClick()}>
|
|
|
|
<div class="fileToast__content">
|
|
|
|
${fileIcon(file.name, file._hasPassword)}
|
|
|
|
<div class="fileData">
|
|
|
|
<p class="fileName">${fileName}</p>
|
|
|
|
<p class="fileInfo">
|
|
|
|
<span>${bytes(file.size)}</span> ·
|
|
|
|
<span>${state.translate('downloadCount', {
|
|
|
|
num: `${number(totalDownloads)} / ${number(downloadLimit)}`
|
|
|
|
})}</span>
|
|
|
|
<span>${remainingTime}</span>
|
|
|
|
</p>
|
|
|
|
</div>
|
2018-07-31 18:09:18 +00:00
|
|
|
</div>
|
2018-08-09 00:24:58 +00:00
|
|
|
</a>
|
2018-07-31 18:09:18 +00:00
|
|
|
</li>
|
2017-08-24 21:54:02 +00:00
|
|
|
`;
|
|
|
|
|
2018-07-31 18:09:18 +00:00
|
|
|
function toastClick() {
|
|
|
|
return isOnSharePage() ? '/' : `/share/${file.id}`;
|
2017-08-24 21:54:02 +00:00
|
|
|
}
|
|
|
|
|
2018-07-31 18:09:18 +00:00
|
|
|
function isOnSharePage() {
|
|
|
|
return state.href.includes('/share/') && state.params.id === file.id;
|
2017-08-24 21:54:02 +00:00
|
|
|
}
|
|
|
|
};
|
2018-02-16 20:56:53 +00:00
|
|
|
|
|
|
|
function timeLeft(milliseconds, state) {
|
|
|
|
const minutes = Math.floor(milliseconds / 1000 / 60);
|
|
|
|
const hours = Math.floor(minutes / 60);
|
|
|
|
if (hours >= 1) {
|
|
|
|
return state.translate('expiresHoursMinutes', {
|
|
|
|
hours,
|
|
|
|
minutes: minutes % 60
|
|
|
|
});
|
|
|
|
} else if (hours === 0) {
|
|
|
|
if (minutes === 0) {
|
|
|
|
return state.translate('expiresMinutes', { minutes: '< 1' });
|
|
|
|
}
|
|
|
|
return state.translate('expiresMinutes', { minutes });
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|