feat: add command for arbitrary URLs (#137)

* feat: install command for direct downloads

* use sha1 instead of sha256

* apply suggestions

* feat: parse urls instead of using hasprefix

* stop by default and add force flag

* Implement various fixes and improvements

Co-authored-by: Tricked <72335827+SkyBlockDev@users.noreply.github.com>
Co-authored-by: comp500 <comp500@users.noreply.github.com>
This commit is contained in:
Tricked
2022-08-27 01:08:25 +02:00
committed by GitHub
parent 11671421ac
commit c7c2ca786b
5 changed files with 188 additions and 2 deletions

View File

@@ -6,6 +6,8 @@ import (
"io"
"os"
"path/filepath"
"regexp"
"strings"
)
// Mod stores metadata about a mod. This is written to a TOML file for each mod.
@@ -44,7 +46,7 @@ type ModOption struct {
}
// The three possible values of Side (the side that the mod is on) are "server", "client", and "both".
//noinspection GoUnusedConst
// noinspection GoUnusedConst
const (
ServerSide = "server"
ClientSide = "client"
@@ -129,3 +131,19 @@ func (m Mod) GetFilePath() string {
func (m Mod) GetDestFilePath() string {
return filepath.Join(filepath.Dir(m.metaFile), filepath.FromSlash(m.FileName))
}
var slugifyRegex1 = regexp.MustCompile("\\(.*\\)")
var slugifyRegex2 = regexp.MustCompile(" - .+")
var slugifyRegex3 = regexp.MustCompile("[^a-z\\d]")
var slugifyRegex4 = regexp.MustCompile("-+")
var slugifyRegex5 = regexp.MustCompile("^-|-$")
func SlugifyName(name string) string {
lower := strings.ToLower(name)
noBrackets := slugifyRegex1.ReplaceAllString(lower, "")
noSuffix := slugifyRegex2.ReplaceAllString(noBrackets, "")
limitedChars := slugifyRegex3.ReplaceAllString(noSuffix, "-")
noDuplicateDashes := slugifyRegex4.ReplaceAllString(limitedChars, "-")
noLeadingTrailingDashes := slugifyRegex5.ReplaceAllString(noDuplicateDashes, "")
return noLeadingTrailingDashes
}