Skip to content

Commit

Permalink
fix: In modrinth, the curseforge link won't correctly handled
Browse files Browse the repository at this point in the history
  • Loading branch information
ci010 committed Jun 27, 2024
1 parent f6f27c7 commit 8561086
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 55 deletions.
52 changes: 50 additions & 2 deletions xmcl-keystone-ui/src/components/MarketProjectDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ import AppCopyChip from './AppCopyChip.vue'
import { kImageDialog } from '@/composables/imageDialog'
import { useDateString } from '@/composables/date'
import { kTheme } from '@/composables/theme'
import { clientCurseforgeV1 } from '@/util/clients'

const props = defineProps<{
detail: ProjectDetail
Expand Down Expand Up @@ -794,7 +795,7 @@ const detailsHeaders = computed(() => {
const { getDateString } = useDateString()
const hasInstalledVersion = computed(() => props.versions.some(v => v.installed))

const { replace, currentRoute } = useRouter()
const { push, replace, currentRoute } = useRouter()
const goCurseforgeProject = (id: number) => {
replace({ query: { ...currentRoute.query, id: `curseforge:${id}` } })
}
Expand Down Expand Up @@ -870,14 +871,61 @@ function onDescriptionDivClicked(e: MouseEvent) {
const href = ele.getAttribute('href')

if (href) {
emit('description-link-clicked', e, href)
onDescriptionLinkClicked(e, href)
break
}
}
ele = ele.parentElement
}
}

function onDescriptionLinkClicked(e: MouseEvent, href: string) {
const url = new URL(href)
if (url.host === 'modrinth.com') {
const slug = url.pathname.split('/')[2] ?? ''
let domain: string = ''
if (url.pathname.startsWith('/mod/')) {
domain = 'mods'
} else if (url.pathname.startsWith('/shaders/')) {
domain = 'shaderpacks'
} else if (url.pathname.startsWith('/resourcepacks/')) {
domain = 'resourcepacks'
} else if (url.pathname.startsWith('/modpacks')) {
domain = 'modpacks'
}

if (domain !== 'modpacks' && slug && domain) {
push({ query: { ...currentRoute.query, id: `modrinth:${slug}` } })
e.preventDefault()
e.stopPropagation()
}
}
if ((url.host === 'www.curseforge.com' || url.host === 'curseforge.com') && url.pathname.startsWith('/minecraft')) {
const slug = url.pathname.split('/')[3] ?? ''
let domain: string = ''
if (url.pathname.startsWith('/minecraft/mc-mods/')) {
domain = 'mods'
} else if (url.pathname.startsWith('/texture-packs/')) {
domain = 'resourcepacks'
} else if (url.pathname.startsWith('/modpacks')) {
domain = 'modpacks'
}

if (domain && domain !== 'modpacks' && slug) {
clientCurseforgeV1.searchMods({ slug, pageSize: 1 }).then((result) => {
const id = result.data[0]?.id
if (id) {
push({ query: { ...currentRoute.query, id: `curseforge:${id}` } })
} else {
window.open(href, '_blank')
}
})
e.preventDefault()
e.stopPropagation()
}
}
}

</script>

<style>
Expand Down
29 changes: 0 additions & 29 deletions xmcl-keystone-ui/src/components/MarketProjectDetailCurseforge.vue
Original file line number Diff line number Diff line change
Expand Up @@ -341,34 +341,6 @@ const onRefresh = () => {
const modrinthId = computed(() => props.modrinth || props.allFiles.find(v => v.curseforge?.projectId === props.curseforgeId && v.modrinth)?.modrinth?.projectId)
function onDescriptionLinkClicked(e: MouseEvent, href: string) {
const url = new URL(href)
if ((url.host === 'www.curseforge.com' || url.host === 'curseforge.com') && url.pathname.startsWith('/minecraft')) {
const slug = url.pathname.split('/')[3] ?? ''
let domain: string = ''
if (url.pathname.startsWith('/minecraft/mc-mods/')) {
domain = 'mods'
} else if (url.pathname.startsWith('/texture-packs/')) {
domain = 'resourcepacks'
} else if (url.pathname.startsWith('/modpacks')) {
domain = 'modpacks'
}
if (domain && domain !== 'modpacks' && slug) {
clientCurseforgeV1.searchMods({ slug, pageSize: 4 }).then((result) => {
const id = result.data[0]?.id
if (id) {
push({ query: { ...currentRoute.query, id: `curseforge:${id}` } })
} else {
window.open(href, '_blank')
}
})
e.preventDefault()
e.stopPropagation()
}
}
}
</script>
<template>
<MarketProjectDetail
Expand Down Expand Up @@ -396,6 +368,5 @@ function onDescriptionLinkClicked(e: MouseEvent, href: string) {
@install-dependency="installDependency"
@select:category="emit('category', Number($event))"
@refresh="onRefresh"
@description-link-clicked="onDescriptionLinkClicked"
/>
</template>
24 changes: 0 additions & 24 deletions xmcl-keystone-ui/src/components/MarketProjectDetailModrinth.vue
Original file line number Diff line number Diff line change
Expand Up @@ -163,29 +163,6 @@ const onOpenDependency = (dep: ProjectDependency) => {
const curseforgeId = computed(() => props.curseforge || props.allFiles.find(v => v.modrinth?.projectId === props.projectId && v.curseforge)?.curseforge?.projectId)
function onDescriptionLinkClicked(e: MouseEvent, href: string) {
const url = new URL(href)
if (url.host === 'modrinth.com') {
const slug = url.pathname.split('/')[2] ?? ''
let domain: string = ''
if (url.pathname.startsWith('/mod/')) {
domain = 'mods'
} else if (url.pathname.startsWith('/shaders/')) {
domain = 'shaderpacks'
} else if (url.pathname.startsWith('/resourcepacks/')) {
domain = 'resourcepacks'
} else if (url.pathname.startsWith('/modpacks')) {
domain = 'modpacks'
}
if (domain !== 'modpacks' && slug && domain) {
push({ query: { ...currentRoute.query, id: `modrinth:${slug}` } })
e.preventDefault()
e.stopPropagation()
}
}
}
</script>

<template>
Expand All @@ -212,6 +189,5 @@ function onDescriptionLinkClicked(e: MouseEvent, href: string) {
@install-dependency="onInstallDependency"
@select:category="emit('category', $event)"
@refresh="refresh()"
@description-link-clicked="onDescriptionLinkClicked"
/>
</template>

0 comments on commit 8561086

Please sign in to comment.