feat(be/files): enable shareID for sharing APIs

This commit is contained in:
hexxa 2022-01-15 14:33:52 +08:00 committed by Hexxa
parent 772ec7992c
commit a378296980
5 changed files with 217 additions and 85 deletions

View file

@ -190,6 +190,7 @@ func (cl *FilesClient) IsSharing(dirpath string) (*http.Response, string, []erro
End()
}
// Deprecated: use ListSharingIDs intead
func (cl *FilesClient) ListSharings() (*http.Response, *fileshdr.SharingResp, []error) {
resp, body, errs := cl.r.Get(cl.url("/v1/fs/sharings")).
AddCookie(cl.token).
@ -206,6 +207,22 @@ func (cl *FilesClient) ListSharings() (*http.Response, *fileshdr.SharingResp, []
return resp, shResp, nil
}
func (cl *FilesClient) ListSharingIDs() (*http.Response, *fileshdr.SharingIDsResp, []error) {
resp, body, errs := cl.r.Get(cl.url("/v1/fs/sharings/ids")).
AddCookie(cl.token).
End()
if len(errs) > 0 {
return nil, nil, errs
}
shResp := &fileshdr.SharingIDsResp{}
err := json.Unmarshal([]byte(body), shResp)
if err != nil {
return nil, nil, append(errs, err)
}
return resp, shResp, nil
}
func (cl *FilesClient) GenerateHash(filepath string) (*http.Response, string, []error) {
return cl.r.Post(cl.url("/v1/fs/hashes/sha1")).
AddCookie(cl.token).
@ -214,3 +231,20 @@ func (cl *FilesClient) GenerateHash(filepath string) (*http.Response, string, []
}).
End()
}
func (cl *FilesClient) GetSharingDir(shareID string) (*http.Response, string, []error) {
resp, body, errs := cl.r.Get(cl.url("/v1/fs/sharings/dirs")).
AddCookie(cl.token).
Param(fileshdr.ShareIDQuery, shareID).
End()
if len(errs) > 0 {
return nil, "", errs
}
sdResp := &fileshdr.GetSharingDirResp{}
err := json.Unmarshal([]byte(body), sdResp)
if err != nil {
return nil, "", append(errs, err)
}
return resp, sdResp.SharingDir, nil
}