Feat: remote delete file / Fix: broken Filesystem recycle in upload request
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package request
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/HFO4/cloudreve/pkg/auth"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
@@ -104,3 +106,17 @@ func (c HTTPClient) Request(method, target string, body io.Reader, opts ...Optio
|
||||
|
||||
return Response{Err: nil, Response: resp}
|
||||
}
|
||||
|
||||
// GetResponse 检查响应并获取响应正文
|
||||
// todo 测试
|
||||
func (resp Response) GetResponse(expectStatus int) (string, error) {
|
||||
if resp.Err != nil {
|
||||
return "", resp.Err
|
||||
}
|
||||
respBody, err := ioutil.ReadAll(resp.Response.Body)
|
||||
if resp.Response.StatusCode != expectStatus {
|
||||
return string(respBody),
|
||||
fmt.Errorf("服务器返回非正常HTTP状态%d", resp.Response.StatusCode)
|
||||
}
|
||||
return string(respBody), err
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"github.com/HFO4/cloudreve/pkg/conf"
|
||||
"github.com/HFO4/cloudreve/pkg/serializer"
|
||||
"github.com/HFO4/cloudreve/pkg/util"
|
||||
"io/ioutil"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -36,20 +35,14 @@ func RemoteCallback(url string, body serializer.RemoteUploadCallback) error {
|
||||
}
|
||||
|
||||
// 检查返回HTTP状态码
|
||||
if resp.Response.StatusCode != 200 {
|
||||
util.Log().Debug("服务端返回非正常状态码:%d", resp.Response.StatusCode)
|
||||
return serializer.NewError(serializer.CodeCallbackError, "服务端返回非正常状态码", nil)
|
||||
}
|
||||
|
||||
// 检查返回API状态码
|
||||
var response serializer.Response
|
||||
rawResp, err := ioutil.ReadAll(resp.Response.Body)
|
||||
rawResp, err := resp.GetResponse(200)
|
||||
if err != nil {
|
||||
return serializer.NewError(serializer.CodeCallbackError, "无法读取响应正文", err)
|
||||
return serializer.NewError(serializer.CodeCallbackError, "服务器返回异常响应", err)
|
||||
}
|
||||
|
||||
// 解析回调服务端响应
|
||||
err = json.Unmarshal(rawResp, &response)
|
||||
var response serializer.Response
|
||||
err = json.Unmarshal([]byte(rawResp), &response)
|
||||
if err != nil {
|
||||
util.Log().Debug("无法解析回调服务端响应:%s", string(rawResp))
|
||||
return serializer.NewError(serializer.CodeCallbackError, "无法解析服务端返回的响应", err)
|
||||
Reference in New Issue
Block a user