-
-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathPreviewSignature.vue
More file actions
110 lines (106 loc) · 2.16 KB
/
PreviewSignature.vue
File metadata and controls
110 lines (106 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<!--
- SPDX-FileCopyrightText: 2024 LibreCode coop and LibreCode contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<template>
<div>
<NcLoadingIcon v-if="loading" :size="64" :name="t('libresign', 'Loading …')" />
<div v-show="isLoaded" class="wrapper">
<img v-show="isLoaded"
:src="imageData"
:style="{
width,
height,
}"
@load="onImageLoad">
</div>
</div>
</template>
<script>
import axios from '@nextcloud/axios'
import { getCapabilities } from '@nextcloud/capabilities'
import NcLoadingIcon from '@nextcloud/vue/components/NcLoadingIcon'
export default {
name: 'PreviewSignature',
components: {
NcLoadingIcon,
},
props: {
src: {
type: String,
default: () => '',
required: true,
},
signRequestUuid: {
type: String,
required: false,
default: '',
},
},
data() {
return {
loading: true,
isLoaded: false,
imageData: '',
width: getCapabilities().libresign.config['sign-elements'].width,
height: getCapabilities().libresign.config['sign-elements'].height,
}
},
watch: {
src() {
this.loadImage()
},
},
mounted() {
this.loadImage()
},
methods: {
async loadImage() {
if (this.src.startsWith('data:')) {
this.imageData = this.src
return
}
const config = {
url: this.src,
method: 'get',
responseType: 'arraybuffer',
}
if (this.signRequestUuid !== '') {
config.headers = {
'libresign-sign-request-uuid': this.signRequestUuid,
}
}
await axios(config)
.then(response => {
const buffer = Buffer.from(response.data, 'binary').toString('base64')
this.imageData = 'data:' + response.headers['content-type'] + ';base64,' + buffer
this.onImageLoad(true)
})
.catch(() => this.onImageLoad(false))
},
onImageLoad(status) {
this.loading = false
this.isLoaded = true
this.$emit('loaded', status)
},
},
}
</script>
<style lang="scss" scoped>
.wrapper{
display: flex;
position: relative;
overflow: hidden;
width: 100%;
height: 100%;
justify-content: center;
align-items: center;
img{
max-width: 100%;
max-height: 100%;
position: block;
background-color: #cecece;
border-radius: 10px;
}
}
</style>