This repository has been archived by the owner on Oct 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
129 lines (118 loc) · 2.98 KB
/
app.js
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import 'regenerator-runtime/runtime'
import axios from 'axios'
import store from './store'
// file extensions that are supported to be opened
const fileExtensions = [
'odt',
'ott',
'ods',
'odp',
'odg',
'otg',
'doc',
'dot',
'xls',
'xlt',
'xlm',
'ppt',
'pot',
'pps',
'vsd',
'dxf',
'wmf',
'cdr',
'pages',
'number',
'key'
]
// file extensions that are working to create new files
const newFileExtensions = [
'odt',
'ods',
'odp',
'odg'
]
const openModes = [
'edit'
]
const appInfo = {
name: 'Wopi',
id: 'wopi',
isFileEditor: true,
icon: 'x-office-document',
extensions: getExtensions(openModes, fileExtensions)
}
export default {
appInfo,
store
}
function getExtension (openMode, fileExtension) {
let newFileMenu = null
if (newFileExtensions.includes(fileExtension)) {
newFileMenu = {
menuTitle ($gettext) {
return $gettext('New ' + fileExtension.toUpperCase() + ' document')
}
}
}
return {
extension: fileExtension,
icon: 'x-office-document',
routes: [
'files-personal',
'files-favorites',
'files-shared-with-others',
'files-shared-with-me'
],
handler: function ({ extensionConfig, filePath, fileId }) {
axios.interceptors.request.use(config => {
if (typeof config.headers.Authorization === 'undefined') {
if (window.Vue.$store.getters['Wopi/accessToken']) {
config.headers.Authorization = 'Bearer ' + window.Vue.$store.getters['Wopi/accessToken']
}
}
return config
})
const tokenUrl = window.Vue.$store.getters['Wopi/getServerForJsClient'] + '/api/v0/wopi/open'
axios.get(tokenUrl, { params: { fileId: fileId } })
.then(response => {
var form = document.createElement('form')
form.setAttribute('method', 'POST')
form.setAttribute('action', response.data.wopiclienturl)
form.setAttribute('target', '_blank')
var accesstoken = document.createElement('input')
accesstoken.type = 'hidden'
accesstoken.name = 'access_token'
accesstoken.value = response.data.accesstoken
form.appendChild(accesstoken)
var accesstokenttl = document.createElement('input')
accesstokenttl.type = 'hidden'
accesstokenttl.name = 'access_token_ttl'
accesstokenttl.value = response.data.accesstokenttl
form.appendChild(accesstokenttl)
var f = document.body.appendChild(form)
form.submit()
document.body.removeChild(f)
})
.catch(error => {
this.errorMessage = error.message
console.error('opening file with WOPI failed', error)
})
},
newFileMenu: newFileMenu
}
}
function getExtensions (openModes, fileExtensions) {
const ext = []
openModes.forEach(
function (m) {
fileExtensions.forEach(
function (e) {
ext.push(getExtension(m, e)
)
}
)
}
)
return ext
}