feat: add "copy download link to clipboard" button to Share prompt (#5173)

Co-authored-by: Henrique Dias <mail@hacdias.com>
This commit is contained in:
Kosmos 2025-11-22 17:07:10 +01:00 committed by GitHub
parent 54306bdc87
commit d48f5665d6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 36 additions and 9 deletions

View File

@ -12,6 +12,7 @@
<th>{{ $t("settings.shareDuration") }}</th> <th>{{ $t("settings.shareDuration") }}</th>
<th></th> <th></th>
<th></th> <th></th>
<th></th>
</tr> </tr>
<tr v-for="link in links" :key="link.hash"> <tr v-for="link in links" :key="link.hash">
@ -24,7 +25,7 @@
</td> </td>
<td class="small"> <td class="small">
<button <button
class="action copy-clipboard" class="action"
:aria-label="$t('buttons.copyToClipboard')" :aria-label="$t('buttons.copyToClipboard')"
:title="$t('buttons.copyToClipboard')" :title="$t('buttons.copyToClipboard')"
@click="copyToClipboard(buildLink(link))" @click="copyToClipboard(buildLink(link))"
@ -32,6 +33,17 @@
<i class="material-icons">content_paste</i> <i class="material-icons">content_paste</i>
</button> </button>
</td> </td>
<td class="small">
<button
class="action"
:aria-label="$t('buttons.copyDownloadLinkToClipboard')"
:title="$t('buttons.copyDownloadLinkToClipboard')"
:disabled="!!link.password_hash"
@click="copyToClipboard(buildDownloadLink(link))"
>
<i class="material-icons">content_paste_go</i>
</button>
</td>
<td class="small"> <td class="small">
<button <button
class="action" class="action"
@ -132,7 +144,7 @@
<script> <script>
import { mapActions, mapState } from "pinia"; import { mapActions, mapState } from "pinia";
import { useFileStore } from "@/stores/file"; import { useFileStore } from "@/stores/file";
import { share as api } from "@/api"; import * as api from "@/api/index";
import dayjs from "dayjs"; import dayjs from "dayjs";
import { useLayoutStore } from "@/stores/layout"; import { useLayoutStore } from "@/stores/layout";
import { copy } from "@/utils/clipboard"; import { copy } from "@/utils/clipboard";
@ -172,7 +184,7 @@ export default {
}, },
async beforeMount() { async beforeMount() {
try { try {
const links = await api.get(this.url); const links = await api.share.get(this.url);
this.links = links; this.links = links;
this.sort(); this.sort();
@ -211,9 +223,14 @@ export default {
let res = null; let res = null;
if (!this.time) { if (!this.time) {
res = await api.create(this.url, this.password); res = await api.share.create(this.url, this.password);
} else { } else {
res = await api.create(this.url, this.password, this.time, this.unit); res = await api.share.create(
this.url,
this.password,
this.time,
this.unit
);
} }
this.links.push(res); this.links.push(res);
@ -231,7 +248,7 @@ export default {
deleteLink: async function (event, link) { deleteLink: async function (event, link) {
event.preventDefault(); event.preventDefault();
try { try {
await api.remove(link.hash); await api.share.remove(link.hash);
this.links = this.links.filter((item) => item.hash !== link.hash); this.links = this.links.filter((item) => item.hash !== link.hash);
if (this.links.length == 0) { if (this.links.length == 0) {
@ -245,7 +262,16 @@ export default {
return dayjs(time * 1000).fromNow(); return dayjs(time * 1000).fromNow();
}, },
buildLink(share) { buildLink(share) {
return api.getShareURL(share); return api.share.getShareURL(share);
},
buildDownloadLink(share) {
return api.pub.getDownloadURL(
{
hash: share.hash,
path: "",
},
true
);
}, },
sort() { sort() {
this.links = this.links.sort((a, b) => { this.links = this.links.sort((a, b) => {

View File

@ -98,7 +98,8 @@ main .spinner .bounce2 {
position: relative; position: relative;
} }
.action.disabled { .action.disabled,
.action[disabled] {
opacity: 0.2; opacity: 0.2;
cursor: not-allowed; cursor: not-allowed;
} }