Spaces:
Paused
Paused
Update bin/modules/chapter/repositories/queries/chapter_query_impl.go
Browse files
bin/modules/chapter/repositories/queries/chapter_query_impl.go
CHANGED
|
@@ -8,14 +8,13 @@ import (
|
|
| 8 |
)
|
| 9 |
|
| 10 |
type ChapterQueryImpl struct {
|
| 11 |
-
URL
|
| 12 |
-
Collector
|
| 13 |
}
|
| 14 |
|
| 15 |
-
|
| 16 |
func NewChapterQuery(url string, collector *colly.Collector) ChapterQuery {
|
| 17 |
return &ChapterQueryImpl{
|
| 18 |
-
URL:
|
| 19 |
Collector: collector,
|
| 20 |
}
|
| 21 |
}
|
|
@@ -23,8 +22,10 @@ func NewChapterQuery(url string, collector *colly.Collector) ChapterQuery {
|
|
| 23 |
func (c ChapterQueryImpl) GetListChapter(endpoint string) utils.Result {
|
| 24 |
var output utils.Result
|
| 25 |
var chapterList []domain.Chapter
|
|
|
|
| 26 |
c.URL = config.GlobalEnv.BaseURL + endpoint
|
| 27 |
c.Collector.AllowURLRevisit = true
|
|
|
|
| 28 |
c.Collector.OnHTML("tbody._3Rsjq", func(e *colly.HTMLElement) {
|
| 29 |
e.ForEach("tr", func(i int, element *colly.HTMLElement) {
|
| 30 |
var chapter domain.Chapter
|
|
@@ -35,16 +36,17 @@ func (c ChapterQueryImpl) GetListChapter(endpoint string) utils.Result {
|
|
| 35 |
}
|
| 36 |
})
|
| 37 |
})
|
|
|
|
| 38 |
err := c.Collector.Visit(c.URL)
|
| 39 |
if err != nil {
|
| 40 |
output = utils.Result{
|
| 41 |
Error: err,
|
| 42 |
}
|
| 43 |
}
|
|
|
|
| 44 |
output = utils.Result{
|
| 45 |
Data: chapterList,
|
| 46 |
}
|
| 47 |
-
|
| 48 |
return output
|
| 49 |
}
|
| 50 |
|
|
@@ -54,15 +56,30 @@ func (c ChapterQueryImpl) DetailChapter(endpoint string) utils.Result {
|
|
| 54 |
|
| 55 |
c.URL = config.GlobalEnv.BaseURL + endpoint
|
| 56 |
c.Collector.AllowURLRevisit = true
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
})
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
})
|
|
|
|
| 66 |
err := c.Collector.Visit(c.URL)
|
| 67 |
if err != nil {
|
| 68 |
output = utils.Result{
|
|
@@ -70,8 +87,9 @@ func (c ChapterQueryImpl) DetailChapter(endpoint string) utils.Result {
|
|
| 70 |
}
|
| 71 |
return output
|
| 72 |
}
|
|
|
|
| 73 |
output = utils.Result{
|
| 74 |
Data: chapter,
|
| 75 |
}
|
| 76 |
return output
|
| 77 |
-
}
|
|
|
|
| 8 |
)
|
| 9 |
|
| 10 |
type ChapterQueryImpl struct {
|
| 11 |
+
URL string
|
| 12 |
+
Collector *colly.Collector
|
| 13 |
}
|
| 14 |
|
|
|
|
| 15 |
func NewChapterQuery(url string, collector *colly.Collector) ChapterQuery {
|
| 16 |
return &ChapterQueryImpl{
|
| 17 |
+
URL: url,
|
| 18 |
Collector: collector,
|
| 19 |
}
|
| 20 |
}
|
|
|
|
| 22 |
func (c ChapterQueryImpl) GetListChapter(endpoint string) utils.Result {
|
| 23 |
var output utils.Result
|
| 24 |
var chapterList []domain.Chapter
|
| 25 |
+
|
| 26 |
c.URL = config.GlobalEnv.BaseURL + endpoint
|
| 27 |
c.Collector.AllowURLRevisit = true
|
| 28 |
+
|
| 29 |
c.Collector.OnHTML("tbody._3Rsjq", func(e *colly.HTMLElement) {
|
| 30 |
e.ForEach("tr", func(i int, element *colly.HTMLElement) {
|
| 31 |
var chapter domain.Chapter
|
|
|
|
| 36 |
}
|
| 37 |
})
|
| 38 |
})
|
| 39 |
+
|
| 40 |
err := c.Collector.Visit(c.URL)
|
| 41 |
if err != nil {
|
| 42 |
output = utils.Result{
|
| 43 |
Error: err,
|
| 44 |
}
|
| 45 |
}
|
| 46 |
+
|
| 47 |
output = utils.Result{
|
| 48 |
Data: chapterList,
|
| 49 |
}
|
|
|
|
| 50 |
return output
|
| 51 |
}
|
| 52 |
|
|
|
|
| 56 |
|
| 57 |
c.URL = config.GlobalEnv.BaseURL + endpoint
|
| 58 |
c.Collector.AllowURLRevisit = true
|
| 59 |
+
|
| 60 |
+
// PERBAIKAN: Menggunakan selector "#Baca_Komik" agar lebih fleksibel (tidak peduli div atau section)
|
| 61 |
+
c.Collector.OnHTML("#Baca_Komik", func(e *colly.HTMLElement) {
|
| 62 |
+
e.ForEach("img", func(_ int, img *colly.HTMLElement) {
|
| 63 |
+
// PERBAIKAN: Prioritaskan atribut "data-src" (lazy load) terlebih dahulu
|
| 64 |
+
imgLink := img.Attr("data-src")
|
| 65 |
+
|
| 66 |
+
// Jika tidak ada data-src, baru ambil dari "src" standar
|
| 67 |
+
if imgLink == "" {
|
| 68 |
+
imgLink = img.Attr("src")
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
// Masukkan ke daftar jika link-nya ada isinya
|
| 72 |
+
if imgLink != "" {
|
| 73 |
+
chapter.Image = append(chapter.Image, imgLink)
|
| 74 |
+
}
|
| 75 |
+
})
|
| 76 |
})
|
| 77 |
+
|
| 78 |
+
// PERBAIKAN: Menggunakan "#Judul" agar lebih tangguh
|
| 79 |
+
c.Collector.OnHTML("#Judul", func(e *colly.HTMLElement) {
|
| 80 |
+
chapter.Title = e.ChildText("h1")
|
| 81 |
})
|
| 82 |
+
|
| 83 |
err := c.Collector.Visit(c.URL)
|
| 84 |
if err != nil {
|
| 85 |
output = utils.Result{
|
|
|
|
| 87 |
}
|
| 88 |
return output
|
| 89 |
}
|
| 90 |
+
|
| 91 |
output = utils.Result{
|
| 92 |
Data: chapter,
|
| 93 |
}
|
| 94 |
return output
|
| 95 |
+
}
|