Skip to content

Commit 5880c8e

Browse files
authored
fix(189tv): use rate-limited upload stream in OldUpload function (#1176)
* fix(189tv): use rate-limited upload stream in OldUpload function * fix(189tv): wrap tempFile with io.NopCloser to prevent premature closure in OldUpload function * .
1 parent 14bf4ec commit 5880c8e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

drivers/189_tv/utils.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ func (y *Cloud189TV) put(ctx context.Context, url string, headers map[string]str
131131
}
132132
}
133133

134+
// 请求完成后http.Client会Close Request.Body
134135
resp, err := base.HttpClient.Do(req)
135136
if err != nil {
136137
return nil, err
@@ -333,6 +334,10 @@ func (y *Cloud189TV) OldUpload(ctx context.Context, dstDir model.Obj, file model
333334

334335
// 网盘中不存在该文件,开始上传
335336
status := GetUploadFileStatusResp{CreateUploadFileResp: *uploadInfo}
337+
// driver.RateLimitReader会尝试Close底层的reader
338+
// 但这里的tempFile是一个*os.File,Close后就没法继续读了
339+
// 所以这里用io.NopCloser包一层
340+
rateLimitedRd := driver.NewLimitedUploadStream(ctx, io.NopCloser(tempFile))
336341
for status.GetSize() < file.GetSize() && status.FileDataExists != 1 {
337342
if utils.IsCanceled(ctx) {
338343
return nil, ctx.Err()
@@ -350,7 +355,7 @@ func (y *Cloud189TV) OldUpload(ctx context.Context, dstDir model.Obj, file model
350355
header["Edrive-UploadFileId"] = fmt.Sprint(status.UploadFileId)
351356
}
352357

353-
_, err := y.put(ctx, status.FileUploadUrl, header, true, tempFile, isFamily)
358+
_, err := y.put(ctx, status.FileUploadUrl, header, true, rateLimitedRd, isFamily)
354359
if err, ok := err.(*RespErr); ok && err.Code != "InputStreamReadError" {
355360
return nil, err
356361
}

0 commit comments

Comments
 (0)