| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 |
- package plane_v2
- import (
- "fmt"
- "go.uber.org/zap"
- )
- // ==================== Page API ====================
- // ListPages 列出页面
- func ListPages(slug, projectID string) ([]byte, error) {
- url := fmt.Sprintf("/api/workspaces/%s/projects/%s/pages/", slug, projectID)
- resp, err := planeWebGet(url)
- if err != nil {
- zap.L().Error("[PlaneWeb] ListPages 请求失败", zap.Error(err))
- return nil, err
- }
- if !isWebSuccess(resp.StatusCode) {
- zap.L().Error("[PlaneWeb] ListPages 返回错误", zap.String("status", resp.Status))
- return nil, fmt.Errorf("ListPages 失败: %s", resp.Status)
- }
- return resp.Body, nil
- }
- // CreatePage 创建页面
- func CreatePage(slug, projectID string, data map[string]interface{}) ([]byte, error) {
- url := fmt.Sprintf("/api/workspaces/%s/projects/%s/pages/", slug, projectID)
- resp, err := planeWebPost(url, data)
- if err != nil {
- zap.L().Error("[PlaneWeb] CreatePage 请求失败", zap.Error(err))
- return nil, err
- }
- if resp.StatusCode != 201 {
- zap.L().Error("[PlaneWeb] CreatePage 返回错误",
- zap.String("status", resp.Status),
- zap.String("body", string(resp.Body)),
- )
- return nil, fmt.Errorf("CreatePage 失败: %s", resp.Status)
- }
- return resp.Body, nil
- }
- // GetPage 获取页面详情
- func GetPage(slug, projectID, pageID string) ([]byte, error) {
- url := fmt.Sprintf("/api/workspaces/%s/projects/%s/pages/%s/", slug, projectID, pageID)
- resp, err := planeWebGet(url)
- if err != nil {
- zap.L().Error("[PlaneWeb] GetPage 请求失败", zap.Error(err))
- return nil, err
- }
- if !isWebSuccess(resp.StatusCode) {
- zap.L().Error("[PlaneWeb] GetPage 返回错误", zap.String("status", resp.Status))
- return nil, fmt.Errorf("GetPage 失败: %s", resp.Status)
- }
- return resp.Body, nil
- }
- // UpdatePage 更新页面
- func UpdatePage(slug, projectID, pageID string, data map[string]interface{}) ([]byte, error) {
- url := fmt.Sprintf("/api/workspaces/%s/projects/%s/pages/%s/", slug, projectID, pageID)
- resp, err := planeWebPatch(url, data)
- if err != nil {
- zap.L().Error("[PlaneWeb] UpdatePage 请求失败", zap.Error(err))
- return nil, err
- }
- if !isWebSuccess(resp.StatusCode) {
- zap.L().Error("[PlaneWeb] UpdatePage 返回错误",
- zap.String("status", resp.Status),
- zap.String("body", string(resp.Body)),
- )
- return nil, fmt.Errorf("UpdatePage 失败: %s", resp.Status)
- }
- return resp.Body, nil
- }
- // GetPageDescription 获取页面描述内容
- func GetPageDescription(slug, projectID, pageID string) ([]byte, error) {
- url := fmt.Sprintf("/api/workspaces/%s/projects/%s/pages/%s/description/", slug, projectID, pageID)
- resp, err := planeWebGet(url)
- if err != nil {
- zap.L().Error("[PlaneWeb] GetPageDescription 请求失败", zap.Error(err))
- return nil, err
- }
- if !isWebSuccess(resp.StatusCode) {
- zap.L().Error("[PlaneWeb] GetPageDescription 返回错误", zap.String("status", resp.Status))
- return nil, fmt.Errorf("GetPageDescription 失败: %s", resp.Status)
- }
- return resp.Body, nil
- }
- // UpdatePageDescription 更新页面描述内容
- func UpdatePageDescription(slug, projectID, pageID, descHTML string) ([]byte, error) {
- url := fmt.Sprintf("/api/workspaces/%s/projects/%s/pages/%s/description/", slug, projectID, pageID)
- payload := map[string]interface{}{
- "description_html": descHTML,
- }
- resp, err := planeWebPatch(url, payload)
- if err != nil {
- zap.L().Error("[PlaneWeb] UpdatePageDescription 请求失败", zap.Error(err))
- return nil, err
- }
- if !isWebSuccess(resp.StatusCode) {
- zap.L().Error("[PlaneWeb] UpdatePageDescription 返回错误",
- zap.String("status", resp.Status),
- zap.String("body", string(resp.Body)),
- )
- return nil, fmt.Errorf("UpdatePageDescription 失败: %s", resp.Status)
- }
- return resp.Body, nil
- }
- // DeletePage 删除页面
- func DeletePage(slug, projectID, pageID string) error {
- url := fmt.Sprintf("/api/workspaces/%s/projects/%s/pages/%s/", slug, projectID, pageID)
- resp, err := planeWebDelete(url)
- if err != nil {
- zap.L().Error("[PlaneWeb] DeletePage 请求失败", zap.Error(err))
- return err
- }
- if resp.StatusCode != 204 {
- zap.L().Error("[PlaneWeb] DeletePage 返回错误", zap.String("status", resp.Status))
- return fmt.Errorf("DeletePage 失败: %s", resp.Status)
- }
- return nil
- }
- // ArchivePage 归档页面
- func ArchivePage(slug, projectID, pageID string) error {
- url := fmt.Sprintf("/api/workspaces/%s/projects/%s/pages/%s/archive/", slug, projectID, pageID)
- resp, err := planeWebPost(url, map[string]interface{}{})
- if err != nil {
- zap.L().Error("[PlaneWeb] ArchivePage 请求失败", zap.Error(err))
- return err
- }
- if !isWebSuccess(resp.StatusCode) {
- zap.L().Error("[PlaneWeb] ArchivePage 返回错误", zap.String("status", resp.Status))
- return fmt.Errorf("ArchivePage 失败: %s", resp.Status)
- }
- return nil
- }
- // UnarchivePage 取消归档页面
- func UnarchivePage(slug, projectID, pageID string) error {
- url := fmt.Sprintf("/api/workspaces/%s/projects/%s/pages/%s/archive/", slug, projectID, pageID)
- resp, err := planeWebDelete(url)
- if err != nil {
- zap.L().Error("[PlaneWeb] UnarchivePage 请求失败", zap.Error(err))
- return err
- }
- if !isWebSuccess(resp.StatusCode) {
- zap.L().Error("[PlaneWeb] UnarchivePage 返回错误", zap.String("status", resp.Status))
- return fmt.Errorf("UnarchivePage 失败: %s", resp.Status)
- }
- return nil
- }
- // LockPage 锁定页面
- func LockPage(slug, projectID, pageID string) error {
- url := fmt.Sprintf("/api/workspaces/%s/projects/%s/pages/%s/lock/", slug, projectID, pageID)
- resp, err := planeWebPost(url, map[string]interface{}{})
- if err != nil {
- zap.L().Error("[PlaneWeb] LockPage 请求失败", zap.Error(err))
- return err
- }
- if !isWebSuccess(resp.StatusCode) {
- zap.L().Error("[PlaneWeb] LockPage 返回错误", zap.String("status", resp.Status))
- return fmt.Errorf("LockPage 失败: %s", resp.Status)
- }
- return nil
- }
- // UnlockPage 解锁页面
- func UnlockPage(slug, projectID, pageID string) error {
- url := fmt.Sprintf("/api/workspaces/%s/projects/%s/pages/%s/lock/", slug, projectID, pageID)
- resp, err := planeWebDelete(url)
- if err != nil {
- zap.L().Error("[PlaneWeb] UnlockPage 请求失败", zap.Error(err))
- return err
- }
- if !isWebSuccess(resp.StatusCode) {
- zap.L().Error("[PlaneWeb] UnlockPage 返回错误", zap.String("status", resp.Status))
- return fmt.Errorf("UnlockPage 失败: %s", resp.Status)
- }
- return nil
- }
- // SetPageAccess 设置页面访问权限 (access: 0=私密, 1=公开)
- func SetPageAccess(slug, projectID, pageID string, access int) error {
- url := fmt.Sprintf("/api/workspaces/%s/projects/%s/pages/%s/access/", slug, projectID, pageID)
- resp, err := planeWebPost(url, map[string]interface{}{"access": access})
- if err != nil {
- zap.L().Error("[PlaneWeb] SetPageAccess 请求失败", zap.Error(err))
- return err
- }
- if !isWebSuccess(resp.StatusCode) {
- zap.L().Error("[PlaneWeb] SetPageAccess 返回错误", zap.String("status", resp.Status))
- return fmt.Errorf("SetPageAccess 失败: %s", resp.Status)
- }
- return nil
- }
- // DuplicatePage 复制页面
- func DuplicatePage(slug, projectID, pageID string) ([]byte, error) {
- url := fmt.Sprintf("/api/workspaces/%s/projects/%s/pages/%s/duplicate/", slug, projectID, pageID)
- resp, err := planeWebPost(url, map[string]interface{}{})
- if err != nil {
- zap.L().Error("[PlaneWeb] DuplicatePage 请求失败", zap.Error(err))
- return nil, err
- }
- if !isWebSuccess(resp.StatusCode) {
- zap.L().Error("[PlaneWeb] DuplicatePage 返回错误",
- zap.String("status", resp.Status),
- zap.String("body", string(resp.Body)),
- )
- return nil, fmt.Errorf("DuplicatePage 失败: %s", resp.Status)
- }
- return resp.Body, nil
- }
|