From 992cdb992a2018a123e7a7c5e5157b3764b6c060 Mon Sep 17 00:00:00 2001 From: Jai A Date: Tue, 1 Dec 2020 11:39:47 -0700 Subject: [PATCH] Fix some moderation bugs --- pages/dashboard/projects.vue | 32 ++++++++++----------------- pages/mod/_id/index.vue | 34 ++++++++++++++++------------- pages/mod/_id/version/_version.vue | 35 +++++++++++++++++------------- pages/mod/_id/versions.vue | 35 +++++++++++++++++------------- pages/mods.vue | 1 + pages/user/_id.vue | 15 ++++++++++--- 6 files changed, 84 insertions(+), 68 deletions(-) diff --git a/pages/dashboard/projects.vue b/pages/dashboard/projects.vue index 46f09478..86ed02bc 100644 --- a/pages/dashboard/projects.vue +++ b/pages/dashboard/projects.vue @@ -56,33 +56,25 @@ export default { ModCard, ModIcon, }, - async fetch() { + async asyncData(data) { const config = { headers: { - Authorization: this.$auth.getToken('local'), + Authorization: data.$auth.getToken('local'), }, } - try { - let res = await axios.get( - `https://api.modrinth.com/api/v1/user/${this.$auth.user.id}/mods`, - config - ) + let res = await axios.get( + `https://api.modrinth.com/api/v1/user/${data.$auth.user.id}/mods`, + config + ) + + res = await axios.get( + `https://api.modrinth.com/api/v1/mods?ids=${JSON.stringify(res.data)}`, + config + ) - if (res.data) { - res = await axios.get( - `https://api.modrinth.com/api/v1/mods?ids=${JSON.stringify( - res.data - )}`, - config - ) - this.mods = res.data - } - } catch (err) {} - }, - data() { return { - mods: [], + mods: res.data, } }, } diff --git a/pages/mod/_id/index.vue b/pages/mod/_id/index.vue index 9dc23f04..80b92ceb 100644 --- a/pages/mod/_id/index.vue +++ b/pages/mod/_id/index.vue @@ -12,37 +12,41 @@ export default { components: { ModPage }, auth: false, async asyncData(data) { + const config = { + headers: { + Authorization: data.$auth.getToken('local'), + }, + } + let res = await axios.get( - `https://api.modrinth.com/api/v1/mod/${data.params.id}` + `https://api.modrinth.com/api/v1/mod/${data.params.id}`, + config ) const mod = res.data res = await axios.get( - `https://api.modrinth.com/api/v1/team/${mod.team}/members` + `https://api.modrinth.com/api/v1/team/${mod.team}/members`, + config ) const members = res.data for (let i = 0; i < members.length; i++) { res = await axios.get( - `https://api.modrinth.com/api/v1/user/${members[i].user_id}` + `https://api.modrinth.com/api/v1/user/${members[i].user_id}`, + config ) members[i].avatar_url = res.data.avatar_url } const body = (await axios.get(mod.body_url)).data - const versions = [] + res = await axios.get( + `https://api.modrinth.com/api/v1/versions?ids=${JSON.stringify( + mod.versions + )}`, + config + ) - for (const version of mod.versions) { - try { - res = await axios.get( - `https://api.modrinth.com/api/v1/version/${version}` - ) - versions.push(res.data) - } catch { - // eslint-disable-next-line no-console - console.log('Some versions may be missing...') - } - } + const versions = res.data.reverse() return { mod, diff --git a/pages/mod/_id/version/_version.vue b/pages/mod/_id/version/_version.vue index 4ce0f016..0f374173 100644 --- a/pages/mod/_id/version/_version.vue +++ b/pages/mod/_id/version/_version.vue @@ -119,34 +119,39 @@ export default { }, auth: false, async asyncData(data) { + const config = { + headers: { + Authorization: data.$auth.getToken('local'), + }, + } + let res = await axios.get( - `https://api.modrinth.com/api/v1/mod/${data.params.id}` + `https://api.modrinth.com/api/v1/mod/${data.params.id}`, + config ) const mod = res.data res = await axios.get( - `https://api.modrinth.com/api/v1/team/${mod.team}/members` + `https://api.modrinth.com/api/v1/team/${mod.team}/members`, + config ) const members = res.data for (let i = 0; i < members.length; i++) { res = await axios.get( - `https://api.modrinth.com/api/v1/user/${members[i].user_id}` + `https://api.modrinth.com/api/v1/user/${members[i].user_id}`, + config ) members[i].avatar_url = res.data.avatar_url } - const versions = [] - for (const version of mod.versions) { - try { - res = await axios.get( - `https://api.modrinth.com/api/v1/version/${version}` - ) - versions.push(res.data) - } catch { - // eslint-disable-next-line no-console - console.log('Some versions may be missing...') - } - } + res = await axios.get( + `https://api.modrinth.com/api/v1/versions?ids=${JSON.stringify( + mod.versions + )}`, + config + ) + + const versions = res.data.reverse() const version = versions.find((x) => x.id === data.params.version) diff --git a/pages/mod/_id/versions.vue b/pages/mod/_id/versions.vue index 1ef7987a..2f16964f 100644 --- a/pages/mod/_id/versions.vue +++ b/pages/mod/_id/versions.vue @@ -218,34 +218,39 @@ export default { }, auth: false, async asyncData(data) { + const config = { + headers: { + Authorization: data.$auth.getToken('local'), + }, + } + let res = await axios.get( - `https://api.modrinth.com/api/v1/mod/${data.params.id}` + `https://api.modrinth.com/api/v1/mod/${data.params.id}`, + config ) const mod = res.data res = await axios.get( - `https://api.modrinth.com/api/v1/team/${mod.team}/members` + `https://api.modrinth.com/api/v1/team/${mod.team}/members`, + config ) const members = res.data for (let i = 0; i < members.length; i++) { res = await axios.get( - `https://api.modrinth.com/api/v1/user/${members[i].user_id}` + `https://api.modrinth.com/api/v1/user/${members[i].user_id}`, + config ) members[i].avatar_url = res.data.avatar_url } - const versions = [] - for (const version of mod.versions) { - try { - res = await axios.get( - `https://api.modrinth.com/api/v1/version/${version}` - ) - versions.push(res.data) - } catch { - // eslint-disable-next-line no-console - console.log('Some versions may be missing...') - } - } + res = await axios.get( + `https://api.modrinth.com/api/v1/versions?ids=${JSON.stringify( + mod.versions + )}`, + config + ) + + const versions = res.data.reverse() res = await axios.get(`https://api.modrinth.com/api/v1/tag/loader`) const selectableLoaders = res.data diff --git a/pages/mods.vue b/pages/mods.vue index 871bbeca..a105ce77 100644 --- a/pages/mods.vue +++ b/pages/mods.vue @@ -389,6 +389,7 @@ export default { for (const facet of [...this.facets]) await this.toggleFacet(facet, true) this.selectedVersions = [] + this.facets.push('host:modrinth') await this.onSearchChange(1) }, async toggleFacet(elementName, sendRequest) { diff --git a/pages/user/_id.vue b/pages/user/_id.vue index 2837ab49..6ee04e4b 100644 --- a/pages/user/_id.vue +++ b/pages/user/_id.vue @@ -91,18 +91,27 @@ export default { MFooter, }, async asyncData(data) { + const config = { + headers: { + Authorization: data.$auth.getToken('local'), + }, + } + let res = await axios.get( - `https://api.modrinth.com/api/v1/user/${data.params.id}` + `https://api.modrinth.com/api/v1/user/${data.params.id}`, + config ) const user = res.data let mods = [] res = await axios.get( - `https://api.modrinth.com/api/v1/user/${data.params.id}/mods` + `https://api.modrinth.com/api/v1/user/${data.params.id}/mods`, + config ) if (res.data) { res = await axios.get( - `https://api.modrinth.com/api/v1/mods?ids=${JSON.stringify(res.data)}` + `https://api.modrinth.com/api/v1/mods?ids=${JSON.stringify(res.data)}`, + config ) mods = res.data }