Skip to content

Commit

Permalink
feat: add option to copy download links from shares (#2442)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeicor committed May 1, 2023
1 parent 1a5b999 commit a4ef02a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
20 changes: 19 additions & 1 deletion frontend/src/components/prompts/Share.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@
<i class="material-icons">content_paste</i>
</button>
</td>
<td class="small" v-if="hasDownloadLink()">
<button
class="action copy-clipboard"
:data-clipboard-text="buildDownloadLink(link)"
:aria-label="$t('buttons.copyDownloadLinkToClipboard')"
:title="$t('buttons.copyDownloadLinkToClipboard')"
>
<i class="material-icons">content_paste_go</i>
</button>
</td>
<td class="small">
<button
class="action"
Expand Down Expand Up @@ -117,7 +127,7 @@

<script>
import { mapState, mapGetters } from "vuex";
import { share as api } from "@/api";
import { share as api, pub as pub_api } from "@/api";
import moment from "moment";
import Clipboard from "clipboard";
Expand Down Expand Up @@ -215,6 +225,14 @@ export default {
buildLink(share) {
return api.getShareURL(share);
},
hasDownloadLink() {
return (
this.selected.length === 1 && !this.req.items[this.selected[0]].isDir
);
},
buildDownloadLink(share) {
return pub_api.getDownloadURL(share);
},
sort() {
this.links = this.links.sort((a, b) => {
if (a.expire === 0) return -1;
Expand Down
1 change: 1 addition & 0 deletions frontend/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"copy": "Copy",
"copyFile": "Copy file",
"copyToClipboard": "Copy to clipboard",
"copyDownloadLinkToClipboard": "Copy download link to clipboard",
"create": "Create",
"delete": "Delete",
"download": "Download",
Expand Down
33 changes: 31 additions & 2 deletions frontend/src/views/Share.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
@action="download"
:counter="selectedCount"
/>
<button
v-if="isSingleFile()"
class="action copy-clipboard"
:data-clipboard-text="linkSelected()"
:aria-label="$t('buttons.copyDownloadLinkToClipboard')"
:title="$t('buttons.copyDownloadLinkToClipboard')"
>
<i class="material-icons">content_paste</i>
</button>
<action
icon="check_circle"
:label="$t('buttons.selectMultiple')"
Expand Down Expand Up @@ -182,6 +191,7 @@ import Breadcrumbs from "@/components/Breadcrumbs";
import Errors from "@/views/Errors";
import QrcodeVue from "qrcode.vue";
import Item from "@/components/files/ListingItem";
import Clipboard from "clipboard";
export default {
name: "share",
Expand All @@ -200,6 +210,7 @@ export default {
attemptedPasswordLogin: false,
hash: null,
token: null,
clip: null,
}),
watch: {
$route: function () {
Expand All @@ -215,13 +226,18 @@ export default {
},
mounted() {
window.addEventListener("keydown", this.keyEvent);
this.clip = new Clipboard(".copy-clipboard");
this.clip.on("success", () => {
this.$showSuccess(this.$t("success.linkCopied"));
});
},
beforeDestroy() {
window.removeEventListener("keydown", this.keyEvent);
this.clip.destroy();
},
computed: {
...mapState(["req", "loading", "multiple", "selected"]),
...mapGetters(["selectedCount", "selectedCount"]),
...mapGetters(["selectedCount"]),
icon: function () {
if (this.req.isDir) return "folder";
if (this.req.type === "image") return "insert_photo";
Expand Down Expand Up @@ -300,8 +316,13 @@ export default {
toggleMultipleSelection() {
this.$store.commit("multiple", !this.multiple);
},
isSingleFile: function () {
return (
this.selectedCount === 1 && !this.req.items[this.selected[0]].isDir
);
},
download() {
if (this.selectedCount === 1 && !this.req.items[this.selected[0]].isDir) {
if (this.isSingleFile()) {
api.download(
null,
this.hash,
Expand All @@ -326,6 +347,14 @@ export default {
},
});
},
linkSelected: function () {
return this.isSingleFile()
? api.getDownloadURL({
hash: this.hash,
path: this.req.items[this.selected[0]].path,
})
: "";
},
},
};
</script>

0 comments on commit a4ef02a

Please sign in to comment.