sdk

package module
v0.1.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 11, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

docs: https://www.yuque.com/115yun/open/shtpzfhewv5nag11

https://www.yuque.com/115yun/open/qur839kyx9cgxpxi

Index

Constants

View Source
const (
	ApiBaseURL = "https://proapi.115.com"
	ApiAuthURL = "https://passportapi.115.com"
)
View Source
const (
	ApiAuthDeviceCode = ApiAuthURL + "/open/authDeviceCode"
	ApiQrCodeStatus   = "https://qrcodeapi.115.com/get/status/"
	ApiCodeToToken    = ApiAuthURL + "/open/deviceCodeToToken"
	ApiRefreshToken   = ApiAuthURL + "/open/refreshToken"
)

Auth API

View Source
const (
	ApiFsUploadGetToken = ApiBaseURL + "/open/upload/get_token"
	ApiFsUploadInit     = ApiBaseURL + "/open/upload/init"
	ApiFsUploadResume   = ApiBaseURL + "/open/upload/resume"
	ApiFsMkdir          = ApiBaseURL + "/open/folder/add"
	ApiFsGetFiles       = ApiBaseURL + "/open/ufile/files"
	ApiFsGetFolderInfo  = ApiBaseURL + "/open/folder/get_info"
	ApiFsSearchFiles    = ApiBaseURL + "/open/ufile/search"
	ApiFsCopy           = ApiBaseURL + "/open/ufile/copy"
	ApiFsMove           = ApiBaseURL + "/open/ufile/move"
	ApiFsDownURL        = ApiBaseURL + "/open/ufile/downurl"
	ApiFsUpdate         = ApiBaseURL + "/open/ufile/update"
	ApiFsDelete         = ApiBaseURL + "/open/ufile/delete"
	ApiFsRbList         = ApiBaseURL + "/open/rb/list"
	ApiFsRbRevert       = ApiBaseURL + "/open/rb/revert"
	ApiFsRbDelete       = ApiBaseURL + "/open/rb/del"
)

File API

View Source
const (
	ApiUserInfo = ApiBaseURL + "/open/user/info"
)

User API

Variables

This section is empty.

Functions

func Is401Started

func Is401Started(code int64) bool

func SliceContains

func SliceContains[T comparable](s []T, e T) bool

func Ternary

func Ternary[T any](condition bool, a T, b T) T

Types

type AuthDeviceCodeResp

type AuthDeviceCodeResp struct {
	UID    string `json:"uid"`
	Time   int64  `json:"time"`
	QrCode string `json:"qrcode"`
	Sign   string `json:"sign"`
}

type AuthResp

