mirror of
https://github.com/packwiz/packwiz.git
synced 2025-04-19 13:06:30 +02:00
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.
This commit is contained in:
parent
f47d71f203
commit
57b554d5e3
@ -85,8 +85,10 @@ var exportCmd = &cobra.Command{
|
|||||||
|
|
||||||
fmt.Printf("Retrieving %v external files...\n", len(mods))
|
fmt.Printf("Retrieving %v external files...\n", len(mods))
|
||||||
|
|
||||||
|
restrictDomains := viper.GetBool("modrinth.export.restrictDomains")
|
||||||
|
|
||||||
for _, mod := range mods {
|
for _, mod := range mods {
|
||||||
if !canBeIncludedDirectly(mod) {
|
if !canBeIncludedDirectly(mod, restrictDomains) {
|
||||||
cmdshared.PrintDisclaimer(false)
|
cmdshared.PrintDisclaimer(false)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -102,7 +104,7 @@ var exportCmd = &cobra.Command{
|
|||||||
|
|
||||||
manifestFiles := make([]PackFile, 0)
|
manifestFiles := make([]PackFile, 0)
|
||||||
for dl := range session.StartDownloads() {
|
for dl := range session.StartDownloads() {
|
||||||
if canBeIncludedDirectly(dl.Mod) {
|
if canBeIncludedDirectly(dl.Mod, restrictDomains) {
|
||||||
if dl.Error != nil {
|
if dl.Error != nil {
|
||||||
fmt.Printf("Download of %s (%s) failed: %v\n", dl.Mod.Name, dl.Mod.FileName, dl.Error)
|
fmt.Printf("Download of %s (%s) failed: %v\n", dl.Mod.Name, dl.Mod.FileName, dl.Error)
|
||||||
continue
|
continue
|
||||||
@ -272,14 +274,17 @@ var exportCmd = &cobra.Command{
|
|||||||
|
|
||||||
var whitelistedHosts = []string{
|
var whitelistedHosts = []string{
|
||||||
"cdn.modrinth.com",
|
"cdn.modrinth.com",
|
||||||
"edge.forgecdn.net",
|
|
||||||
"media.forgecdn.net",
|
|
||||||
"github.com",
|
"github.com",
|
||||||
"raw.githubusercontent.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 mod.Download.Mode == "url" || mod.Download.Mode == "" {
|
||||||
|
if !restrictDomains {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
modUrl, err := url.Parse(mod.Download.URL)
|
modUrl, err := url.Parse(mod.Download.URL)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if slices.Contains(whitelistedHosts, modUrl.Host) {
|
if slices.Contains(whitelistedHosts, modUrl.Host) {
|
||||||
@ -292,6 +297,8 @@ func canBeIncludedDirectly(mod *core.Mod) bool {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
modrinthCmd.AddCommand(exportCmd)
|
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")
|
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"))
|
_ = viper.BindPFlag("modrinth.export.output", exportCmd.Flags().Lookup("output"))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user