Skip to content
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

[FIX] Manifest URL #14

Merged
merged 10 commits into from
Jun 25, 2024
15 changes: 9 additions & 6 deletions src/modals/PluginDataModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,21 @@ export class PluginDataModal extends Modal {
new Notice('Github <username>/<repository> do not match the pattern!');
return;
}
// Check a manifest could be fetched
const manifest = await fetchManifest(repo);
if (!manifest) {
new Notice('Github repository could not be found!');
return;
}
// check there are releases for the repo
const releases = await fetchReleases(repo);
if (!releases || releases.length <= 0) {
new Notice('No releases found for this plugin. May it do not have any.');
return;
}
// Check a manifest could be fetched
const manifest =
await fetchManifest(undefined,undefined,releases[0].manifest_url) ||
await fetchManifest(repo, releases[0].tag_name) ||
await fetchManifest(repo);
if (!manifest) {
new Notice('Github repository could not be found!');
return;
}
// Combine data
const pluginInfo = Object.assign({}, manifest, { repo, releases }) as PluginInfo;
pluginInfo.targetVersion = pluginInfo.version;
Expand Down
2 changes: 1 addition & 1 deletion src/modals/PluginTroubleshootingModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class PluginTroubleshootingModal extends Modal {
}));

if (repositoryRegEx.test(this.pluginInfo.repo)) {
manifest = await fetchManifest(this.pluginInfo.repo);
manifest = await fetchManifest(this.pluginInfo.repo); // leaving this one alone as it seems to serve a different purpose - Blue Falcon
hasManifest = manifest !== undefined;
new Setting(contentEl)
.setName('Test connection')
Expand Down
6 changes: 5 additions & 1 deletion src/settings/SettingsTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,11 @@ export class VareSettingTab extends PluginSettingTab {
.onClick(async () => {
try {
// Fetch the manifest from GitHub
const manifest = await fetchManifest(plugin.repo, plugin.targetVersion);
const manifest_url = plugin.releases.find(release => release.tag_name === plugin.targetVersion)?.manifest_url;
const manifest =
await fetchManifest(undefined,undefined,manifest_url) ||
await fetchManifest(plugin.repo, plugin.targetVersion) ||
await fetchManifest(plugin.repo);
if (!manifest) {
throw Error('No manifest found for this plugin!');
}
Expand Down
11 changes: 7 additions & 4 deletions src/util/GitHub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface CommunityPlugin {

export type Release = {
url: string;
manifest_url: string;
html_url: string;
assets_url: string;
upload_url: string;
Expand Down Expand Up @@ -85,6 +86,7 @@ export async function fetchReleases(repository: string): Promise<Partial<Release
return {
tag_name: value.tag_name,
prerelease: value.prerelease,
manifest_url: value.assets.find((asset: Asset) => asset.name === 'manifest.json')?.browser_download_url,
};
});
return releases;
Expand All @@ -99,16 +101,17 @@ export async function fetchReleases(repository: string): Promise<Partial<Release
* Fetch the manifest for a plugin
* @param repository The <user>/<repo> of the plugin
* @param tag_name The name of the tag associated with a release. Required if a specific manifest version is needed.
* @param url The url to the manifest file. Optional. If not provided, the default url will be used.
* @returns The plugin manifest object
*/
export async function fetchManifest(repository: string, tag_name?: string): Promise<PluginManifest | undefined> {
const URL = `https://raw.githubusercontent.com/${repository}/${tag_name ? tag_name : 'HEAD'}/manifest.json`;
export async function fetchManifest(repository?: string, tag_name?: string, url?:string): Promise<PluginManifest | undefined> {
url = url ? url : `https://raw.githubusercontent.com/${repository}/${tag_name ? tag_name : 'HEAD'}/manifest.json`;
try {
if (!repositoryRegEx.test(repository)) {
if (repository && !repositoryRegEx.test(repository)) {
throw Error('Repository string do not match the pattern!');
}
// Do a request to the url
const response = await request({ url: URL });
const response = await request({ url });

// Process the response
return (await JSON.parse(response)) as PluginManifest;
Expand Down