fix(files): Drop `xml2js` dependency and use browser native DOMParser

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
pull/45387/head
Ferdinand Thiessen 6 months ago
parent 7bc4ccba6a
commit a8f4b25ae8
No known key found for this signature in database
GPG Key ID: 45FAE7268762B400
  1. 32
      apps/files/src/views/FilesList.vue
  2. 15
      package-lock.json
  3. 3
      package.json

@ -121,14 +121,13 @@ import type { Upload } from '@nextcloud/upload'
import type { UserConfig } from '../types.ts'
import type { View, ContentsWithRoot } from '@nextcloud/files'
import { getCapabilities } from '@nextcloud/capabilities'
import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'
import { Folder, Node, Permission } from '@nextcloud/files'
import { getCapabilities } from '@nextcloud/capabilities'
import { translate as t } from '@nextcloud/l10n'
import { join, dirname } from 'path'
import { orderBy } from 'natural-orderby'
import { Parser } from 'xml2js'
import { showError } from '@nextcloud/dialogs'
import { translate, translatePlural } from '@nextcloud/l10n'
import { Type } from '@nextcloud/sharing'
import { UploadPicker } from '@nextcloud/upload'
import { loadState } from '@nextcloud/initial-state'
@ -469,6 +468,8 @@ export default defineComponent({
},
methods: {
t,
async fetchContent() {
this.loading = true
const dir = this.dir
@ -569,17 +570,19 @@ export default defineComponent({
}
// Else we try to parse the response error message
try {
const parser = new Parser({ trim: true, explicitRoot: false })
const response = await parser.parseStringPromise(upload.response?.data)
const message = response['s:message'][0] as string
if (typeof message === 'string' && message.trim() !== '') {
// The server message is also translated
showError(this.t('files', 'Error during upload: {message}', { message }))
return
if (typeof upload.response?.data === 'string') {
try {
const parser = new DOMParser()
const doc = parser.parseFromString(upload.response.data, 'text/xml')
const message = doc.getElementsByTagName('s:message')[0]?.textContent ?? ''
if (message.trim() !== '') {
// The server message is also translated
showError(t('files', 'Error during upload: {message}', { message }))
return
}
} catch (error) {
logger.error('Could not parse message', { error })
}
} catch (error) {
logger.error('Error while parsing', { error })
}
// Finally, check the status code if we have one
@ -632,9 +635,6 @@ export default defineComponent({
toggleGridView() {
this.userConfigStore.update('grid_view', !this.userConfig.grid_view)
},
t: translate,
n: translatePlural,
},
})
</script>

15
package-lock.json generated

@ -85,8 +85,7 @@
"vuedraggable": "^2.24.3",
"vuex": "^3.6.2",
"vuex-router-sync": "^5.0.0",
"webdav": "^5.5.0",
"xml2js": "^0.6.2"
"webdav": "^5.5.0"
},
"devDependencies": {
"@babel/node": "^7.22.10",
@ -28469,18 +28468,6 @@
"resolved": "https://registry.npmjs.org/xml-parse-from-string/-/xml-parse-from-string-1.0.1.tgz",
"integrity": "sha512-ErcKwJTF54uRzzNMXq2X5sMIy88zJvfN2DmdoQvy7PAFJ+tPRU6ydWuOKNMyfmOjdyBQTFREi60s0Y0SyI0G0g=="
},
"node_modules/xml2js": {
"version": "0.6.2",
"resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.6.2.tgz",
"integrity": "sha512-T4rieHaC1EXcES0Kxxj4JWgaUQHDk+qwHcYOCFHfiwKz7tOVPLq7Hjq9dM1WCMhylqMEfP7hMcOIChvotiZegA==",
"dependencies": {
"sax": ">=0.6.0",
"xmlbuilder": "~11.0.0"
},
"engines": {
"node": ">=4.0.0"
}
},
"node_modules/xmlbuilder": {
"version": "11.0.1",
"resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-11.0.1.tgz",

@ -112,8 +112,7 @@
"vuedraggable": "^2.24.3",
"vuex": "^3.6.2",
"vuex-router-sync": "^5.0.0",
"webdav": "^5.5.0",
"xml2js": "^0.6.2"
"webdav": "^5.5.0"
},
"devDependencies": {
"@babel/node": "^7.22.10",

Loading…
Cancel
Save