Skip to content

Commit 30f8f00

Browse files
committed
feat: migrate files app integration to new API
Since Nextcloud 28 the files app does not support `OCA.Files` for actions and similar integrations anymore. Instead we need to use the new files API provided by `@nextcloud/files`. Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent 8bb5123 commit 30f8f00

File tree

13 files changed

+228
-178
lines changed

13 files changed

+228
-178
lines changed

.eslintignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
js/
22
l10n/
33
src/adminSettings.js
4-
src/filetypes.js
54
src/utils.js

css/filetypes.css

Lines changed: 0 additions & 3 deletions
This file was deleted.

lib/Listener/LoadAdditionalScriptsListener.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ public function handle(Event $event): void {
4040
return;
4141
}
4242

43-
Util::addScript('maps', 'maps-filetypes');
44-
Util::addStyle('maps', 'filetypes');
43+
Util::addInitScript('maps', 'maps-init-files');
4544
}
4645
}

package-lock.json

Lines changed: 46 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@
3838
"dependencies": {
3939
"@fortawesome/fontawesome-free": "^6.7.2",
4040
"@maplibre/maplibre-gl-leaflet": "^0.1.2",
41+
"@mdi/svg": "^7.4.47",
4142
"@nextcloud/auth": "^2.5.1",
4243
"@nextcloud/axios": "^2.5.1",
4344
"@nextcloud/dialogs": "^6.3.1",
4445
"@nextcloud/event-bus": "^3.3.1",
46+
"@nextcloud/files": "^3.12.0",
4547
"@nextcloud/l10n": "^3.1.0",
4648
"@nextcloud/moment": "^1.3.4",
4749
"@nextcloud/paths": "^2.1.0",
@@ -84,6 +86,8 @@
8486
"@nextcloud/eslint-config": "^8.4.1",
8587
"@nextcloud/stylelint-config": "^3.1.0",
8688
"@nextcloud/webpack-vue-config": "^6.3.0",
87-
"@types/leaflet": "^1.9.20"
89+
"@types/leaflet": "^1.9.20",
90+
"@vue/tsconfig": "^0.5.1",
91+
"typescript": "^5.9.2"
8892
}
8993
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import axios from '@nextcloud/axios'
2+
import { showError, showSuccess } from '@nextcloud/dialogs'
3+
import { FileAction, Permission } from '@nextcloud/files'
4+
import { n, t } from '@nextcloud/l10n'
5+
import { generateUrl } from '@nextcloud/router'
6+
7+
import svgMapMarker from '@mdi/svg/svg/map-marker.svg?raw'
8+
9+
export default new FileAction({
10+
id: 'maps:import-as-favorite',
11+
12+
displayName() {
13+
return t('maps', 'Import as devices in Maps')
14+
},
15+
16+
enabled(files) {
17+
if (files.length !== 1) {
18+
return false
19+
}
20+
21+
const [file] = files
22+
if (!(file.permissions & Permission.READ)) {
23+
return false
24+
}
25+
return [
26+
'application/gpx+xml',
27+
'application/vnd.google-earth.kmz',
28+
'application/vnd.google-earth.kml+xml',
29+
].includes(file.mime)
30+
},
31+
32+
async exec(file) {
33+
const path = file.path
34+
const url = generateUrl('/apps/maps/import/devices')
35+
try {
36+
const { data } = await axios.post(url, { path })
37+
const number = typeof data === 'number' ? data : data.nbImported
38+
showSuccess(n('maps', 'One device imported', '%n devices imported', number))
39+
} catch (error) {
40+
showError(t('maps', 'Failed to import devices'))
41+
console.error('Failed to import devices', { error })
42+
}
43+
return null
44+
},
45+
46+
iconSvgInline() {
47+
return svgMapMarker
48+
},
49+
})
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import axios from '@nextcloud/axios'
2+
import { showError, showSuccess } from '@nextcloud/dialogs'
3+
import { FileAction, Permission } from '@nextcloud/files'
4+
import { n, t } from '@nextcloud/l10n'
5+
import { generateUrl } from '@nextcloud/router'
6+
7+
import svgMapMarker from '@mdi/svg/svg/map-marker.svg?raw'
8+
9+
export default new FileAction({
10+
id: 'maps:import-as-favorite',
11+
12+
displayName() {
13+
return t('maps', 'Import as favorites in Maps')
14+
},
15+
16+
enabled(files) {
17+
if (files.length !== 1) {
18+
return false
19+
}
20+
21+
const [file] = files
22+
if (!(file.permissions & Permission.READ)) {
23+
return false
24+
}
25+
return [
26+
'application/geo+json',
27+
'application/gpx+xml',
28+
'application/vnd.google-earth.kmz',
29+
'application/vnd.google-earth.kml+xml',
30+
].includes(file.mime)
31+
},
32+
33+
async exec(file) {
34+
const path = file.path
35+
const url = generateUrl('/apps/maps/import/favorites')
36+
try {
37+
const { data } = await axios.post(url, { path })
38+
const number = typeof data === 'number' ? data : data.nbImported
39+
showSuccess(n('maps', 'One favorite imported', '%n favorites imported', number))
40+
} catch (error) {
41+
showError(t('maps', 'Failed to import favorites'))
42+
console.error('Failed to import favorites', { error })
43+
}
44+
return null
45+
},
46+
47+
iconSvgInline() {
48+
return svgMapMarker
49+
},
50+
})

src/files-actions/view-in-maps.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { DefaultType, FileAction, Permission } from '@nextcloud/files'
2+
import { t } from '@nextcloud/l10n'
3+
import { generateUrl } from '@nextcloud/router'
4+
5+
import svgMapMarker from '@mdi/svg/svg/map-marker.svg?raw'
6+
7+
export default new FileAction({
8+
id: 'maps:view-map',
9+
default: DefaultType.DEFAULT,
10+
11+
displayName() {
12+
return t('maps', 'View in Maps')
13+
},
14+
15+
enabled(files) {
16+
if (files.length !== 1) {
17+
return false
18+
}
19+
20+
const [file] = files
21+
if (!(file.permissions & Permission.READ)) {
22+
return false
23+
}
24+
return [
25+
'application/gpx+xml',
26+
'application/x-nextcloud-maps',
27+
].includes(file.mime)
28+
},
29+
30+
async exec(file) {
31+
if (file.mime === 'application/x-nextcloud-maps') {
32+
const url = generateUrl('apps/maps/m/{mapId}', { mapId: file.fileid })
33+
window.open(url, '_self')
34+
} else {
35+
const url = generateUrl('apps/maps/?track={path}', { path: file.path })
36+
window.open(url, '_self')
37+
}
38+
39+
return null
40+
},
41+
42+
iconSvgInline() {
43+
return svgMapMarker
44+
},
45+
})

0 commit comments

Comments
 (0)