type AuthResp[T any] struct {
	State   int    `json:"state"`
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    T      `json:"data"`
	Error   string `json:"error"`
	Errno   int    `json:"errno"`
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

func Default

func Default() *Client

func New

func New(opts ...Option) *Client

func (*Client) AuthDeviceCode

func (c *Client) AuthDeviceCode(ctx context.Context, clientID string, codeVerifier string) (*AuthDeviceCodeResp, error)

func (*Client) AuthRequest

func (c *Client) AuthRequest(ctx context.Context, url, method string, respData any, opts ...RestyOption) (*resty.Response, error)

func (*Client) AuthRequestRaw

func (c *Client) AuthRequestRaw(ctx context.Context, url, method string, respData any, opts ...RestyOption) (*resty.Response, error)

func (*Client) CodeToToken

func (c *Client) CodeToToken(ctx context.Context, uid, codeVerifier string) (*CodeToTokenResp, error)

func (*Client) DelFile

func (c *Client) DelFile(ctx context.Context, req *DelFileReq) ([]string, error)

DelFile: https://www.yuque.com/115yun/open/kt04fu8vcchd2fnb

func (*Client) DownURL

func (c *Client) DownURL(ctx context.Context, pickCode string, ua string) (DownURLResp, error)

DownURL: https://www.yuque.com/115yun/open/um8whr91bxb5997o

func (*Client) EnableTrace

func (w *Client) EnableTrace() *Client

func (*Client) GetFolderInfo

func (c *Client) GetFolderInfo(ctx context.Context, fileID string) (*GetFolderInfoResp, error)

GetFolderInfo: https://www.yuque.com/115yun/open/rl8zrhe2nag21dfw

func (*Client) Mkdir

func (c *Client) Mkdir(ctx context.Context, pid, filename string) (*MkdirResp, error)

func (*Client) NewRequest

func (w *Client) NewRequest(ctx context.Context) *resty.Request

func (*Client) QrCodeStatus

func (c *Client) QrCodeStatus(ctx context.Context, uid, time, sign string) (*QrCodeStatusResp, error)

func (*Client) RbDelete

func (c *Client) RbDelete(ctx context.Context, tid string) ([]string, error)

RbDel: https://www.yuque.com/115yun/open/gwtof85nmboulrce

func (*Client) RbList

func (c *Client) RbList(ctx context.Context, limit, offset int64) (*RbListResp, error)

RbList: https://www.yuque.com/115yun/open/bg7l4328t98fwgex

func (*Client) RefreshToken

func (c *Client) RefreshToken(ctx context.Context) (*RefreshTokenResp, error)

func (*Client) Request

func (c *Client) Request(ctx context.Context, url string, method string, opts ...RestyOption) (*resty.Response, error)

func (*Client) SetAccessToken

func (w *Client) SetAccessToken(token string) *Client

func (*Client) SetDebug

func (w *Client) SetDebug(d bool) *Client

func (*Client) SetHttpClient

func (w *Client) SetHttpClient(httpClient *http.Client) *Client

func (*Client) SetOnRefreshToken

func (w *Client) SetOnRefreshToken(fn func(accessToken string, refreshToken string)) *Client

func (*Client) SetProxy

func (w *Client) SetProxy(proxy string) *Client

func (*Client) SetRefreshToken

func (w *Client) SetRefreshToken(token string) *Client

func (*Client) SetUserAgent

func (w *Client) SetUserAgent(userAgent string) *Client

func (*Client) UploadGetToken

func (c *Client) UploadGetToken(ctx context.Context) (*UploadGetTokenResp, error)

UploadGetToken: https://www.yuque.com/115yun/open/kzacvzl0g7aiyyn4

type CodeToTokenResp

type CodeToTokenResp struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	ExpiresIn    int64  `json:"expires_in"`
}

type CopyReq

type CopyReq struct {
	PID     string `json:"pid"`      // 目标目录,即所需移动到的目录
	FileID  string `json:"file_id"`  // 所复制的文件和目录ID,多个文件和目录请以 , 隔开
	NoDupli string `json:"no_dupli"` // 复制的文件在目标目录是否允许重复,默认0:0:可以;1:不可以
}

type DelFileReq

type DelFileReq struct {
	FileIDs  string `json:"file_ids"`  // 需要删除的文件(夹)ID
	ParentID string `json:"parent_id"` // 删除的文件(夹)ID所在的父目录ID
}

type DownURLResp

type DownURLResp = map[string]struct {
	FileName string `json:"file_name"`
	FileSize int64  `json:"file_size"`
	PickCode string `json:"pick_code"`
	Sha1     string `json:"sha1"`
	URL      struct {
		URL string `json:"url"`
	} `json:"url"`
}

type Error

type Error struct {
	Code    int64  `json:"code"`
	Message string `json:"message"`
}

func (*Error) Error

func (e *Error) Error() string

type Form

type Form map[string]string

type GetFilesReq

type GetFilesReq struct {
	CID         string
	Type        string
	Limit       int64
	Offset      int64
	Suffix      string
	ASC         bool   // 1: asc, 0: desc
	O           string // order by file_name|file_size|user_utime|file_type
	CustomOrder int
	Stdir       int  // 筛选文件时, 是否显示文件夹;1:要展示文件夹 0不展示
	Star        bool // 1: filter star files
	Cur         int  // 是否只显示当前文件夹内文件
	ShowDir     bool // 是否显示目录;0 或 1,默认为0
}

type GetFilesResp

