mirror of
https://github.com/adulau/mastodon-markdown-archive.git
synced 2024-11-22 01:47:05 +00:00
Skip 'images' folder
This commit is contained in:
parent
f9ae06fa3c
commit
f73b6c4357
2 changed files with 11 additions and 14 deletions
|
@ -67,10 +67,7 @@ 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]
|
||||||
|
@ -78,13 +75,13 @@ func (f FileWriter) Write(post client.Post) error {
|
||||||
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