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

15
package-lock.json generated

@ -85,8 +85,7 @@
"vuedraggable": "^2.24.3", "vuedraggable": "^2.24.3",
"vuex": "^3.6.2", "vuex": "^3.6.2",
"vuex-router-sync": "^5.0.0", "vuex-router-sync": "^5.0.0",
"webdav": "^5.5.0", "webdav": "^5.5.0"
"xml2js": "^0.6.2"
}, },
"devDependencies": { "devDependencies": {
"@babel/node": "^7.22.10", "@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", "resolved": "https://registry.npmjs.org/xml-parse-from-string/-/xml-parse-from-string-1.0.1.tgz",
"integrity": "sha512-ErcKwJTF54uRzzNMXq2X5sMIy88zJvfN2DmdoQvy7PAFJ+tPRU6ydWuOKNMyfmOjdyBQTFREi60s0Y0SyI0G0g==" "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": { "node_modules/xmlbuilder": {
"version": "11.0.1", "version": "11.0.1",
"resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-11.0.1.tgz", "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-11.0.1.tgz",

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

Loading…
Cancel
Save