Skip to content
Next Next commit
Add function to check exportability
Signed-off-by: Christopher Ng <[email protected]>
(cherry picked from commit 64c7cb8)
  • Loading branch information
Pytal committed Jun 10, 2022
commit fb767aca034feda89c1df4065e79ef37a26f6ddf
13 changes: 13 additions & 0 deletions src/services/migrationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import confirmPassword from '@nextcloud/password-confirmation'
import { generateOcsUrl } from '@nextcloud/router'

import { APP_ID, API_VERSION } from '../shared/constants.js'
import { formatQueryParamArray } from '../shared/utils.js'

/**
* @return {object}
Expand Down Expand Up @@ -59,6 +60,18 @@ export const cancelJob = async () => {
return response.data.ocs?.data
}

/**
* @param {string[]} migrators Array of migrators
*
* @return {object}
*/
export const checkExportability = async (migrators) => {
const url = generateOcsUrl('/apps/{appId}/api/v{apiVersion}/exportable', { appId: APP_ID, apiVersion: API_VERSION }) + formatQueryParamArray('migrators', migrators)
const response = await axios.get(url)

return response.data.ocs?.data
}

/**
* @param {string[]} migrators Array of migrators
*
Expand Down
31 changes: 31 additions & 0 deletions src/shared/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* @copyright 2022 Christopher Ng <[email protected]>
*
* @author Christopher Ng <[email protected]>
*
* @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
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

/**
* @param {string} name Name of the query parameter
* @param {string[]} values Array of values
*
* @return {string}
*/
export const formatQueryParamArray = (name, values) => {
return `?${values.map(value => `${name}[]=${value}`).join('&')}`
}