Stash box client interface (#751)

* Add gql client generation files
* Update dependencies
* Add stash-box client generation to the makefile
* Move scraped scene object matchers to models
* Add stash-box to scrape with dropdown
* Add scrape scene from fingerprint in UI
This commit is contained in:
WithoutPants
2020-09-17 19:57:18 +10:00
committed by GitHub
parent b0b5621337
commit 7a45943e8e
324 changed files with 34978 additions and 17323 deletions

View File

@@ -15,6 +15,8 @@ import (
"text/template"
"unicode"
"github.com/99designs/gqlgen/internal/code"
"github.com/99designs/gqlgen/internal/imports"
"github.com/pkg/errors"
)
@@ -40,9 +42,16 @@ type Options struct {
Filename string
RegionTags bool
GeneratedHeader bool
// PackageDoc is documentation written above the package line
PackageDoc string
// FileNotice is notice written below the package line
FileNotice string
// Data will be passed to the template execution.
Data interface{}
Funcs template.FuncMap
// Packages cache, you can find me on config.Config
Packages *code.Packages
}
// Render renders a gql plugin template from the given Options. Render is an
@@ -53,7 +62,7 @@ func Render(cfg Options) error {
if CurrentImports != nil {
panic(fmt.Errorf("recursive or concurrent call to RenderToFile detected"))
}
CurrentImports = &Imports{destDir: filepath.Dir(cfg.Filename)}
CurrentImports = &Imports{packages: cfg.Packages, destDir: filepath.Dir(cfg.Filename)}
// load path relative to calling source file
_, callerFile, _, _ := runtime.Caller(1)
@@ -131,9 +140,16 @@ func Render(cfg Options) error {
if cfg.GeneratedHeader {
result.WriteString("// Code generated by github.com/99designs/gqlgen, DO NOT EDIT.\n\n")
}
if cfg.PackageDoc != "" {
result.WriteString(cfg.PackageDoc + "\n")
}
result.WriteString("package ")
result.WriteString(cfg.PackageName)
result.WriteString("\n\n")
if cfg.FileNotice != "" {
result.WriteString(cfg.FileNotice)
result.WriteString("\n\n")
}
result.WriteString("import (\n")
result.WriteString(CurrentImports.String())
result.WriteString(")\n")
@@ -143,7 +159,13 @@ func Render(cfg Options) error {
}
CurrentImports = nil
return write(cfg.Filename, result.Bytes())
err = write(cfg.Filename, result.Bytes(), cfg.Packages)
if err != nil {
return err
}
cfg.Packages.Evict(code.ImportPathForDir(filepath.Dir(cfg.Filename)))
return nil
}
func center(width int, pad string, s string) string {
@@ -157,8 +179,8 @@ func center(width int, pad string, s string) string {
func Funcs() template.FuncMap {
return template.FuncMap{
"ucFirst": ucFirst,
"lcFirst": lcFirst,
"ucFirst": UcFirst,
"lcFirst": LcFirst,
"quote": strconv.Quote,
"rawQuote": rawQuote,
"dump": Dump,
@@ -180,7 +202,7 @@ func Funcs() template.FuncMap {
}
}
func ucFirst(s string) string {
func UcFirst(s string) string {
if s == "" {
return ""
}
@@ -189,7 +211,7 @@ func ucFirst(s string) string {
return string(r)
}
func lcFirst(s string) string {
func LcFirst(s string) string {
if s == "" {
return ""
}
@@ -211,6 +233,7 @@ var pkgReplacer = strings.NewReplacer(
"/", "ᚋ",
".", "ᚗ",
"-", "ᚑ",
"~", "א",
)
func TypeIdentifier(t types.Type) string {
@@ -260,6 +283,9 @@ func Call(p *types.Func) string {
}
func ToGo(name string) string {
if name == "_" {
return "_"
}
runes := make([]rune, 0, len(name))
wordWalker(name, func(info *wordInfo) {
@@ -270,7 +296,7 @@ func ToGo(name string) string {
if strings.ToUpper(word) == word || strings.ToLower(word) == word {
// FOO or foo → Foo
// FOo → FOo
word = ucFirst(strings.ToLower(word))
word = UcFirst(strings.ToLower(word))
}
}
runes = append(runes, []rune(word)...)
@@ -280,24 +306,28 @@ func ToGo(name string) string {
}
func ToGoPrivate(name string) string {
if name == "_" {
return "_"
}
runes := make([]rune, 0, len(name))
first := true
wordWalker(name, func(info *wordInfo) {
word := info.Word
if first {
switch {
case first:
if strings.ToUpper(word) == word || strings.ToLower(word) == word {
// ID → id, CAMEL → camel
word = strings.ToLower(info.Word)
} else {
// ITicket → iTicket
word = lcFirst(info.Word)
word = LcFirst(info.Word)
}
first = false
} else if info.MatchCommonInitial {
case info.MatchCommonInitial:
word = strings.ToUpper(word)
} else if !info.HasCommonInitial {
word = ucFirst(strings.ToLower(word))
case !info.HasCommonInitial:
word = UcFirst(strings.ToLower(word))
}
runes = append(runes, []rune(word)...)
})
@@ -314,14 +344,15 @@ type wordInfo struct {
// This function is based on the following code.
// https://github.com/golang/lint/blob/06c8688daad7faa9da5a0c2f163a3d14aac986ca/lint.go#L679
func wordWalker(str string, f func(*wordInfo)) {
runes := []rune(str)
runes := []rune(strings.TrimFunc(str, isDelimiter))
w, i := 0, 0 // index of start of word, scan
hasCommonInitial := false
for i+1 <= len(runes) {
eow := false // whether we hit the end of a word
if i+1 == len(runes) {
switch {
case i+1 == len(runes):
eow = true
} else if isDelimiter(runes[i+1]) {
case isDelimiter(runes[i+1]):
// underscore; shift the remainder forward over any run of underscores
eow = true
n := 1
@@ -336,7 +367,7 @@ func wordWalker(str string, f func(*wordInfo)) {
copy(runes[i+1:], runes[i+n+1:])
runes = runes[:len(runes)-n]
} else if unicode.IsLower(runes[i]) && !unicode.IsLower(runes[i+1]) {
case unicode.IsLower(runes[i]) && !unicode.IsLower(runes[i+1]):
// lower->non-lower
eow = true
}
@@ -429,6 +460,7 @@ var commonInitialisms = map[string]bool{
"IP": true,
"JSON": true,
"LHS": true,
"PGP": true,
"QPS": true,
"RAM": true,
"RHS": true,
@@ -549,13 +581,13 @@ func render(filename string, tpldata interface{}) (*bytes.Buffer, error) {
return buf, t.Execute(buf, tpldata)
}
func write(filename string, b []byte) error {
func write(filename string, b []byte, packages *code.Packages) error {
err := os.MkdirAll(filepath.Dir(filename), 0755)
if err != nil {
return errors.Wrap(err, "failed to create directory")
}
formatted, err := imports.Prune(filename, b)
formatted, err := imports.Prune(filename, b, packages)
if err != nil {
fmt.Fprintf(os.Stderr, "gofmt failed on %s: %s\n", filepath.Base(filename), err.Error())
formatted = b