type GetFilesResp struct {
	Resp[[]GetFilesResp_File]
	Count          int64       `json:"count"`     // 当前目录文件数量
	SysCount       int64       `json:"sys_count"` // 系统文件夹数量
	Offset         int64       `json:"offset"`    // 偏移量
	Limit          json.Number `json:"limit"`     // 分页量
	Aid            int         `json:"aid"`       // 文件的状态,aid 的别名。1 正常,7 删除(回收站),120 彻底删除
	Cid            int64       `json:"cid"`       // 父目录ID
	IsAsc          int         `json:"is_asc"`    // 1: asc, 0: desc
	MinSize        int64       `json:"min_size"`
	MaxSize        int64       `json:"max_size"`
	SysDir         string      `json:"sys_dir"`
	HideData       string      `json:"hide_data"`        //是否返回文件数据
	RecordOpenTime string      `json:"record_open_time"` //是否记录文件夹的打开时间
	Star           int         `json:"star"`             //是否星标;1:星标;0:未星标
	Type           int         `json:"type"`             //一级筛选大分类,1:文档,2:图片,3:音乐,4:视频,5:压缩包,6:应用
	Suffix         string      `json:"suffix"`           //一级筛选选其他时填写的后缀名
	Path           []struct {
		Name string      `json:"name"` //父目录名
		Aid  json.Number `json:"aid"`
		Cid  json.Number `json:"cid"`
		Pid  json.Number `json:"pid"`
		Isp  json.Number `json:"isp"`
		PCid string      `json:"p_cid"`
		Fv   string      `json:"fv"`
	} `json:"path"` //父目录树
	Cur    int64  `json:"cur"`
	StdDir int    `json:"stdir"`
	Fields string `json:"fields"`
	Order  string `json:"order"`
}

type GetFilesResp_File

type GetFilesResp_File struct {
	Fid       string                 `json:"fid"`  // 文件ID
	Aid       string                 `json:"aid"`  // 文件的状态,aid 的别名。1 正常,7 删除(回收站),120 彻底删除
	Pid       string                 `json:"pid"`  // 父文件夹ID
	Fc        string                 `json:"fc"`   // 文件分类 0 文件夹 1 文件
	Fn        string                 `json:"fn"`   // 文件名
	Fco       string                 `json:"fco"`  // 文件夹封面
	Ism       string                 `json:"ism"`  // 是否星标,1:星标
	Isp       int                    `json:"isp"`  // 是否加密;1:加密
	Pc        string                 `json:"pc"`   // 文件提取码
	Upt       int64                  `json:"upt"`  // 修改时间
	Uet       int64                  `json:"uet"`  // 修改时间
	UpPt      int64                  `json:"uppt"` // 上传时间
	Cm        int64                  `json:"cm"`
	FDesc     string                 `json:"fdesc"`     // 文件备注
	IsPl      int64                  `json:"ispl"`      // 是否统计文件夹下视频时长开关
	Fl        []GetFilesResp_File_FL `json:"fl"`        // 文件标签
	Sha1      string                 `json:"sha1"`      // 文件sha1
	FS        int64                  `json:"fs"`        // 文件大小
	Fta       string                 `json:"fta"`       // 文件状态 0/2 未上传完成,1 已上传完成
	Ico       string                 `json:"ico"`       // 文件后缀名
	Fatr      string                 `json:"fatr"`      // 音频长度
	IsV       int64                  `json:"isv"`       // 是否视频文件
	Def       int64                  `json:"def"`       // 视频清晰度;1:标清 2:高清 3:超清 4:1080P 5:4k;100:原画
	Def2      int64                  `json:"def2"`      // 视频清晰度;1:标清 2:高清 3:超清 4:1080P 5:4k;100:原画
	PlayLong  json.Number            `json:"play_long"` // 音视频时长
	VImg      string                 `json:"v_img"`
	Thumbnail string                 `json:"thumb"` // 图片缩略图
	Uo        string                 `json:"uo"`    // 原图地址
}

type GetFilesResp_File_FL

type GetFilesResp_File_FL struct {
	Id         string `json:"id"`          // 文件标签ID
	Name       string `json:"name"`        // 文件标签名称
	Sort       string `json:"sort"`        // 文件标签排序
	Color      string `json:"color"`       // 文件标签颜色
	IsDefault  int    `json:"is_default"`  // 文件标签类型;0:最近使用;1:非最近使用;2:为默认标签
	UpdateTime int64  `json:"update_time"` // 文件标签更新时间
	CreateTime int64  `json:"create_time"` // 文件标签创建时间
}

type GetFolderInfoResp

type GetFolderInfoResp struct {
	Count        string `json:"count"`
	Size         string `json:"size"`
	FolderCount  int64  `json:"folder_count"`
	PlayLong     int64  `json:"play_long"`
	ShowPlayLong int64  `json:"show_play_long"`
	PTime        string `json:"ptime"`
	UTime        string `json:"utime"`
	FileName     string `json:"file_name"`
	PickCode     string `json:"pick_code"`
	Sha1         string `json:"sha1"`
	FileID       string `json:"file_id"`
	IsMark       string `json:"is_mark"`
	OpenTime     int64  `json:"open_time"`
	FileCategory string `json:"file_category"`
	Paths        []struct {
		FileID   int64  `json:"file_id"`
		FileName string `json:"file_name"`
	} `json:"paths"`
}

