Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
zly2006 committed May 15, 2024
1 parent e1d01f6 commit 2a887ff
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 23 deletions.
10 changes: 2 additions & 8 deletions src/components/UserProfileCard.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts" setup>
import { ref, VueElement, toRefs } from 'vue';
import { doFetchDelete, Profile, toastError } from '@/constants';
import { doFetchDelete, doFetchPut, Profile, toastError } from '@/constants';
import UserBadges from '@/components/UserBadges.vue';
import VerifyMinecraft from '@/components/VerifyMinecraft.vue';
import { toast } from 'vuetify-sonner';
Expand Down Expand Up @@ -44,13 +44,7 @@ function fileSelected() {
);
return;
}
fetch('/api/account/avatar', {
method: 'PUT',
body: file,
headers: {
'X-CSRF-Token': useAppStore().csrfToken || '<no csrf token>',
},
})
doFetchPut('/api/account/avatar', file)
.then((response) => {
if (response.ok) {
console.log('avatar updated');
Expand Down
12 changes: 12 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ export function doFetchPost(url: string, data: any) {
});
}

export function doFetchPut(url: string, data: any) {
return fetch(url, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
'X-CSRF-Token': useAppStore().csrfToken || '[Reden] no csrf token',
},
credentials: 'include',
body: JSON.stringify(data),
});
}

export function doFetchGet(url: string) {
return fetch(url, {
method: 'GET',
Expand Down
13 changes: 2 additions & 11 deletions src/views/admin/AdminEditUserButton.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<script lang="ts" setup>
import { ref } from 'vue';
import { Profile, toastError } from '@/constants';
import { doFetchPut, Profile, toastError } from '@/constants';
import UserBadges from '@/components/UserBadges.vue';
import { useAppStore } from '@/store/app';
import { toast } from 'vuetify-sonner';
import RedenRouter from '@/router/RedenRouter.vue';
Expand All @@ -16,15 +15,7 @@ const resetPassword = ref(false);
function save() {
saving.value = true;
fetch(`/api/admin/user/${props.item.id}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
'X-CSRF-Token': useAppStore().csrfToken || '[Reden] no csrf token',
},
credentials: 'include',
body: JSON.stringify(mutableCopy.value),
})
doFetchPut(`/api/admin/user/${props.item.id}`, mutableCopy.value)
.then(async (res) => {
if (res.ok) {
toast('Success', {
Expand Down
12 changes: 8 additions & 4 deletions src/views/profile/UserHome.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<script lang="ts" setup>
import { doFetchGet, fetchUser, Profile, toastError } from '@/constants';
import {
doFetchGet,
doFetchPut,
fetchUser,
Profile,
toastError,
} from '@/constants';
import { toast } from 'vuetify-sonner';
import { useAppStore } from '@/store/app';
import UserProfileCard from '@/components/UserProfileCard.vue';
Expand Down Expand Up @@ -61,9 +67,7 @@ doFetchGet('/api/account/activity').then((response) => {
});
function installWebhook() {
fetch('/api/github/reden-webhook', {
method: 'PUT',
})
doFetchPut('/api/github/reden-webhook', {})
.then((response) =>
response.ok ? response.json() : Promise.reject(response),
)
Expand Down

0 comments on commit 2a887ff

Please sign in to comment.