Skip to content

Commit

Permalink
feat(links): copy all download links for files added to frontend.
Browse files Browse the repository at this point in the history
  • Loading branch information
MR-MKZ committed Jan 6, 2025
1 parent 2a0563a commit 644f5af
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 8 deletions.
30 changes: 25 additions & 5 deletions static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,35 @@ body {
padding: 12px;
}

.pathContainer {
background: #56585fa6;
.box {
margin-bottom: 20px;
border-radius: 7px;
padding: 12px;
position: sticky;
top: 20px;
backdrop-filter: blur(3px);
z-index: 1;
display: grid;
gap: 12px;
grid-template-columns: 1fr 100px;
}

.box * {
border-radius: 7px;
}

.pathContainer {
background: #56585fa6;
padding: 12px;
backdrop-filter: blur(3px);
white-space: nowrap;
overflow: auto;
}

.linksContainer button {
border: none;
background-color: #0064ff;
height: 100%;
width: 100%;
color: white;
cursor: pointer;
}

.pathContainer span {
Expand Down
41 changes: 41 additions & 0 deletions static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,47 @@ const isVideo = (extension) => {
return videoExtensions.indexOf(extension) > -1;
}

/**
* @returns {Array} array of links
*/
const getAllLinks = () => {
const files = document.getElementsByClassName("fileItem");
let links = [];

for (let a of files) {
links.push(a.href)
}

return links;
}

const copyAllLinks = () => {
let links = getAllLinks();

links = links.join("\n");

const copyText = async () => {
try {
await navigator.clipboard.writeText(links);
} catch (err) {
fallbackCopy(links);
}
};

const fallbackCopy = (links) => {
const textArea = document.createElement("textarea");
textArea.value = links;
document.body.appendChild(textArea);
textArea.select();
document.execCommand("copy");
document.body.removeChild(textArea);
};

copyText();

showNotification("Links copied successfully.");
}

const showNotification = (message) => {
$(".notifContainer p").text(message)
$(".notifContainer").addClass("show")
Expand Down
11 changes: 8 additions & 3 deletions templates/main_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@
{% endfor %}
</select>
</div>
<div class="pathContainer">
<span>{{ current_path }}</span>
<div class="box">
<div class="pathContainer">
<span>{{ current_path }}</span>
</div>
<div class="linksContainer">
<button onclick="copyAllLinks()">Copy Links</button>
</div>
</div>
<div class="listContainer">
{% if dir_contents[0] %}
Expand All @@ -40,7 +45,7 @@
{% if dir_content.isFile %}
<span class="listItem file">
<icon id="{{ dir_content.icon }}"></icon>
<a href="/download/{{ dir_content.path }}">{{ dir_content.name }}</a>
<a class="fileItem" href="/download/{{ dir_content.path }}">{{ dir_content.name }}</a>
{% if dir_content.preview %}
<button class="showPreview" name="{{ dir_content.name }}"
src="/download/{{ dir_content.path }}">
Expand Down

0 comments on commit 644f5af

Please sign in to comment.