Skip to content

Commit 9176054

Browse files
committed
fix(SimpCity): Update how filenames are created during download
1 parent 7376cf2 commit 9176054

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

internal/extractors/simpcity/api.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ func getThread(id string, startPage, maxPages int, headers map[string]string) <-
3535
return
3636
}
3737

38-
name := doc.Find("h1.p-title-value").Contents().Not("a, span").Text()
39-
name = strings.TrimSpace(name)
38+
title := doc.Find("h1.p-title-value").Contents().Not("a, span").Text()
39+
title = strings.TrimSpace(title)
4040

4141
pagesStr := doc.Find("li.pageNav-page > a").Last().Text()
4242
pagesNum, err := strconv.Atoi(pagesStr)
@@ -71,7 +71,7 @@ func getThread(id string, startPage, maxPages int, headers map[string]string) <-
7171
}
7272

7373
pDoc.Find("div.message-cell--main").Each(func(i int, q *goquery.Selection) {
74-
post, postErr := parsePost(id, name, q)
74+
post, postErr := parsePost(id, title, q)
7575

7676
if postErr != nil {
7777
out <- types.Result[Post]{Err: postErr}
@@ -85,7 +85,7 @@ func getThread(id string, startPage, maxPages int, headers map[string]string) <-
8585
return out
8686
}
8787

88-
func parsePost(id, name string, query *goquery.Selection) (*Post, error) {
88+
func parsePost(id, title string, query *goquery.Selection) (*Post, error) {
8989
attachments := make([]Attachment, 0)
9090
timeS := query.Find("time.u-dt")
9191
published := time.Now()
@@ -114,7 +114,7 @@ func parsePost(id, name string, query *goquery.Selection) (*Post, error) {
114114
return &Post{
115115
Id: id,
116116
Url: postUrl,
117-
Name: name,
117+
Title: title,
118118
Attachments: attachments,
119119
Published: published,
120120
}, nil

internal/extractors/simpcity/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ func (s *SimpCity) dataToMedia(post Post, sourceName string) <-chan types.Media
195195

196196
for _, attachment := range post.Attachments {
197197
media := types.NewMedia(attachment.ThumbUrl, types.SimpCity, map[string]interface{}{
198-
"id": post.Id,
198+
"name": post.Id,
199199
"url": post.Url,
200-
"name": post.Name,
200+
"title": post.Title,
201201
"source": strings.ToLower(sourceName),
202202
"created": post.Published,
203203
}, headers)

internal/extractors/simpcity/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import "time"
55
type Post struct {
66
Id string
77
Url string
8-
Name string
8+
Title string
99
Attachments []Attachment
1010
Published time.Time
1111
}

tests/simpcity_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ func TestSimpCity_QueryThread(t *testing.T) {
4040
assert.Equal(t, NumberOfPosts, len(resp.Media))
4141
assert.Equal(t, "https://simpcity.cr/attachments/1215x1688_7ec0a1bb6b3e911e892e54556be53825-jpg.2063/", resp.Media[0].Url)
4242
assert.Equal(t, "thread", resp.Media[0].Metadata["source"])
43-
assert.Equal(t, "Jessica Nigri", resp.Media[0].Metadata["name"])
43+
assert.Equal(t, "jessica-nigri.9946", resp.Media[0].Metadata["name"])
44+
assert.Equal(t, "Jessica Nigri", resp.Media[0].Metadata["title"])
4445
}
4546

4647
func TestSimpCity_QueryThread_Page45(t *testing.T) {
@@ -75,6 +76,7 @@ func TestSimpCity_QueryThread_Page45(t *testing.T) {
7576
assert.NoError(t, err)
7677
assert.Equal(t, NumberOfPosts, len(resp.Media))
7778
assert.Equal(t, "thread", resp.Media[0].Metadata["source"])
78-
assert.Equal(t, "Jessica Nigri", resp.Media[0].Metadata["name"])
79+
assert.Equal(t, "jessica-nigri.9946", resp.Media[0].Metadata["name"])
80+
assert.Equal(t, "Jessica Nigri", resp.Media[0].Metadata["title"])
7981
assert.True(t, exists)
8082
}

0 commit comments

Comments
 (0)