Skip to content

Commit

Permalink
Update client.go
Browse files Browse the repository at this point in the history
  • Loading branch information
DdGnoybab authored Nov 19, 2024
1 parent dbec930 commit 5e79c1a
Showing 1 changed file with 50 additions and 2 deletions.
52 changes: 50 additions & 2 deletions core/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@ import (
"time"

"github.com/chyroc/lark"
"github.com/chyroc/lark_rate_limiter"
)

type Client struct {
larkClient *lark.Lark
}

func NewClient(appID, appSecret string, domain string) *Client {
func NewClient(appID, appSecret string) *Client {
return &Client{
larkClient: lark.New(
lark.WithAppCredential(appID, appSecret),
lark.WithOpenBaseURL("https://open."+domain),
lark.WithTimeout(60*time.Second),
lark.WithApiMiddleware(lark_rate_limiter.Wait(5, 5)),
),
}
}
Expand Down Expand Up @@ -80,6 +81,10 @@ func (c *Client) GetDocxContent(ctx context.Context, docToken string) (*lark.Doc
var blocks []*lark.DocxBlock
var pageToken *string
for {
resp2, _, err := c.larkClient.Drive.GetDocxBlockListOfDocument(ctx, &lark.GetDocxBlockListOfDocumentReq{
DocumentID: docx.DocumentID,
PageToken: pageToken,
})
if err != nil {
return docx, nil, err
}
Expand Down Expand Up @@ -126,3 +131,46 @@ func (c *Client) GetDriveFolderFileList(ctx context.Context, pageToken *string,
return files, nil
}

func (c *Client) GetWikiName(ctx context.Context, spaceID string) (string, error) {
resp, _, err := c.larkClient.Drive.GetWikiSpace(ctx, &lark.GetWikiSpaceReq{
SpaceID: spaceID,
})

if err != nil {
return "", err
}

return resp.Space.Name, nil
}

func (c *Client) GetWikiNodeList(ctx context.Context, spaceID string, parentNodeToken *string) ([]*lark.GetWikiNodeListRespItem, error) {
resp, _, err := c.larkClient.Drive.GetWikiNodeList(ctx, &lark.GetWikiNodeListReq{
SpaceID: spaceID,
PageSize: nil,
PageToken: nil,
ParentNodeToken: parentNodeToken,
})

if err != nil {
return nil, err
}

nodes := resp.Items

for resp.HasMore {
resp, _, err := c.larkClient.Drive.GetWikiNodeList(ctx, &lark.GetWikiNodeListReq{
SpaceID: spaceID,
PageSize: nil,
PageToken: nil,
ParentNodeToken: parentNodeToken,
})

if err != nil {
return nil, err
}

nodes = append(nodes, resp.Items...)
}

return nodes, nil
}

0 comments on commit 5e79c1a

Please sign in to comment.