From 57b554d5e3250eedaef034740930915800a9d393 Mon Sep 17 00:00:00 2001 From: Jamie Mansfield Date: Thu, 2 Jun 2022 17:40:51 +0100 Subject: [PATCH] Add flag to disable Modrinth restricted domains (#126) * Update list of Modrinth approved domains * Add flag to disable Modrinth restricted domains This allows packwiz to produce .mrpack files with direct downloads, for packs that aren't distributed on modrinth.com. --- modrinth/export.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/modrinth/export.go b/modrinth/export.go index e8a651f..9bd2433 100644 --- a/modrinth/export.go +++ b/modrinth/export.go @@ -85,8 +85,10 @@ var exportCmd = &cobra.Command{ fmt.Printf("Retrieving %v external files...\n", len(mods)) + restrictDomains := viper.GetBool("modrinth.export.restrictDomains") + for _, mod := range mods { - if !canBeIncludedDirectly(mod) { + if !canBeIncludedDirectly(mod, restrictDomains) { cmdshared.PrintDisclaimer(false) break } @@ -102,7 +104,7 @@ var exportCmd = &cobra.Command{ manifestFiles := make([]PackFile, 0) for dl := range session.StartDownloads() { - if canBeIncludedDirectly(dl.Mod) { + if canBeIncludedDirectly(dl.Mod, restrictDomains) { if dl.Error != nil { fmt.Printf("Download of %s (%s) failed: %v\n", dl.Mod.Name, dl.Mod.FileName, dl.Error) continue @@ -272,14 +274,17 @@ var exportCmd = &cobra.Command{ var whitelistedHosts = []string{ "cdn.modrinth.com", - "edge.forgecdn.net", - "media.forgecdn.net", "github.com", "raw.githubusercontent.com", + "gitlab.com", } -func canBeIncludedDirectly(mod *core.Mod) bool { +func canBeIncludedDirectly(mod *core.Mod, restrictDomains bool) bool { if mod.Download.Mode == "url" || mod.Download.Mode == "" { + if !restrictDomains { + return true + } + modUrl, err := url.Parse(mod.Download.URL) if err == nil { if slices.Contains(whitelistedHosts, modUrl.Host) { @@ -292,6 +297,8 @@ func canBeIncludedDirectly(mod *core.Mod) bool { func init() { modrinthCmd.AddCommand(exportCmd) + exportCmd.Flags().Bool("restrictDomains", true, "Restricts domains to those allowed by modrinth.com") exportCmd.Flags().StringP("output", "o", "", "The file to export the modpack to") + _ = viper.BindPFlag("modrinth.export.restrictDomains", exportCmd.Flags().Lookup("restrictDomains")) _ = viper.BindPFlag("modrinth.export.output", exportCmd.Flags().Lookup("output")) }