-
-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathinit.js
More file actions
70 lines (62 loc) · 2.09 KB
/
init.js
File metadata and controls
70 lines (62 loc) · 2.09 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
/**
* SPDX-FileCopyrightText: 2020-2024 LibreCode coop and contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import Vue from 'vue'
import axios from '@nextcloud/axios'
import { addNewFileMenuEntry, Permission, getSidebar } from '@nextcloud/files'
import { registerDavProperty } from '@nextcloud/files/dav'
import { translate, translatePlural } from '@nextcloud/l10n'
import { generateOcsUrl } from '@nextcloud/router'
import { getUploader } from '@nextcloud/upload'
import logger from './logger.js'
import LibreSignLogoSvg from '../img/app-colored.svg?raw'
import LibreSignLogoDarkSvg from '../img/app-dark.svg?raw'
import { useIsDarkTheme } from './helpers/useIsDarkTheme.js'
Vue.prototype.t = translate
Vue.prototype.n = translatePlural
Vue.prototype.OC = OC
Vue.prototype.OCA = OCA
registerDavProperty('nc:libresign-signature-status', { nc: 'http://nextcloud.org/ns' })
registerDavProperty('nc:libresign-signed-node-id', { nc: 'http://nextcloud.org/ns' })
addNewFileMenuEntry({
id: 'libresign-request',
displayName: t('libresign', 'New signature request'),
iconSvgInline: useIsDarkTheme() ? LibreSignLogoDarkSvg : LibreSignLogoSvg,
uploadManager: getUploader(),
order: 1,
enabled() {
return Permission.CREATE !== 0
},
async handler(context, content) {s
const input = document.createElement('input')
input.accept = 'application/pdf'
input.type = 'file'
input.onchange = async (ev) => {
const file = ev.target.files[0]
input.remove()
if (!file) {
return
}
this.uploadManager.addNotifier(async (upload) => {
const path = context.path + '/' + upload.file.name
await axios.post(generateOcsUrl('/apps/libresign/api/v1/file'), {
file: {
path,
},
name: upload.file.name,
})
.then(async ({ data }) => {
const sidebar = getSidebar()
sidebar.open({ path }, 'libresign')
sidebar.setActiveTab('libresign')
})
.catch((error) => logger.error('Error uploading file:', error))
})
this.uploadManager
.upload(file.name, file)
.catch((error) => logger.debug('Error while uploading', { error }))
}
input.click()
},
})