feat(files/sharing): refactor sharing apis with tests
This commit is contained in:
parent
5ef94afd7a
commit
80d54f42a1
5 changed files with 67 additions and 16 deletions
|
@ -179,7 +179,14 @@ func (cl *FilesClient) AddSharing(dirpath string) (*http.Response, string, []err
|
|||
func (cl *FilesClient) DelSharing(dirpath string) (*http.Response, string, []error) {
|
||||
return cl.r.Delete(cl.url("/v1/fs/sharings")).
|
||||
AddCookie(cl.token).
|
||||
Send(fileshdr.SharingReq{SharingPath: dirpath}).
|
||||
Param(fileshdr.FilePathQuery, dirpath).
|
||||
End()
|
||||
}
|
||||
|
||||
func (cl *FilesClient) IsSharing(dirpath string) (*http.Response, string, []error) {
|
||||
return cl.r.Get(cl.url("/v1/fs/sharings/exist")).
|
||||
AddCookie(cl.token).
|
||||
Param(fileshdr.FilePathQuery, dirpath).
|
||||
End()
|
||||
}
|
||||
|
||||
|
|
|
@ -14,13 +14,12 @@ const listDirQuery = "dp";
|
|||
function translateResp(resp: Response<any>): Response<any> {
|
||||
if (resp.status === 500) {
|
||||
if (
|
||||
(resp.data == null || resp.data === "") ||
|
||||
(
|
||||
resp.data.error != null &&
|
||||
resp.data == null ||
|
||||
resp.data === "" ||
|
||||
(resp.data.error != null &&
|
||||
!resp.data.error.includes("fail to lock the file") &&
|
||||
!resp.data.error.includes("offset != uploaded") &&
|
||||
!resp.data.error.includes("i/o timeout")
|
||||
)
|
||||
!resp.data.error.includes("i/o timeout"))
|
||||
) {
|
||||
return FatalErrResp(resp.statusText);
|
||||
}
|
||||
|
@ -160,4 +159,34 @@ export class FilesClient extends BaseClient {
|
|||
},
|
||||
});
|
||||
};
|
||||
|
||||
addSharing = (dirPath: string): Promise<Response> => {
|
||||
return this.do({
|
||||
method: "post",
|
||||
url: `${this.url}/v1/fs/sharings`,
|
||||
data: {
|
||||
SharingPath: dirPath,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
deleteSharing = (dirPath: string): Promise<Response> => {
|
||||
return this.do({
|
||||
method: "delete",
|
||||
url: `${this.url}/v1/fs/sharings`,
|
||||
params: {
|
||||
[filePathQuery]: dirPath,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
isSharing = (dirPath: string): Promise<Response> => {
|
||||
return this.do({
|
||||
method: "get",
|
||||
url: `${this.url}/v1/fs/sharings/exist`,
|
||||
params: {
|
||||
[filePathQuery]: dirPath,
|
||||
},
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue