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"`
|
||||
Description string `json:"description"`
|
||||
Id string `json:"id"`
|
||||
Path string
|
||||
Path string
|
||||
}
|
||||
|
||||
func (ma MediaAttachment) SetPath(path string) {
|
||||
|
|
|
@ -67,10 +67,7 @@ func (f FileWriter) Write(post client.Post) error {
|
|||
file, err = os.Create(filename)
|
||||
} else {
|
||||
dir := filepath.Join(f.dir, post.Id)
|
||||
imagedir := filepath.Join(dir, "images")
|
||||
|
||||
os.Mkdir(dir, os.ModePerm)
|
||||
os.Mkdir(imagedir, os.ModePerm)
|
||||
|
||||
for i := 0; i < len(post.MediaAttachments); i++ {
|
||||
media := &post.MediaAttachments[i]
|
||||
|
@ -78,13 +75,13 @@ func (f FileWriter) Write(post client.Post) error {
|
|||
continue
|
||||
}
|
||||
|
||||
image, err := downloadAttachment(imagedir, media.Id, media.Url)
|
||||
imageFilename, err := downloadAttachment(dir, media.Id, media.Url)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
media.Path = fmt.Sprintf("images/%s", image)
|
||||
media.Path = imageFilename
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
@ -150,21 +147,21 @@ func downloadAttachment(dir string, id string, url string) (string, error) {
|
|||
return filename, err
|
||||
}
|
||||
|
||||
var ext string
|
||||
urlExt := filepath.Ext(url)
|
||||
var extension string
|
||||
urlExtension := filepath.Ext(url)
|
||||
|
||||
for _, i := range extensions {
|
||||
if i == urlExt {
|
||||
ext = i
|
||||
if i == urlExtension {
|
||||
extension = i
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if ext == "" {
|
||||
return filename, fmt.Errorf("Could not match extension for media")
|
||||
if extension == "" {
|
||||
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))
|
||||
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue