diff --git a/package-lock.json b/package-lock.json index 23458bd..cb4f546 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,8 +9,10 @@ "version": "1.0.0", "license": "agpl", "dependencies": { + "@mdi/svg": "^7.4.47", "@nextcloud/axios": "^2.4.0", "@nextcloud/dialogs": "^4.2.2", + "@nextcloud/files": "^3.0.0", "@nextcloud/l10n": "^1.6.0", "@nextcloud/logger": "^2.7.0", "@nextcloud/moment": "^1.2.2", @@ -3119,9 +3121,9 @@ } }, "node_modules/@mdi/svg": { - "version": "7.3.67", - "resolved": "https://registry.npmjs.org/@mdi/svg/-/svg-7.3.67.tgz", - "integrity": "sha512-KNr7D8jbu8DEprgRckVywVBkajsGGqocFjOzlekv35UedLjpkMDTkFO8VYnhnLySL0QaPBa568fe8BZsB0TBJQ==" + "version": "7.4.47", + "resolved": "https://registry.npmjs.org/@mdi/svg/-/svg-7.4.47.tgz", + "integrity": "sha512-WQ2gDll12T9WD34fdRFgQVgO8bag3gavrAgJ0frN4phlwdJARpE6gO1YvLEMJR0KKgoc+/Ea/A0Pp11I00xBvw==" }, "node_modules/@nextcloud/auth": { "version": "2.2.1", @@ -21283,9 +21285,9 @@ } }, "@mdi/svg": { - "version": "7.3.67", - "resolved": "https://registry.npmjs.org/@mdi/svg/-/svg-7.3.67.tgz", - "integrity": "sha512-KNr7D8jbu8DEprgRckVywVBkajsGGqocFjOzlekv35UedLjpkMDTkFO8VYnhnLySL0QaPBa568fe8BZsB0TBJQ==" + "version": "7.4.47", + "resolved": "https://registry.npmjs.org/@mdi/svg/-/svg-7.4.47.tgz", + "integrity": "sha512-WQ2gDll12T9WD34fdRFgQVgO8bag3gavrAgJ0frN4phlwdJARpE6gO1YvLEMJR0KKgoc+/Ea/A0Pp11I00xBvw==" }, "@nextcloud/auth": { "version": "2.2.1", diff --git a/package.json b/package.json index bd991e9..229c834 100644 --- a/package.json +++ b/package.json @@ -25,8 +25,10 @@ "stylelint:fix": "stylelint css/*.css css/*.scss src/**/*.scss src/**/*.vue --fix" }, "dependencies": { + "@mdi/svg": "^7.4.47", "@nextcloud/axios": "^2.4.0", "@nextcloud/dialogs": "^4.2.2", + "@nextcloud/files": "^3.0.0", "@nextcloud/l10n": "^1.6.0", "@nextcloud/logger": "^2.7.0", "@nextcloud/moment": "^1.2.2", diff --git a/src/adminSettings.js b/src/adminSettings.js index 57ecaa8..e645ec7 100644 --- a/src/adminSettings.js +++ b/src/adminSettings.js @@ -25,7 +25,7 @@ import Vue from 'vue' import { translate as t, translatePlural as n } from '@nextcloud/l10n' import { generateFilePath } from '@nextcloud/router' -import BackupAdminSettings from './views/BackupAdminSettings' +import BackupAdminSettings from './views/BackupAdminSettings.vue' // eslint-disable-next-line __webpack_public_path__ = generateFilePath(appName, '', 'js/') diff --git a/src/components/AppDataSection.vue b/src/components/AppDataSection.vue index 8720046..72af956 100644 --- a/src/components/AppDataSection.vue +++ b/src/components/AppDataSection.vue @@ -94,7 +94,7 @@ import { generateOcsUrl } from '@nextcloud/router' import { showSuccess, showError } from '@nextcloud/dialogs' import { NcModal, NcButton, NcCheckboxRadioSwitch, NcSettingsSection } from '@nextcloud/vue' -import logger from '../logger' +import logger from '../logger.js' /** * @typedef {object} ExternalLocation diff --git a/src/components/ExternalLocationsSection.vue b/src/components/ExternalLocationsSection.vue index 2d6a0d8..f98ac93 100644 --- a/src/components/ExternalLocationsSection.vue +++ b/src/components/ExternalLocationsSection.vue @@ -107,7 +107,7 @@ import { generateOcsUrl } from '@nextcloud/router' import { showSuccess, showError } from '@nextcloud/dialogs' import { NcSettingsSection, NcEmptyContent, NcButton } from '@nextcloud/vue' -import logger from '../logger' +import logger from '../logger.js' /** * @typedef {object} ExternalLocation diff --git a/src/components/GeneralSettingsSection.vue b/src/components/GeneralSettingsSection.vue index 8f1ad54..a7b481d 100644 --- a/src/components/GeneralSettingsSection.vue +++ b/src/components/GeneralSettingsSection.vue @@ -252,7 +252,7 @@ import { generateOcsUrl } from '@nextcloud/router' import { showSuccess, showError } from '@nextcloud/dialogs' import { NcSettingsSection, NcCheckboxRadioSwitch, NcButton, NcModal } from '@nextcloud/vue' -import logger from '../logger' +import logger from '../logger.js' import SettingsModel from '../models/SettingsModel.js' export default { diff --git a/src/components/RestoringPointsListSection.vue b/src/components/RestoringPointsListSection.vue index 3804457..c1380ec 100644 --- a/src/components/RestoringPointsListSection.vue +++ b/src/components/RestoringPointsListSection.vue @@ -181,7 +181,7 @@ import RestoringPointHealthIcon from './RestoringPointHealthIcon.vue' import RestoringPointStatusIcon from './RestoringPointStatusIcon.vue' import SettingsModel from '../models/SettingsModel.js' import RestoringPoint from '../models/RestoringPointModel.js' -import logger from '../logger' +import logger from '../logger.js' /** * @typedef {object} ExternalLocation @@ -303,11 +303,11 @@ export default { */ /** - * @typedef {object} RestoringPoints + * @typedef {{[key: string]: PointLocation}} RestoringPoints */ /** - * @param {object} restoringPoints - The list of restoring points + * @param {RestoringPoints} restoringPoints - The list of restoring points */ handleRestoringPoints(restoringPoints) { return Object.keys(restoringPoints) @@ -332,7 +332,7 @@ export default { } // The variable assignment is useful to have type completion. - /** @type {Array} */ + /** @type {ExternalLocation[]} */ const externalStorages = this.externalStorages return externalStorages.find(storage => storage.storageId === parseInt(storageId.split(':')[1])).storage }, diff --git a/src/filesAction.js b/src/filesAction.js index fccd2a0..5fbe2d9 100644 --- a/src/filesAction.js +++ b/src/filesAction.js @@ -5,8 +5,9 @@ * later. See the COPYING file. * * @author Maxence Lange + * @author Louis Chmn * @copyright 2021, Maxence Lange - * @license GNU AGPL version 3 or any later version + * @license AGPL-3.0-or-later * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -23,54 +24,36 @@ * */ -/** global: OCA */ - import axios from '@nextcloud/axios' import { generateOcsUrl } from '@nextcloud/router' import { showSuccess, showWarning } from '@nextcloud/dialogs' - -const Backup = function() { - this.init() -} - -Backup.prototype = { - - fileActions: null, - - init() { - this._initFileActions() - }, - - _initFileActions() { - const self = this - - this.fileActions = OCA.Files.fileActions - this.fileActions.registerAction({ - name: 'ScanBackupFolder', - displayName: t('backup', 'Scan Backup Folder'), - mime: 'file', - filename: 'restoring-point.data', - order: -50, - iconClass: 'icon-folder', - permissions: OC.PERMISSION_READ, - actionHandler: self.scanBackupFile, - }) - }, - - async scanBackupFile(fileName, context) { - const fileId = context.$file.data('id') - - try { - const res = await axios.post(generateOcsUrl('apps/backup/action/scan/') + fileId + '?format=json') - showSuccess(res.data.ocs.data.message) - } catch (e) { - showWarning((e.message) || 'failed to initiate scan') - } - }, -} - -OCA.Files.Backup = Backup +import { translate as t } from '@nextcloud/l10n' +import Folder from '@mdi/svg/svg/folder.svg' +import { + FileAction, + registerFileAction, + Permission, + FileType, +} from '@nextcloud/files' window.addEventListener('DOMContentLoaded', function() { - OCA.Files.Backup = new Backup() + registerFileAction(new FileAction({ + id: 'ScanBackupFolder', + displayName() { return t('backup', 'Scan Backup Folder') }, + iconSvgInline: () => Folder, + enabled(nodes) { + return nodes.length === 1 && nodes[0].type === FileType.File && nodes[0].basename === 'restoring-point.data' && (nodes[0].permissions & Permission.READ) !== 0 + }, + async exec({ fileid }) { + try { + const res = await axios.post(generateOcsUrl('apps/backup/action/scan/') + fileid + '?format=json') + showSuccess(res.data.ocs.data.message) + return true + } catch (e) { + showWarning((e.message) || 'failed to initiate scan') + return false + } + }, + order: -50, + })) }) diff --git a/src/views/BackupAdminSettings.vue b/src/views/BackupAdminSettings.vue index 8788d7c..a22709b 100644 --- a/src/views/BackupAdminSettings.vue +++ b/src/views/BackupAdminSettings.vue @@ -30,10 +30,10 @@