Fix some moderation bugs

This commit is contained in:
Jai A
2020-12-01 11:39:47 -07:00
parent db0dc71319
commit 992cdb992a
6 changed files with 84 additions and 68 deletions

View File

@@ -56,33 +56,25 @@ export default {
ModCard, ModCard,
ModIcon, ModIcon,
}, },
async fetch() { async asyncData(data) {
const config = { const config = {
headers: { headers: {
Authorization: this.$auth.getToken('local'), Authorization: data.$auth.getToken('local'),
}, },
} }
try { let res = await axios.get(
let res = await axios.get( `https://api.modrinth.com/api/v1/user/${data.$auth.user.id}/mods`,
`https://api.modrinth.com/api/v1/user/${this.$auth.user.id}/mods`, config
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 { return {
mods: [], mods: res.data,
} }
}, },
} }

View File

@@ -12,37 +12,41 @@ export default {
components: { ModPage }, components: { ModPage },
auth: false, auth: false,
async asyncData(data) { async asyncData(data) {
const config = {
headers: {
Authorization: data.$auth.getToken('local'),
},
}
let res = await axios.get( 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 const mod = res.data
res = await axios.get( 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 const members = res.data
for (let i = 0; i < members.length; i++) { for (let i = 0; i < members.length; i++) {
res = await axios.get( 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 members[i].avatar_url = res.data.avatar_url
} }
const body = (await axios.get(mod.body_url)).data 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) { const versions = res.data.reverse()
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...')
}
}
return { return {
mod, mod,

View File

@@ -119,34 +119,39 @@ export default {
}, },
auth: false, auth: false,
async asyncData(data) { async asyncData(data) {
const config = {
headers: {
Authorization: data.$auth.getToken('local'),
},
}
let res = await axios.get( 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 const mod = res.data
res = await axios.get( 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 const members = res.data
for (let i = 0; i < members.length; i++) { for (let i = 0; i < members.length; i++) {
res = await axios.get( 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 members[i].avatar_url = res.data.avatar_url
} }
const versions = [] res = await axios.get(
for (const version of mod.versions) { `https://api.modrinth.com/api/v1/versions?ids=${JSON.stringify(
try { mod.versions
res = await axios.get( )}`,
`https://api.modrinth.com/api/v1/version/${version}` config
) )
versions.push(res.data)
} catch { const versions = res.data.reverse()
// eslint-disable-next-line no-console
console.log('Some versions may be missing...')
}
}
const version = versions.find((x) => x.id === data.params.version) const version = versions.find((x) => x.id === data.params.version)

View File

@@ -218,34 +218,39 @@ export default {
}, },
auth: false, auth: false,
async asyncData(data) { async asyncData(data) {
const config = {
headers: {
Authorization: data.$auth.getToken('local'),
},
}
let res = await axios.get( 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 const mod = res.data
res = await axios.get( 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 const members = res.data
for (let i = 0; i < members.length; i++) { for (let i = 0; i < members.length; i++) {
res = await axios.get( 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 members[i].avatar_url = res.data.avatar_url
} }
const versions = [] res = await axios.get(
for (const version of mod.versions) { `https://api.modrinth.com/api/v1/versions?ids=${JSON.stringify(
try { mod.versions
res = await axios.get( )}`,
`https://api.modrinth.com/api/v1/version/${version}` config
) )
versions.push(res.data)
} catch { const versions = res.data.reverse()
// eslint-disable-next-line no-console
console.log('Some versions may be missing...')
}
}
res = await axios.get(`https://api.modrinth.com/api/v1/tag/loader`) res = await axios.get(`https://api.modrinth.com/api/v1/tag/loader`)
const selectableLoaders = res.data const selectableLoaders = res.data

View File

@@ -389,6 +389,7 @@ export default {
for (const facet of [...this.facets]) await this.toggleFacet(facet, true) for (const facet of [...this.facets]) await this.toggleFacet(facet, true)
this.selectedVersions = [] this.selectedVersions = []
this.facets.push('host:modrinth')
await this.onSearchChange(1) await this.onSearchChange(1)
}, },
async toggleFacet(elementName, sendRequest) { async toggleFacet(elementName, sendRequest) {

View File

@@ -91,18 +91,27 @@ export default {
MFooter, MFooter,
}, },
async asyncData(data) { async asyncData(data) {
const config = {
headers: {
Authorization: data.$auth.getToken('local'),
},
}
let res = await axios.get( 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 const user = res.data
let mods = [] let mods = []
res = await axios.get( 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) { if (res.data) {
res = await axios.get( 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 mods = res.data
} }