init.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /**
  2. * @copyright Copyright (c) 2023 John Molakvoæ <skjnldsv@protonmail.com>
  3. *
  4. * @author John Molakvoæ <skjnldsv@protonmail.com>
  5. *
  6. * @license AGPL-3.0-or-later
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. import { loadState } from '@nextcloud/initial-state'
  23. import { translate as t } from '@nextcloud/l10n'
  24. import { View, getNavigation, Column, registerFileAction } from '@nextcloud/files'
  25. import FolderNetworkSvg from '@mdi/svg/svg/folder-network.svg?raw'
  26. import { action as enterCredentialsAction } from './actions/enterCredentialsAction'
  27. import { action as inlineStorageCheckAction } from './actions/inlineStorageCheckAction'
  28. import { action as openInFilesAction } from './actions/openInFilesAction'
  29. import { getContents } from './services/externalStorage'
  30. const allowUserMounting = loadState('files_external', 'allowUserMounting', false)
  31. // Register view
  32. const Navigation = getNavigation()
  33. Navigation.register(new View({
  34. id: 'extstoragemounts',
  35. name: t('files_external', 'External storage'),
  36. caption: t('files_external', 'List of external storage.'),
  37. emptyCaption: allowUserMounting
  38. ? t('files_external', 'There is no external storage configured. You can configure them in your Personal settings.')
  39. : t('files_external', 'There is no external storage configured and you don\'t have the permission to configure them.'),
  40. emptyTitle: t('files_external', 'No external storage'),
  41. icon: FolderNetworkSvg,
  42. order: 30,
  43. columns: [
  44. new Column({
  45. id: 'storage-type',
  46. title: t('files_external', 'Storage type'),
  47. render(node) {
  48. const backend = node.attributes?.backend || t('files_external', 'Unknown')
  49. const span = document.createElement('span')
  50. span.textContent = backend
  51. return span
  52. },
  53. }),
  54. new Column({
  55. id: 'scope',
  56. title: t('files_external', 'Scope'),
  57. render(node) {
  58. const span = document.createElement('span')
  59. let scope = t('files_external', 'Personal')
  60. if (node.attributes?.scope === 'system') {
  61. scope = t('files_external', 'System')
  62. }
  63. span.textContent = scope
  64. return span
  65. },
  66. }),
  67. ],
  68. getContents,
  69. }))
  70. // Register actions
  71. registerFileAction(enterCredentialsAction)
  72. registerFileAction(inlineStorageCheckAction)
  73. registerFileAction(openInFilesAction)