-
Notifications
You must be signed in to change notification settings - Fork 224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add searching URL support #1283
Open
FireController1847
wants to merge
2
commits into
modrinth:main
Choose a base branch
from
FireController1847:unlisted-url-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,6 +146,80 @@ if (route.query.ai) { | |
async function refreshSearch() { | ||
const base = 'https://api.modrinth.com/v2/' | ||
|
||
// Perform direct url check | ||
try { | ||
const potentialUrl = new URL(query.value) | ||
let searchResults = { | ||
hits: [], | ||
total_hits: 0, | ||
limit: 1, | ||
} | ||
if ( | ||
potentialUrl.hostname.indexOf('modrinth.com') != -1 && | ||
potentialUrl.href.indexOf(`/${projectType.value}/`) != -1 | ||
) { | ||
const potentialUrlSlashes = potentialUrl.href.split('/') | ||
const modpacksIndex = potentialUrlSlashes.indexOf(projectType.value) | ||
const packSlug = potentialUrlSlashes[modpacksIndex + 1] | ||
if (packSlug) { | ||
let url = 'project' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make it const |
||
let val = `${base}${url}/${packSlug}` | ||
let rawResults = await useFetch(val, 'direct url search results', true) | ||
let memberRawResults = await useFetch( | ||
val + `/members`, | ||
'direct url members search results', | ||
true | ||
) | ||
if (rawResults) { | ||
if (rawResults.project_type != projectType.value) { | ||
results.value = searchResults | ||
return | ||
} | ||
|
||
// Convert to ProjectResult | ||
searchResults.total_hits = 1 | ||
searchResults.hits = [ | ||
{ | ||
slug: rawResults.slug, | ||
title: rawResults.title, | ||
description: rawResults.description, | ||
categories: rawResults.categories.concat(rawResults.additional_categories), | ||
client_side: rawResults.client_side, | ||
server_side: rawResults.server_side, | ||
project_type: rawResults.project_type, | ||
downloads: rawResults.downloads, | ||
icon_url: rawResults.icon_url, | ||
color: rawResults.color, | ||
thread_id: rawResults.thread_id, | ||
monetization_status: rawResults.monetization_status, | ||
project_id: rawResults.id, | ||
author: memberRawResults | ||
.filter((mem) => mem.role === 'Owner') | ||
.map((mem) => mem.user.username)[0], | ||
display_categories: rawResults.categories, | ||
versions: rawResults.game_versions, | ||
follows: rawResults.followers, | ||
date_created: new Date().toISOString(), | ||
date_modified: rawResults.updated, | ||
latest_version: rawResults.game_versions[rawResults.game_versions.length - 1], | ||
license: rawResults.license.id, | ||
gallery: rawResults.gallery.map((img) => img.url), | ||
featured_gallery: rawResults.gallery | ||
.filter((img) => img.featured === true) | ||
.map((img) => img.url)[0], | ||
}, | ||
Comment on lines
+182
to
+210
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using update syntax |
||
] | ||
} | ||
} | ||
} | ||
results.value = searchResults | ||
|
||
// short circuit | ||
return | ||
} catch (e) { | ||
// ignore | ||
} | ||
|
||
const params = [`limit=${maxResults.value}`, `index=${sortType.value.name}`] | ||
if (query.value.length > 0) { | ||
params.push(`query=${query.value.replace(/ /g, '+')}`) | ||
|
@@ -256,13 +330,17 @@ async function refreshSearch() { | |
limit: 1, | ||
} | ||
} | ||
|
||
// Check for installed | ||
if (instanceContext.value) { | ||
for (val of rawResults.hits) { | ||
val.installed = await check_installed(instanceContext.value.path, val.project_id).then( | ||
(x) => (val.installed = x), | ||
) | ||
} | ||
} | ||
|
||
// Set results | ||
results.value = rawResults | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.