refactor: remove useBaseFetch for @modrinth/api-client (#5596)

* Reapply "fix: start swapping useBaseFetch usages to api-client"

This reverts commit f4f33db7019ea861addb2c66c204d736800b7b6c.

* fix: bugs

* fix: analytics

* fix: lint
This commit is contained in:
Calum H.
2026-03-17 20:06:19 +00:00
committed by GitHub
parent 58c1e225c8
commit 87c86c7d0d
64 changed files with 2073 additions and 691 deletions

View File

@@ -86,6 +86,7 @@ import {
Button,
commonMessages,
defineMessages,
injectModrinthClient,
injectNotificationManager,
IntlFormatted,
normalizeChildren,
@@ -96,8 +97,8 @@ import { computed } from 'vue'
import { useAuth } from '@/composables/auth.js'
import { useScopes } from '@/composables/auth/scopes.ts'
import { useBaseFetch } from '@/composables/fetch.js'
const client = injectModrinthClient()
const { addNotification } = injectNotificationManager()
const { formatMessage } = useVIntl()
@@ -139,20 +140,16 @@ const scope = router.query?.scope || false
const state = router.query?.state || false
const getFlowIdAuthorization = async () => {
const query = {
const params = {
client_id: clientId,
redirect_uri: redirectUri,
scope,
}
if (state) {
query.state = state
params.state = state
}
const authorization = await useBaseFetch('oauth/authorize', {
method: 'GET',
internal: true,
query,
}) // This will contain the flow_id and oauth_client_id for accepting the oauth on behalf of the user
const authorization = await client.labrinth.oauth_internal.authorize(params)
if (typeof authorization === 'string') {
await navigateTo(authorization, {
@@ -175,21 +172,13 @@ const {
const { data: app } = useQuery({
queryKey: computed(() => ['oauth/app', clientId]),
queryFn: () =>
useBaseFetch('oauth/app/' + clientId, {
method: 'GET',
internal: true,
}),
queryFn: () => client.labrinth.oauth_internal.getApp(clientId),
enabled: computed(() => !!clientId),
})
const { data: createdBy } = useQuery({
queryKey: computed(() => ['user', app.value?.created_by]),
queryFn: () =>
useBaseFetch('user/' + app.value.created_by, {
method: 'GET',
apiVersion: 3,
}),
queryFn: () => client.labrinth.users_v2.get(app.value.created_by),
enabled: computed(() => !!app.value?.created_by),
})
@@ -199,12 +188,8 @@ const scopeDefinitions = computed(() =>
const onAuthorize = async () => {
try {
const res = await useBaseFetch('oauth/accept', {
method: 'POST',
internal: true,
body: {
flow: authorizationData.value.flow_id,
},
const res = await client.labrinth.oauth_internal.accept({
flow: authorizationData.value.flow_id,
})
if (typeof res === 'string') {
@@ -215,7 +200,7 @@ const onAuthorize = async () => {
}
throw new Error(formatMessage(messages.noRedirectUrlError))
} catch {
} catch (err) {
addNotification({
title: formatMessage(commonMessages.errorNotificationTitle),
text: err.data ? err.data.description : err,
@@ -226,11 +211,8 @@ const onAuthorize = async () => {
const onReject = async () => {
try {
const res = await useBaseFetch('oauth/reject', {
method: 'POST',
body: {
flow: authorizationData.value.flow_id,
},
const res = await client.labrinth.oauth_internal.reject({
flow: authorizationData.value.flow_id,
})
if (typeof res === 'string') {
@@ -241,7 +223,7 @@ const onReject = async () => {
}
throw new Error(formatMessage(messages.noRedirectUrlError))
} catch {
} catch (err) {
addNotification({
title: formatMessage(commonMessages.errorNotificationTitle),
text: err.data ? err.data.description : err,