Merge pull request #721 from shikhar-scs/show-dlimits
show download Limits on page; Fixes #661
This commit is contained in:
commit
118edef773
5 changed files with 37 additions and 22 deletions
|
@ -36,22 +36,16 @@ function openLinksInNewTab(links, should = true) {
|
||||||
return links;
|
return links;
|
||||||
}
|
}
|
||||||
|
|
||||||
function exists(id) {
|
async function getDLCounts(file) {
|
||||||
return new Promise((resolve, reject) => {
|
const url = `/api/metadata/${file.id}`;
|
||||||
const xhr = new XMLHttpRequest();
|
const receiver = new FileReceiver(url, file);
|
||||||
xhr.onreadystatechange = () => {
|
try {
|
||||||
if (xhr.readyState === XMLHttpRequest.HEADERS_RECEIVED) {
|
await receiver.getMetadata(file.nonce);
|
||||||
resolve(xhr.status === 200);
|
return receiver.file;
|
||||||
}
|
} catch (e) {
|
||||||
};
|
if (e.message === '404') return false;
|
||||||
xhr.onerror = () => resolve(false);
|
}
|
||||||
xhr.ontimeout = () => resolve(false);
|
|
||||||
xhr.open('get', '/api/exists/' + id);
|
|
||||||
xhr.timeout = 2000;
|
|
||||||
xhr.send();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function(state, emitter) {
|
export default function(state, emitter) {
|
||||||
let lastRender = 0;
|
let lastRender = 0;
|
||||||
let updateTitle = false;
|
let updateTitle = false;
|
||||||
|
@ -64,10 +58,17 @@ export default function(state, emitter) {
|
||||||
const files = state.storage.files;
|
const files = state.storage.files;
|
||||||
let rerender = false;
|
let rerender = false;
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
const ok = await exists(file.id);
|
const oldLimit = file.dlimit;
|
||||||
if (!ok) {
|
const oldTotal = file.dtotal;
|
||||||
|
const receivedFile = await getDLCounts(file);
|
||||||
|
if (!receivedFile) {
|
||||||
state.storage.remove(file.id);
|
state.storage.remove(file.id);
|
||||||
rerender = true;
|
rerender = true;
|
||||||
|
} else if (
|
||||||
|
oldLimit !== receivedFile.dlimit ||
|
||||||
|
oldTotal !== receivedFile.dtotal
|
||||||
|
) {
|
||||||
|
rerender = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (rerender) {
|
if (rerender) {
|
||||||
|
|
|
@ -15,7 +15,9 @@ function timeLeft(milliseconds) {
|
||||||
|
|
||||||
module.exports = function(file, state, emit) {
|
module.exports = function(file, state, emit) {
|
||||||
const ttl = file.expiresAt - Date.now();
|
const ttl = file.expiresAt - Date.now();
|
||||||
const remaining = timeLeft(ttl) || state.translate('linkExpiredAlt');
|
const remainingTime = timeLeft(ttl) || state.translate('linkExpiredAlt');
|
||||||
|
const downloadLimit = file.dlimit || 1;
|
||||||
|
const totalDownloads = file.dtotal || 0;
|
||||||
const row = html`
|
const row = html`
|
||||||
<tr id="${file.id}">
|
<tr id="${file.id}">
|
||||||
<td class="overflow-col" title="${
|
<td class="overflow-col" title="${
|
||||||
|
@ -29,7 +31,8 @@ module.exports = function(file, state, emit) {
|
||||||
'copiedUrl'
|
'copiedUrl'
|
||||||
)}</span>
|
)}</span>
|
||||||
</td>
|
</td>
|
||||||
<td>${remaining}</td>
|
<td>${remainingTime}</td>
|
||||||
|
<td class="center-col">${totalDownloads}/${downloadLimit}</td>
|
||||||
<td class="center-col">
|
<td class="center-col">
|
||||||
<img onclick=${showPopup} src="${assets.get(
|
<img onclick=${showPopup} src="${assets.get(
|
||||||
'close-16.svg'
|
'close-16.svg'
|
||||||
|
|
|
@ -12,7 +12,12 @@ module.exports = function(state, emit) {
|
||||||
<th id="copy-file-list" class="center-col">${state.translate(
|
<th id="copy-file-list" class="center-col">${state.translate(
|
||||||
'copyFileList'
|
'copyFileList'
|
||||||
)}</th>
|
)}</th>
|
||||||
<th id="expiry-file-list">${state.translate('expiryFileList')}</th>
|
<th id="expiry-time-file-list" >${state.translate(
|
||||||
|
'timeFileList'
|
||||||
|
)}</th>
|
||||||
|
<th id="expiry-downloads-file-list" >${state.translate(
|
||||||
|
'downloadsFileList'
|
||||||
|
)}</th>
|
||||||
<th id="delete-file-list" class="center-col">${state.translate(
|
<th id="delete-file-list" class="center-col">${state.translate(
|
||||||
'deleteFileList'
|
'deleteFileList'
|
||||||
)}</th>
|
)}</th>
|
||||||
|
|
|
@ -342,10 +342,14 @@ tbody {
|
||||||
width: 25%;
|
width: 25%;
|
||||||
}
|
}
|
||||||
|
|
||||||
#expiry-file-list {
|
#expiry-time-file-list {
|
||||||
width: 21%;
|
width: 21%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#expiry-downloads-file-list {
|
||||||
|
width: 8%;
|
||||||
|
}
|
||||||
|
|
||||||
#delete-file-list {
|
#delete-file-list {
|
||||||
width: 12%;
|
width: 12%;
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,8 @@ deleteFileButton = Delete file
|
||||||
sendAnotherFileLink = Send another file
|
sendAnotherFileLink = Send another file
|
||||||
// Alternative text used on the download link/button (indicates an action).
|
// Alternative text used on the download link/button (indicates an action).
|
||||||
downloadAltText = Download
|
downloadAltText = Download
|
||||||
|
downloadsFileList = Downloads
|
||||||
|
timeFileList = Time
|
||||||
downloadFileName = Download { $filename }
|
downloadFileName = Download { $filename }
|
||||||
downloadFileSize = ({ $size })
|
downloadFileSize = ({ $size })
|
||||||
unlockInputLabel = Enter Password
|
unlockInputLabel = Enter Password
|
||||||
|
@ -99,4 +101,4 @@ changePasswordButton = Change
|
||||||
passwordTryAgain = Incorrect password. Try again.
|
passwordTryAgain = Incorrect password. Try again.
|
||||||
// This label is followed by the password needed to download a file
|
// This label is followed by the password needed to download a file
|
||||||
passwordResult = Password: { $password }
|
passwordResult = Password: { $password }
|
||||||
reportIPInfringement = Report IP Infringement
|
reportIPInfringement = Report IP Infringement
|
||||||
|
|
Loading…
Reference in a new issue