mirror of
https://git.macaw.me/skunky/SkunkyArt.git
synced 2025-04-03 21:17:35 +03:00
v1.3.2
This commit is contained in:
parent
c39399403e
commit
191984b31e
19 changed files with 230 additions and 124 deletions
91
app/api.go
91
app/api.go
|
@ -9,69 +9,68 @@ import (
|
|||
)
|
||||
|
||||
type API struct {
|
||||
main *skunkyart
|
||||
main *skunkyart
|
||||
}
|
||||
|
||||
type info struct {
|
||||
Version string `json:"version"`
|
||||
Settings settingsParams `json:"settings"`
|
||||
Version string `json:"version"`
|
||||
Settings settingsParams `json:"settings"`
|
||||
}
|
||||
|
||||
func (a API) Info() {
|
||||
json, err := json.Marshal(info{
|
||||
Version: a.main.Version,
|
||||
Settings: settingsParams{
|
||||
Nsfw: CFG.Nsfw,
|
||||
Proxy: CFG.Proxy,
|
||||
},
|
||||
})
|
||||
try(err)
|
||||
a.main.Writer.Write(json)
|
||||
return
|
||||
json, err := json.Marshal(info{
|
||||
Version: a.main.Version,
|
||||
Settings: settingsParams{
|
||||
Nsfw: CFG.Nsfw,
|
||||
Proxy: CFG.Proxy,
|
||||
},
|
||||
})
|
||||
try(err)
|
||||
a.main.Writer.Write(json)
|
||||
}
|
||||
|
||||
func (a API) Error(description string, status int) {
|
||||
a.main.Writer.WriteHeader(status)
|
||||
var response strings.Builder
|
||||
response.WriteString(`{"error":"`)
|
||||
response.WriteString(description)
|
||||
response.WriteString(`"}`)
|
||||
wr(a.main.Writer, response.String())
|
||||
a.main.Writer.WriteHeader(status)
|
||||
var response strings.Builder
|
||||
response.WriteString(`{"error":"`)
|
||||
response.WriteString(description)
|
||||
response.WriteString(`"}`)
|
||||
wr(a.main.Writer, response.String())
|
||||
}
|
||||
|
||||
func (a API) sendMedia(d *devianter.Deviation) {
|
||||
mediaUrl, name := devianter.UrlFromMedia(d.Media)
|
||||
mediaUrl, name := devianter.UrlFromMedia(d.Media)
|
||||
a.main.SetFilename(name)
|
||||
|
||||
if len(mediaUrl) != 0 {
|
||||
mediaUrl = mediaUrl[21:]
|
||||
|
||||
if len(mediaUrl) != 0 {
|
||||
mediaUrl = mediaUrl[21:]
|
||||
dot := strings.Index(mediaUrl, ".")
|
||||
a.main.Writer.Header().Del("Content-Type")
|
||||
a.main.DownloadAndSendMedia(mediaUrl[:dot], mediaUrl[dot+11:])
|
||||
}
|
||||
a.main.DownloadAndSendMedia(mediaUrl[:dot], mediaUrl[dot+11:])
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: сделать фильтры
|
||||
func (a API) Random() {
|
||||
for attempt := 1;; {
|
||||
if attempt > 3 {
|
||||
a.Error("Sorry, butt NSFW on this are disabled, and the instance failed to find a random art without NSFW", 500)
|
||||
}
|
||||
|
||||
s, err, daErr := devianter.PerformSearch(string(rand.Intn(999)), rand.Intn(30), 'a')
|
||||
try(err)
|
||||
if daErr.RAW != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
deviation := &s.Results[rand.Intn(len(s.Results))]
|
||||
|
||||
if deviation.NSFW && !CFG.Nsfw {
|
||||
attempt++
|
||||
continue
|
||||
}
|
||||
|
||||
a.sendMedia(deviation)
|
||||
return
|
||||
}
|
||||
for attempt := 1; ; {
|
||||
if attempt > 3 {
|
||||
a.Error("Sorry, butt NSFW on this are disabled, and the instance failed to find a random art without NSFW", 500)
|
||||
}
|
||||
|
||||
s, err, daErr := devianter.PerformSearch(string(rand.Intn(999)), rand.Intn(30), 'a')
|
||||
try(err)
|
||||
if daErr.RAW != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
deviation := &s.Results[rand.Intn(len(s.Results))]
|
||||
|
||||
if deviation.NSFW && !CFG.Nsfw {
|
||||
attempt++
|
||||
continue
|
||||
}
|
||||
|
||||
a.sendMedia(deviation)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue