You've already forked filebrowser
mirror of
https://github.com/filebrowser/filebrowser.git
synced 2025-11-26 14:25:26 +08:00
Former-commit-id: e483df4402733b102d11b10436ff74aad11dfa7c [formerly 6d761c2ee838a9766f755b6c54cdc2ca388b5934] [formerly 1365e9e067af021ad0c680bae3af963dc4a90b28 [formerly 889871ec0a]]
Former-commit-id: ba443a90fded4501c0a6872eb293c14b2923c627 [formerly d21c6b9ab41869d2b10aa99853bc5b6931b63d96]
Former-commit-id: 7c19b231861797c62dc35c1e8a28f4ceeb8761c7
159 lines
4.3 KiB
Vue
159 lines
4.3 KiB
Vue
<template>
|
|
<div class="prompt" id="share">
|
|
<h3>{{ $t('buttons.share') }}</h3>
|
|
<p></p>
|
|
<ul>
|
|
<li v-if="!hasPermanent">
|
|
<a @click="getPermalink" :aria-label="$t('buttons.permalink')">{{ $t('buttons.permalink') }}</a>
|
|
</li>
|
|
|
|
<li v-for="link in links" :key="link.hash">
|
|
<a :href="buildLink(link.hash)" target="_blank">
|
|
<template v-if="link.expires">{{ humanTime(link.expireDate) }}</template>
|
|
<template v-else>{{ $t('permanent') }}</template>
|
|
</a>
|
|
|
|
<button class="action"
|
|
@click="deleteLink($event, link)"
|
|
:aria-label="$t('buttons.delete')"
|
|
:title="$t('buttons.delete')"><i class="material-icons">delete</i></button>
|
|
|
|
<button class="action copy-clipboard"
|
|
:data-clipboard-text="buildLink(link.hash)"
|
|
:aria-label="$t('buttons.copyToClipboard')"
|
|
:title="$t('buttons.copyToClipboard')"><i class="material-icons">content_paste</i></button>
|
|
</li>
|
|
|
|
<li>
|
|
<input autofocus
|
|
type="number"
|
|
max="2147483647"
|
|
min="0"
|
|
@keyup.enter="submit"
|
|
v-model.trim="time">
|
|
<select v-model="unit" :aria-label="$t('time.unit')">
|
|
<option value="seconds">{{ $t('time.seconds') }}</option>
|
|
<option value="minutes">{{ $t('time.minutes') }}</option>
|
|
<option value="hours">{{ $t('time.hours') }}</option>
|
|
<option value="days">{{ $t('time.days') }}</option>
|
|
</select>
|
|
<button class="action"
|
|
@click="submit"
|
|
:aria-label="$t('buttons.create')"
|
|
:title="$t('buttons.create')"><i class="material-icons">add</i></button>
|
|
</li>
|
|
</ul>
|
|
|
|
<div>
|
|
<button class="cancel"
|
|
@click="$store.commit('closeHovers')"
|
|
:aria-label="$t('buttons.close')"
|
|
:title="$t('buttons.close')">{{ $t('buttons.close') }}</button>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import { mapState } from 'vuex'
|
|
import { getShare, deleteShare, share } from '@/utils/api'
|
|
import moment from 'moment'
|
|
import Clipboard from 'clipboard'
|
|
|
|
export default {
|
|
name: 'share',
|
|
data: function () {
|
|
return {
|
|
time: '',
|
|
unit: 'hours',
|
|
hasPermanent: false,
|
|
links: [],
|
|
clip: null
|
|
}
|
|
},
|
|
computed: {
|
|
...mapState([ 'baseURL', 'req', 'selected', 'selectedCount' ]),
|
|
url () {
|
|
// Get the current name of the file we are editing.
|
|
if (this.req.kind !== 'listing') {
|
|
return this.$route.path
|
|
}
|
|
|
|
if (this.selectedCount === 0 || this.selectedCount > 1) {
|
|
// This shouldn't happen.
|
|
return
|
|
}
|
|
|
|
return this.req.items[this.selected[0]].url
|
|
}
|
|
},
|
|
beforeMount () {
|
|
getShare(this.url)
|
|
.then(links => {
|
|
this.links = links
|
|
this.sort()
|
|
|
|
for (let link of this.links) {
|
|
if (!link.expires) {
|
|
this.hasPermanent = true
|
|
break
|
|
}
|
|
}
|
|
})
|
|
.catch(error => {
|
|
if (error === 404) return
|
|
this.$showError(error)
|
|
})
|
|
},
|
|
mounted () {
|
|
this.clip = new Clipboard('.copy-clipboard')
|
|
this.clip.on('success', (e) => {
|
|
this.$showSuccess(this.$t('success.linkCopied'))
|
|
})
|
|
},
|
|
beforeDestroy () {
|
|
this.clip.destroy()
|
|
},
|
|
methods: {
|
|
submit: function (event) {
|
|
if (!this.time) return
|
|
|
|
share(this.url, this.time, this.unit)
|
|
.then(result => { this.links.push(result); this.sort() })
|
|
.catch(this.$showError)
|
|
},
|
|
getPermalink (event) {
|
|
share(this.url)
|
|
.then(result => {
|
|
this.links.push(result)
|
|
this.sort()
|
|
this.hasPermanent = true
|
|
})
|
|
.catch(this.$showError)
|
|
},
|
|
deleteLink (event, link) {
|
|
event.preventDefault()
|
|
deleteShare(link.hash)
|
|
.then(() => {
|
|
if (!link.expires) this.hasPermanent = false
|
|
this.links = this.links.filter(item => item.hash !== link.hash)
|
|
})
|
|
.catch(this.$showError)
|
|
},
|
|
humanTime (time) {
|
|
return moment(time).fromNow()
|
|
},
|
|
buildLink (hash) {
|
|
return `${window.location.origin}${this.baseURL}/share/${hash}`
|
|
},
|
|
sort () {
|
|
this.links = this.links.sort((a, b) => {
|
|
if (!a.expires) return -1
|
|
if (!b.expires) return 1
|
|
return new Date(a.expireDate) - new Date(b.expireDate)
|
|
})
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|