From 050a1aff8317669883653dfcad3e889682133482 Mon Sep 17 00:00:00 2001 From: shikhar-scs Date: Tue, 23 Jan 2018 07:41:48 +0530 Subject: [PATCH] show download Limits on page --- app/fileManager.js | 35 ++++++++++++++++++----------------- app/templates/file.js | 7 +++++-- app/templates/fileList.js | 7 ++++++- assets/main.css | 6 +++++- public/locales/en-US/send.ftl | 4 +++- 5 files changed, 37 insertions(+), 22 deletions(-) diff --git a/app/fileManager.js b/app/fileManager.js index 0dd46d21..acbe9161 100644 --- a/app/fileManager.js +++ b/app/fileManager.js @@ -36,22 +36,16 @@ function openLinksInNewTab(links, should = true) { return links; } -function exists(id) { - return new Promise((resolve, reject) => { - const xhr = new XMLHttpRequest(); - xhr.onreadystatechange = () => { - if (xhr.readyState === XMLHttpRequest.HEADERS_RECEIVED) { - resolve(xhr.status === 200); - } - }; - xhr.onerror = () => resolve(false); - xhr.ontimeout = () => resolve(false); - xhr.open('get', '/api/exists/' + id); - xhr.timeout = 2000; - xhr.send(); - }); +async function getDLCounts(file) { + const url = `/api/metadata/${file.id}`; + const receiver = new FileReceiver(url, file); + try { + await receiver.getMetadata(file.nonce); + return receiver.file; + } catch (e) { + if (e.message === '404') return false; + } } - export default function(state, emitter) { let lastRender = 0; let updateTitle = false; @@ -64,10 +58,17 @@ export default function(state, emitter) { const files = state.storage.files; let rerender = false; for (const file of files) { - const ok = await exists(file.id); - if (!ok) { + const oldLimit = file.dlimit; + const oldTotal = file.dtotal; + const receivedFile = await getDLCounts(file); + if (!receivedFile) { state.storage.remove(file.id); rerender = true; + } else if ( + oldLimit !== receivedFile.dlimit || + oldTotal !== receivedFile.dtotal + ) { + rerender = true; } } if (rerender) { diff --git a/app/templates/file.js b/app/templates/file.js index 881ef098..8d658ad7 100644 --- a/app/templates/file.js +++ b/app/templates/file.js @@ -15,7 +15,9 @@ function timeLeft(milliseconds) { module.exports = function(file, state, emit) { 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` ${totalDownloads}/${downloadLimit} ${state.translate( 'copyFileList' )} - ${state.translate('expiryFileList')} + ${state.translate( + 'timeFileList' + )} + ${state.translate( + 'downloadsFileList' + )} ${state.translate( 'deleteFileList' )} diff --git a/assets/main.css b/assets/main.css index 65d8bea1..32884b25 100644 --- a/assets/main.css +++ b/assets/main.css @@ -342,10 +342,14 @@ tbody { width: 25%; } -#expiry-file-list { +#expiry-time-file-list { width: 21%; } +#expiry-downloads-file-list { + width: 8%; +} + #delete-file-list { width: 12%; } diff --git a/public/locales/en-US/send.ftl b/public/locales/en-US/send.ftl index 765b5bb1..8a71e974 100644 --- a/public/locales/en-US/send.ftl +++ b/public/locales/en-US/send.ftl @@ -41,6 +41,8 @@ deleteFileButton = Delete file sendAnotherFileLink = Send another file // Alternative text used on the download link/button (indicates an action). downloadAltText = Download +downloadsFileList = Downloads +timeFileList = Time downloadFileName = Download { $filename } downloadFileSize = ({ $size }) unlockInputLabel = Enter Password @@ -99,4 +101,4 @@ changePasswordButton = Change passwordTryAgain = Incorrect password. Try again. // This label is followed by the password needed to download a file passwordResult = Password: { $password } -reportIPInfringement = Report IP Infringement \ No newline at end of file +reportIPInfringement = Report IP Infringement