type Json

type Json map[string]any

type MkdirResp

type MkdirResp struct {
	FileName string `json:"file_name"`
	FileID   string `json:"file_id"`
}

type MoveReq

type MoveReq struct {
	FileIDs string `json:"file_ids"` // 需要移动的文件(夹)ID
	ToCid   string `json:"to_cid"`   // 要移动所在的目录ID,根目录为0
}

type Option

type Option func(*Client)

func WithAccessToken

func WithAccessToken(token string) Option

func WithDebug

func WithDebug() Option

func WithOnRefreshToken

func WithOnRefreshToken(fn func(accessToken string, refreshToken string)) Option

func WithProxy

func WithProxy(proxy string) Option

func WithRefreshToken

func WithRefreshToken(token string) Option

func WithRestyClient

func WithRestyClient(rc *resty.Client) Option

func WithTrace

func WithTrace() Option

type QrCodeStatusResp

type QrCodeStatusResp struct {
	Msg     string `json:"msg"`
	Status  int    `json:"status"`
	Version string `json:"version"`
}

type RbListResp

type RbListResp struct {
	Offset int64                          `json:"offset"`  // 偏移量
	Limit  int64                          `json:"limit"`   // 分页量
	Count  string                         `json:"count"`   // 回收站文件总数
	RbPass int                            `json:"rb_pass"` // 是否设置回收站密码
	Files  map[string]RbListResp_FileInfo `json:"-"`
}

type RbListResp_FileInfo

type RbListResp_FileInfo struct {
	ID         string `json:"id"`
	FileName   string `json:"file_name"`
	Type       string `json:"type"`
	FileSize   string `json:"file_size"`
	Dtime      string `json:"dtime"`
	ThumbURL   string `json:"thumb_url"`
	Status     string `json:"status"`
	CID        string `json:"cid"`
	ParentName string `json:"parent_name"`
	PickCode   string `json:"pick_code"`
	IsV        int    `json:"isv"`
	Ico        string `json:"ico"`
	Muc        string `json:"muc"`
	DImg       string `json:"d_img"`
	SHA1       string `json:"sha1"`
}

type RbRevertResp

type RbRevertResp map[string]struct {
	State bool   `json:"state"`
	Error string `json:"error"`
	ErrNo int    `json:"errno"`
}

type RefreshTokenResp

type RefreshTokenResp CodeToTokenResp

type Resp

type Resp[T any] struct {
	State   bool   `json:"state"`
	Code    int64  `json:"code"`
	Message string `json:"message"`
	Data    T      `json:"data"`
}

type RestyOption

type RestyOption func(request *resty.Request)

func ReqWithForm

func ReqWithForm(form Form) RestyOption

func ReqWithJson

func ReqWithJson(json any) RestyOption

func ReqWithQuery

func ReqWithQuery(query Form) RestyOption

func ReqWithResp

func ReqWithResp(v any) RestyOption

func ReqWithUA

func ReqWithUA(ua string) RestyOption

type SearchFilesReq

type SearchFilesReq struct {
	SearchValue string //查找关键字
	Limit       int64  //单页记录数,默认20,offset+limit最大不超过10000
	Offset      int64  //数据显示偏移量
	FileLabel   string //支持文件标签搜索
	CID         string //目标目录cid=-1时,表示不返回列表任何内容
	GteDay      string //搜索结果匹配的开始时间;格式:2020-11-19
	LteDay      string //搜索结果匹配的结束时间;格式:2020-11-20
	FC          string //只显示文件或文件夹。1 只显示文件夹,2 只显示文件
	Type        string //一级筛选大分类,1:文档,2:图片,3:音乐,4:视频,5:压缩包,6:应用
	Suffix      string //一级筛选选其他时填写的后缀名
}

type SearchFilesResp

