filebrowser/frontend/src/components/prompts/Info.vue

153 lines
3.8 KiB
Vue
Raw Normal View History

2018-02-01 12:17:04 +00:00
<template>
<div class="card floating">
<div class="card-title">
2021-03-21 11:51:58 +00:00
<h2>{{ $t("prompts.fileInfo") }}</h2>
2018-02-01 12:17:04 +00:00
</div>
<div class="card-content">
2021-03-21 11:51:58 +00:00
<p v-if="selected.length > 1">
{{ $t("prompts.filesSelected", { count: selected.length }) }}
</p>
2018-02-01 12:17:04 +00:00
2021-03-21 11:51:58 +00:00
<p class="break-word" v-if="selected.length < 2">
<strong>{{ $t("prompts.displayName") }}</strong> {{ name }}
</p>
<p v-if="!dir || selected.length > 1">
<strong>{{ $t("prompts.size") }}:</strong>
<span id="content_length"></span> {{ humanSize }}
</p>
2021-04-23 11:57:56 +00:00
<p v-if="selected.length < 2" :title="modTime">
2021-03-21 11:51:58 +00:00
<strong>{{ $t("prompts.lastModified") }}:</strong> {{ humanTime }}
</p>
2018-02-01 12:17:04 +00:00
<template v-if="dir && selected.length === 0">
2021-03-21 11:51:58 +00:00
<p>
<strong>{{ $t("prompts.numberFiles") }}:</strong> {{ req.numFiles }}
</p>
<p>
<strong>{{ $t("prompts.numberDirs") }}:</strong> {{ req.numDirs }}
</p>
2018-02-01 12:17:04 +00:00
</template>
<template v-if="!dir">
2021-03-21 11:51:58 +00:00
<p>
<strong>MD5: </strong
><code
><a @click="checksum($event, 'md5')">{{
$t("prompts.show")
}}</a></code
>
</p>
<p>
<strong>SHA1: </strong
><code
><a @click="checksum($event, 'sha1')">{{
$t("prompts.show")
}}</a></code
>
</p>
<p>
<strong>SHA256: </strong
><code
><a @click="checksum($event, 'sha256')">{{
$t("prompts.show")
}}</a></code
>
</p>
<p>
<strong>SHA512: </strong
><code
><a @click="checksum($event, 'sha512')">{{
$t("prompts.show")
}}</a></code
>
</p>
2018-02-01 12:17:04 +00:00
</template>
</div>
<div class="card-action">
2021-03-21 11:51:58 +00:00
<button
type="submit"
2018-02-01 12:17:04 +00:00
@click="$store.commit('closeHovers')"
class="button button--flat"
2018-02-01 12:17:04 +00:00
:aria-label="$t('buttons.ok')"
2021-03-21 11:51:58 +00:00
:title="$t('buttons.ok')"
>
{{ $t("buttons.ok") }}
</button>
2018-02-01 12:17:04 +00:00
</div>
</div>
</template>
<script>
2021-03-21 11:51:58 +00:00
import { mapState, mapGetters } from "vuex";
import filesize from "filesize";
import moment from "moment";
import { files as api } from "@/api";
2018-02-01 12:17:04 +00:00
export default {
2021-03-21 11:51:58 +00:00
name: "info",
2018-02-01 12:17:04 +00:00
computed: {
2021-03-21 11:51:58 +00:00
...mapState(["req", "selected"]),
...mapGetters(["selectedCount", "isListing"]),
2018-02-01 12:17:04 +00:00
humanSize: function () {
if (this.selectedCount === 0 || !this.isListing) {
2021-03-21 11:51:58 +00:00
return filesize(this.req.size);
2018-02-01 12:17:04 +00:00
}
2021-03-21 11:51:58 +00:00
let sum = 0;
2018-02-01 12:17:04 +00:00
for (let selected of this.selected) {
2021-03-21 11:51:58 +00:00
sum += this.req.items[selected].size;
2018-02-01 12:17:04 +00:00
}
2021-03-21 11:51:58 +00:00
return filesize(sum);
2018-02-01 12:17:04 +00:00
},
humanTime: function () {
if (this.selectedCount === 0) {
2021-03-21 11:51:58 +00:00
return moment(this.req.modified).fromNow();
2018-02-01 12:17:04 +00:00
}
2021-03-21 11:51:58 +00:00
return moment(this.req.items[this.selected[0]].modified).fromNow();
2018-02-01 12:17:04 +00:00
},
2021-04-23 11:57:56 +00:00
modTime: function () {
return new Date(Date.parse(this.req.modified)).toLocaleString();
},
2018-02-01 12:17:04 +00:00
name: function () {
2021-03-21 11:51:58 +00:00
return this.selectedCount === 0
? this.req.name
: this.req.items[this.selected[0]].name;
2018-02-01 12:17:04 +00:00
},
dir: function () {
2021-03-21 11:51:58 +00:00
return (
this.selectedCount > 1 ||
(this.selectedCount === 0
? this.req.isDir
: this.req.items[this.selected[0]].isDir)
);
},
},
methods: {
checksum: async function (event, algo) {
2021-03-21 11:51:58 +00:00
event.preventDefault();
2018-02-01 12:17:04 +00:00
2021-03-21 11:51:58 +00:00
let link;
2018-02-01 12:17:04 +00:00
if (this.selectedCount) {
2021-03-21 11:51:58 +00:00
link = this.req.items[this.selected[0]].url;
2018-02-01 12:17:04 +00:00
} else {
2021-03-21 11:51:58 +00:00
link = this.$route.path;
2018-02-01 12:17:04 +00:00
}
try {
2021-03-21 11:51:58 +00:00
const hash = await api.checksum(link, algo);
// eslint-disable-next-line
event.target.innerHTML = hash
} catch (e) {
2021-03-21 11:51:58 +00:00
this.$showError(e);
}
2021-03-21 11:51:58 +00:00
},
},
};
2018-02-01 12:17:04 +00:00
</script>