Skip to content

Commit

Permalink
Merge pull request #12 from howarlii/master
Browse files Browse the repository at this point in the history
bug fix: can not get posts from albums
  • Loading branch information
PhiFever authored Dec 11, 2024
2 parents 0c34ff3 + 2fadf8e commit 0a91597
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
16 changes: 8 additions & 8 deletions afdian/afdian.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ import (
"context"
"encoding/json"
"fmt"
md "github.com/JohannesKaufmann/html-to-markdown"
"github.com/carlmjohnson/requests"
"github.com/spf13/cast"
"github.com/tidwall/gjson"
"io"
"log"
"net/http"
Expand All @@ -18,6 +14,11 @@ import (
"path/filepath"
"strings"
"time"

md "github.com/JohannesKaufmann/html-to-markdown"
"github.com/carlmjohnson/requests"
"github.com/spf13/cast"
"github.com/tidwall/gjson"
)

var (
Expand Down Expand Up @@ -222,18 +223,17 @@ func GetAlbumList(userId string, referer string, cookieString string) (albumList
return albumList
}

func GetAlbumPostList(albumId string, authToken string) (albumPostList []AlbumPost) {
func GetAlbumPostList(albumId string, cookieString string) (albumPostList []AlbumPost) {
postCountApiUrl := fmt.Sprintf("%s/api/user/get-album-info?album_id=%s", Host, albumId)
authTokenCookie := fmt.Sprintf("auth_token=%s", authToken)
referer := fmt.Sprintf("%s/album/%s", Host, albumId)

postCountBodyText := NewRequestGet(postCountApiUrl, authTokenCookie, referer)
postCountBodyText := NewRequestGet(postCountApiUrl, cookieString, referer)
postCount := gjson.GetBytes(postCountBodyText, "data.album.post_count").Int()

var i int64
for i = 0; i < postCount; i += 10 {
apiUrl := fmt.Sprintf("%s/api/user/get-album-post?album_id=%s&lastRank=%d&rankOrder=asc&rankField=rank", Host, albumId, i)
body := NewRequestGet(apiUrl, authTokenCookie, referer)
body := NewRequestGet(apiUrl, cookieString, referer)

albumPostListJson := gjson.GetBytes(body, "data.list")
albumPostListJson.ForEach(func(key, value gjson.Result) bool {
Expand Down
8 changes: 4 additions & 4 deletions afdian/album/album.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package album
import (
"AfdianToMarkdown/afdian"
"AfdianToMarkdown/utils"
md "github.com/JohannesKaufmann/html-to-markdown"
"github.com/spf13/cast"
"log"
"net/url"
"os"
"path"
"regexp"
"time"

md "github.com/JohannesKaufmann/html-to-markdown"
"github.com/spf13/cast"
)

func GetAlbums(authorName string, cookieString string, authToken string) error {
Expand All @@ -25,7 +26,7 @@ func GetAlbums(authorName string, cookieString string, authToken string) error {
//album.AlbumUrl会类似于 https://afdian.com/album/xyz
re := regexp.MustCompile("^.*/album/")
albumId := re.ReplaceAllString(album.AlbumUrl, "")
albumPostList := afdian.GetAlbumPostList(albumId, authToken)
albumPostList := afdian.GetAlbumPostList(albumId, cookieString)
time.Sleep(time.Millisecond * time.Duration(afdian.DelayMs))
_ = os.MkdirAll(path.Join(authorName, album.AlbumName), os.ModePerm)

Expand All @@ -49,7 +50,6 @@ func GetAlbums(authorName string, cookieString string, authToken string) error {
log.Fatal("Unknown post type")
}
}
break

}
return nil
Expand Down

0 comments on commit 0a91597

Please sign in to comment.