type SearchFilesResp struct {
	Resp[[]struct {
		FileID       string `json:"file_id"`       // 文件ID
		UserID       string `json:"user_id"`       // 用户ID
		Sha1         string `json:"sha1"`          // 文件sha1值
		FileName     string `json:"file_name"`     // 文件名称
		FileSize     string `json:"file_size"`     // 文件大小
		UserPtime    string `json:"user_ptime"`    // 上传时间
		UserUtime    string `json:"user_utime"`    // 更新时间
		PickCode     string `json:"pick_code"`     // 文件提取码
		ParentID     string `json:"parent_id"`     // 父目录ID
		AreaID       string `json:"area_id"`       // 文件的状态,aid 的别名。1 正常,7 删除(回收站),120 彻底删除
		IsPrivate    int    `json:"is_private"`    // 文件是否隐藏。0 未隐藏,1 已隐藏
		FileCategory string `json:"file_category"` // 1:文件;0;文件夹
		Ico          string `json:"ico"`           // 文件后缀名
	}]
	Count  int64 `json:"count"`  // 搜索符合条件的文件(夹)总数
	Limit  int64 `json:"limit"`  // 单页记录数
	Offset int64 `json:"offset"` // 数据显示偏移量
}

type UpdateFileReq

type UpdateFileReq struct {
	FileID  string `json:"file_id"`   // 需要更改名字的文件(夹)ID
	FileNma string `json:"file_name"` // 新的文件(夹)名字(文件夹名称限制255字节)
	Star    string `json:"star"`      // 是否星标;1:星标;0;取消星标
}

type UpdateFileResp

type UpdateFileResp struct {
	FileName string `json:"file_name"`
	Star     string `json:"star"`
}

type UploadGetTokenResp

type UploadGetTokenResp struct {
	Endpoint        string `json:"endpoint"`
	AccessKeySecret string `json:"AccessKeySecret"`
	SecurityToken   string `json:"SecurityToken"`
	Expiration      string `json:"expiration"`
	AccessKeyId     string `json:"AccessKeyId"`
}

type UploadInitReq

type UploadInitReq struct {
	FileName  string `json:"file_name"`
	FileSize  int64  `json:"file_size"`
	Target    string `json:"target"`
	FileID    string `json:"fileid"` // 文件Sha1
	PreID     string `json:"preid"`  // 文件前128k的sha1
	PickCode  string `json:"pick_code"`
	TopUpload string `json:"topupload"`
	SignKey   string `json:"sign_key"`
	SignVal   string `json:"sign_val"`
}

type UploadInitResp

type UploadInitResp struct {
	PickCode  string `json:"pick_code"`
	Status    int    `json:"status"`
	SignKey   string `json:"sign_key"`
	SignCheck string `json:"sign_check"`
	FileID    string `json:"file_id"`
	Target    string `json:"target"`
	Bucket    string `json:"bucket"`
	Object    string `json:"object"`
	Callback  json_types.StructOrArray[struct {
		Callback    string `json:"callback"`
		CallbackVar string `json:"callback_var"`
	}] `json:"callback"`
}

type UploadResumeReq

type UploadResumeReq struct {
	FileSize int64  `json:"file_size"`
	Target   string `json:"target"`
	FileID   string `json:"fileid"` // 文件Sha1
	PickCode string `json:"pick_code"`
}

type UploadResumeResp

type UploadResumeResp struct {
	PickCode string `json:"pick_code"`
	Target   string `json:"target"`
	Version  string `json:"version"`
	Bucket   string `json:"bucket"`
	Object   string `json:"object"`
	Callback json_types.StructOrArray[struct {
		Callback    string `json:"callback"`
		CallbackVar string `json:"callback_var"`
	}] `json:"callback"`
}

type UserInfoResp

type UserInfoResp struct {
	UserID      int64  `json:"user_id"`
	UserName    string `json:"user_name"`
	UserFaceS   string `json:"user_face_s"`
	UserFaceM   string `json:"user_face_m"`
	UserFaceL   string `json:"user_face_l"`
	RtSpaceInfo struct {
		AllTotal  UserInfoResp_Size `json:"all_total"`
		AllRemain UserInfoResp_Size `json:"all_remain"`
		AllUse    UserInfoResp_Size `json:"all_use"`
	} `json:"rt_space_info"`
	VipInfo struct {
		LevelName string `json:"level_name"`
		Expire    int64  `json:"expire"`
	} `json:"vip_info"`
}

type UserInfoResp_Size

type UserInfoResp_Size struct {
	Size       json.Number `json:"size"`
	SizeFormat string      `json:"size_format"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL