mirror of
https://github.com/jimeh/go-midjourney.git
synced 2026-02-19 01:46:41 +00:00
feat(job): add ImageFilename() method
Produces a filename string that matches what midjourney.com produces when you download a image.
This commit is contained in:
17
job.go
17
job.go
@@ -1,6 +1,9 @@
|
||||
package midjourney
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
type JobType string
|
||||
|
||||
@@ -75,3 +78,15 @@ func (j *Job) DiscordURL() string {
|
||||
func (j *Job) MainImageURL() string {
|
||||
return fmt.Sprintf("https://mj-gallery.com/%s/grid_0.png", j.ID)
|
||||
}
|
||||
|
||||
var imageFilenameRegexp = regexp.MustCompile(`[^a-zA-Z0-9\._]+`)
|
||||
|
||||
func (j *Job) ImageFilename() string {
|
||||
s := fmt.Sprintf("%s_%s", j.Username, j.Prompt)
|
||||
s = imageFilenameRegexp.ReplaceAllString(s, "_")
|
||||
if len(s) > 63 {
|
||||
s = s[:63]
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s_%s.png", s, j.ID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user