Skip to content

Commit df2afa9

Browse files
authored
Merge pull request #57584 from nextcloud/chore/appconfig-cleanup
refactor(core): migrate OCP.AppConfig from jQuery to axios
2 parents 3a91730 + 31ae610 commit df2afa9

File tree

5 files changed

+106
-106
lines changed

5 files changed

+106
-106
lines changed

core/src/OCP/appconfig.js

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

core/src/OCP/appconfig.ts

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
4+
* SPDX-License-Identifier: AGPL-3.0-or-later
5+
*/
6+
7+
import axios from '@nextcloud/axios'
8+
import { confirmPassword, isPasswordConfirmationRequired, PwdConfirmationMode } from '@nextcloud/password-confirmation'
9+
import { generateOcsUrl } from '@nextcloud/router'
10+
11+
/**
12+
* @param method - 'post' or 'delete'
13+
* @param endpoint - endpoint endpoint
14+
* @param options - destructuring object
15+
* @param options.data - option data
16+
* @param options.success - success callback
17+
* @param options.error - error callback
18+
*/
19+
async function call(method: string, endpoint: string, options: { data?: unknown, success?: (data: unknown) => void, error?: (e: unknown) => void } = {}) {
20+
if ((method === 'post' || method === 'delete') && isPasswordConfirmationRequired(PwdConfirmationMode.Lax)) {
21+
await confirmPassword()
22+
}
23+
24+
try {
25+
const { data } = await axios.request({
26+
method: method.toLowerCase(),
27+
url: generateOcsUrl('apps/provisioning_api/api/v1/config/apps') + endpoint,
28+
data: options.data || {},
29+
})
30+
options.success?.(data.ocs.data)
31+
} catch (error) {
32+
options.error?.(error)
33+
}
34+
}
35+
36+
/**
37+
* @param [options] destructuring object
38+
* @param [options.success] success callback
39+
* @since 11.0.0
40+
*/
41+
export function getApps(options) {
42+
call('get', '', options)
43+
}
44+
45+
/**
46+
* @param app app id
47+
* @param [options] destructuring object
48+
* @param [options.success] success callback
49+
* @param [options.error] error callback
50+
* @since 11.0.0
51+
*/
52+
export function getKeys(app, options) {
53+
call('get', '/' + app, options)
54+
}
55+
56+
/**
57+
* @param app app id
58+
* @param key key
59+
* @param defaultValue default value
60+
* @param [options] destructuring object
61+
* @param [options.success] success callback
62+
* @param [options.error] error callback
63+
* @since 11.0.0
64+
*/
65+
export function getValue(app, key, defaultValue, options) {
66+
options = options || {}
67+
options.data = {
68+
defaultValue,
69+
}
70+
71+
call('get', '/' + app + '/' + key, options)
72+
}
73+
74+
/**
75+
* @param app app id
76+
* @param key key
77+
* @param value value
78+
* @param [options] destructuring object
79+
* @param [options.success] success callback
80+
* @param [options.error] error callback
81+
* @since 11.0.0
82+
*/
83+
export function setValue(app, key, value, options) {
84+
options = options || {}
85+
options.data = {
86+
value,
87+
}
88+
89+
call('post', '/' + app + '/' + key, options)
90+
}
91+
92+
/**
93+
* @param app app id
94+
* @param key key
95+
* @param [options] destructuring object
96+
* @param [options.success] success callback
97+
* @param [options.error] error callback
98+
* @since 11.0.0
99+
*/
100+
export function deleteKey(app, key, options) {
101+
call('delete', '/' + app + '/' + key, options)
102+
}

core/src/OCP/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { loadState } from '@nextcloud/initial-state'
77
import Accessibility from './accessibility.js'
8-
import * as AppConfig from './appconfig.js'
8+
import * as AppConfig from './appconfig.ts'
99
import Collaboration from './collaboration.js'
1010
import * as Comments from './comments.js'
1111
import Loader from './loader.js'

dist/core-main.js

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

dist/core-main.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)