Skip to content
This repository has been archived by the owner on May 22, 2021. It is now read-only.

show download Limits on page; Fixes #661 #721

Merged
merged 1 commit into from
Jan 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions app/fileManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
7 changes: 5 additions & 2 deletions app/templates/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`
<tr id="${file.id}">
<td class="overflow-col" title="${
Expand All @@ -29,7 +31,8 @@ module.exports = function(file, state, emit) {
'copiedUrl'
)}</span>
</td>
<td>${remaining}</td>
<td>${remainingTime}</td>
<td class="center-col">${totalDownloads}/${downloadLimit}</td>
<td class="center-col">
<img onclick=${showPopup} src="${assets.get(
'close-16.svg'
Expand Down
7 changes: 6 additions & 1 deletion app/templates/fileList.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ module.exports = function(state, emit) {
<th id="copy-file-list" class="center-col">${state.translate(
'copyFileList'
)}</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(
'deleteFileList'
)}</th>
Expand Down
6 changes: 5 additions & 1 deletion assets/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -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%;
}
Expand Down
4 changes: 3 additions & 1 deletion public/locales/en-US/send.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I lost track of this PR. This should have a comment, "time" it's a very broad word in English.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This Time refers to this header here
screenshot from 2018-01-23 12-23-16

This initially was set as Expires In should I change it back.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's really not my call ;-)

In the meantime I opened a PR to add a localization comment.

downloadFileName = Download { $filename }
downloadFileSize = ({ $size })
unlockInputLabel = Enter Password
Expand Down Expand Up @@ -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
reportIPInfringement = Report IP Infringement