mirror of
https://github.com/adulau/mastodon-markdown-archive.git
synced 2024-11-21 17:37:06 +00:00
Skip 'images' folder
This commit is contained in:
parent
f9ae06fa3c
commit
f73b6c4357
2 changed files with 11 additions and 14 deletions
|
@ -26,7 +26,7 @@ type MediaAttachment struct {
|
||||||
Url string `json:"url"`
|
Url string `json:"url"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
Path string
|
Path string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ma MediaAttachment) SetPath(path string) {
|
func (ma MediaAttachment) SetPath(path string) {
|
||||||
|
|
|
@ -67,24 +67,21 @@ func (f FileWriter) Write(post client.Post) error {
|
||||||
file, err = os.Create(filename)
|
file, err = os.Create(filename)
|
||||||
} else {
|
} else {
|
||||||
dir := filepath.Join(f.dir, post.Id)
|
dir := filepath.Join(f.dir, post.Id)
|
||||||
imagedir := filepath.Join(dir, "images")
|
|
||||||
|
|
||||||
os.Mkdir(dir, os.ModePerm)
|
os.Mkdir(dir, os.ModePerm)
|
||||||
os.Mkdir(imagedir, os.ModePerm)
|
|
||||||
|
|
||||||
for i := 0; i < len(post.MediaAttachments); i++ {
|
for i := 0; i < len(post.MediaAttachments); i++ {
|
||||||
media := &post.MediaAttachments[i]
|
media := &post.MediaAttachments[i]
|
||||||
if media.Type != "image" {
|
if media.Type != "image" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
image, err := downloadAttachment(imagedir, media.Id, media.Url)
|
imageFilename, err := downloadAttachment(dir, media.Id, media.Url)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
media.Path = fmt.Sprintf("images/%s", image)
|
media.Path = imageFilename
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -150,21 +147,21 @@ func downloadAttachment(dir string, id string, url string) (string, error) {
|
||||||
return filename, err
|
return filename, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var ext string
|
var extension string
|
||||||
urlExt := filepath.Ext(url)
|
urlExtension := filepath.Ext(url)
|
||||||
|
|
||||||
for _, i := range extensions {
|
for _, i := range extensions {
|
||||||
if i == urlExt {
|
if i == urlExtension {
|
||||||
ext = i
|
extension = i
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ext == "" {
|
if extension == "" {
|
||||||
return filename, fmt.Errorf("Could not match extension for media")
|
return filename, fmt.Errorf("could not match extension for media")
|
||||||
}
|
}
|
||||||
|
|
||||||
filename = fmt.Sprintf("%s%s", id, ext)
|
filename = fmt.Sprintf("%s%s", id, extension)
|
||||||
file, err := os.Create(filepath.Join(dir, filename))
|
file, err := os.Create(filepath.Join(dir, filename))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue