Skip to content

Commit 9745c42

Browse files
committed
refactor(appstore): adjust frontend for new API location
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent 9f580e4 commit 9745c42

4 files changed

Lines changed: 40 additions & 27 deletions

File tree

apps/appstore/src/components/AppStoreDiscover/AppStoreDiscoverSection.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ import { defineAsyncComponent, defineComponent, onBeforeMount, ref } from 'vue'
4242
import NcEmptyContent from '@nextcloud/vue/components/NcEmptyContent'
4343
import NcIconSvgWrapper from '@nextcloud/vue/components/NcIconSvgWrapper'
4444
import NcLoadingIcon from '@nextcloud/vue/components/NcLoadingIcon'
45-
import logger from '../../utils/logger.ts'
4645
import { filterElements, parseApiResponse } from '../../utils/appDiscoverParser.ts'
46+
import logger from '../../utils/logger.ts'
4747
4848
const PostType = defineAsyncComponent(() => import('./PostType.vue'))
4949
const CarouselType = defineAsyncComponent(() => import('./CarouselType.vue'))
@@ -70,7 +70,7 @@ function shuffleArray<T>(array: T[]): T[] {
7070
*/
7171
onBeforeMount(async () => {
7272
try {
73-
const { data } = await axios.get<Record<string, unknown>[]>(generateUrl('/settings/api/apps/discover'))
73+
const { data } = await axios.get<Record<string, unknown>[]>(generateUrl('/apps/appstore/api/v1/discover'))
7474
if (data.length === 0) {
7575
logger.info('No app discover elements available (empty response)')
7676
hasError.value = true

apps/appstore/src/components/AppStoreDiscover/PostType.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export default defineComponent({
144144
*
145145
* @param url The URL to resolve
146146
*/
147-
const generatePrivacyUrl = (url: string) => url.startsWith('/') ? url : generateUrl('/settings/api/apps/media?fileName={fileName}', { fileName: url })
147+
const generatePrivacyUrl = (url: string) => url.startsWith('/') ? url : generateUrl('/apps/appstore/api/v1/discover/media?fileName={fileName}', { fileName: url })
148148
149149
const mediaElement = ref<HTMLVideoElement | HTMLPictureElement>()
150150
const mediaIsVisible = useElementVisibility(mediaElement, { threshold: 0.3 })

apps/appstore/src/store/apps-store.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

6+
import type { OCSResponse } from '@nextcloud/typings/ocs'
67
import type { IAppstoreApp, IAppstoreCategory } from '../app-types.ts'
78

89
import axios from '@nextcloud/axios'
910
import { showError } from '@nextcloud/dialogs'
1011
import { loadState } from '@nextcloud/initial-state'
1112
import { translate as t } from '@nextcloud/l10n'
12-
import { generateUrl } from '@nextcloud/router'
13+
import { generateOcsUrl } from '@nextcloud/router'
1314
import { defineStore } from 'pinia'
1415
import APPSTORE_CATEGORY_ICONS from '../constants/AppstoreCategoryIcons.ts'
1516
import logger from '../utils/logger.ts'
@@ -37,8 +38,10 @@ export const useAppsStore = defineStore('settings-apps', {
3738

3839
try {
3940
this.loading.categories = true
40-
const { data: categories } = await axios.get<IAppstoreCategory[]>(generateUrl('settings/apps/categories'))
41+
const url = generateOcsUrl('apps/appstore/api/v1/apps/categories')
42+
const { data } = await axios.get<OCSResponse<IAppstoreCategory[]>>(url)
4143

44+
const categories = data.ocs.data
4245
for (const category of categories) {
4346
category.icon = APPSTORE_CATEGORY_ICONS[category.id] ?? ''
4447
}
@@ -61,10 +64,11 @@ export const useAppsStore = defineStore('settings-apps', {
6164

6265
try {
6366
this.loading.apps = true
64-
const { data } = await axios.get<{ apps: IAppstoreApp[] }>(generateUrl('settings/apps/list'))
67+
const url = generateOcsUrl('apps/appstore/api/v1/apps')
68+
const { data } = await axios.get<OCSResponse<IAppstoreApp[]>>(url)
6569

6670
this.$patch({
67-
apps: data.apps,
71+
apps: data.ocs.data,
6872
})
6973
} catch (error) {
7074
logger.error(error as Error)

apps/appstore/src/store/apps.js

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import axios from '@nextcloud/axios'
77
import { showError, showInfo } from '@nextcloud/dialogs'
88
import { loadState } from '@nextcloud/initial-state'
99
import { PwdConfirmationMode } from '@nextcloud/password-confirmation'
10-
import { generateUrl } from '@nextcloud/router'
10+
import { generateOcsUrl, generateUrl } from '@nextcloud/router'
1111
import Vue from 'vue'
1212
import logger from '../utils/logger.ts'
1313
import api from './api.js'
@@ -196,7 +196,8 @@ const actions = {
196196
}
197197
})
198198

199-
return api.post(generateUrl('settings/apps/enable'), { appIds: apps, groups }, { confirmPassword: PwdConfirmationMode.Strict })
199+
const url = generateOcsUrl('apps/appstore/api/v1/enable')
200+
return api.post(url, { appIds: apps, groups }, { confirmPassword: PwdConfirmationMode.Strict })
200201
.then((response) => {
201202
context.commit('stopLoading', apps)
202203
context.commit('stopLoading', 'install')
@@ -268,7 +269,8 @@ const actions = {
268269
return api.requireAdmin().then(() => {
269270
context.commit('startLoading', apps)
270271
context.commit('startLoading', 'install')
271-
return api.post(generateUrl('settings/apps/force'), { appId })
272+
const url = generateOcsUrl('apps/appstore/api/v1/force')
273+
return api.post(url, { appId })
272274
.then(() => {
273275
context.commit('setInstallState', { appId, canInstall: true })
274276
})
@@ -296,24 +298,28 @@ const actions = {
296298
}
297299
return api.requireAdmin().then(() => {
298300
context.commit('startLoading', apps)
299-
return api.post(generateUrl('settings/apps/disable'), { appIds: apps })
300-
.then(() => {
301-
context.commit('stopLoading', apps)
302-
apps.forEach((_appId) => {
303-
context.commit('disableApp', _appId)
301+
const url = generateOcsUrl('apps/appstore/api/v1/disable')
302+
return Promise.all(apps.map((appId) => {
303+
return api.post(url, { appId })
304+
.then(() => {
305+
context.commit('stopLoading', apps)
306+
apps.forEach((_appId) => {
307+
context.commit('disableApp', _appId)
308+
})
309+
return true
304310
})
305-
return true
306-
})
307-
.catch((error) => {
308-
context.commit('stopLoading', apps)
309-
context.commit('APPS_API_FAILURE', { appId, error })
310-
})
311+
.catch((error) => {
312+
context.commit('stopLoading', apps)
313+
context.commit('APPS_API_FAILURE', { appId, error })
314+
})
315+
}))
311316
}).catch((error) => context.commit('API_FAILURE', { appId, error }))
312317
},
313318
uninstallApp(context, { appId }) {
314319
return api.requireAdmin().then(() => {
315320
context.commit('startLoading', appId)
316-
return api.get(generateUrl(`settings/apps/uninstall/${appId}`))
321+
const url = generateOcsUrl('apps/appstore/api/v1/uninstall')
322+
return api.post(url, { appId })
317323
.then(() => {
318324
context.commit('stopLoading', appId)
319325
context.commit('uninstallApp', appId)
@@ -330,7 +336,8 @@ const actions = {
330336
return api.requireAdmin().then(() => {
331337
context.commit('startLoading', appId)
332338
context.commit('startLoading', 'install')
333-
return api.get(generateUrl(`settings/apps/update/${appId}`))
339+
const url = generateOcsUrl('apps/appstore/api/v1/update')
340+
return api.post(url, { appId })
334341
.then(() => {
335342
context.commit('stopLoading', 'install')
336343
context.commit('stopLoading', appId)
@@ -347,9 +354,11 @@ const actions = {
347354

348355
getAllApps(context) {
349356
context.commit('startLoading', 'list')
350-
return api.get(generateUrl('settings/apps/list'))
357+
const url = generateOcsUrl('apps/appstore/api/v1/apps')
358+
return api.get(url)
351359
.then((response) => {
352-
context.commit('setAllApps', response.data.apps)
360+
const apps = response.data.ocs.data
361+
context.commit('setAllApps', apps)
353362
context.commit('stopLoading', 'list')
354363
return true
355364
})
@@ -360,9 +369,9 @@ const actions = {
360369
if (shouldRefetchCategories || !context.state.gettingCategoriesPromise) {
361370
context.commit('startLoading', 'categories')
362371
try {
363-
const categoriesPromise = api.get(generateUrl('settings/apps/categories'))
372+
const categoriesPromise = api.get(generateOcsUrl('apps/appstore/api/v1/apps/categories'))
364373
context.commit('updateCategories', categoriesPromise)
365-
const categoriesPromiseResponse = await categoriesPromise
374+
const categoriesPromiseResponse = (await categoriesPromise).data.ocs
366375
if (categoriesPromiseResponse.data.length > 0) {
367376
context.commit('appendCategories', categoriesPromiseResponse.data)
368377
context.commit('stopLoading', 'categories')

0 commit comments

Comments
 (0)