diff --git a/middleware/common_test.go b/middleware/common_test.go index 5de824a..000687b 100644 --- a/middleware/common_test.go +++ b/middleware/common_test.go @@ -76,3 +76,12 @@ func TestIsFunctionEnabled(t *testing.T) { } } + +func TestCacheControl(t *testing.T) { + a := assert.New(t) + TestFunc := CacheControl() + rec := httptest.NewRecorder() + c, _ := gin.CreateTestContext(rec) + TestFunc(c) + a.Contains(c.Writer.Header().Get("Cache-Control"), "no-cache") +} diff --git a/pkg/filesystem/archive_test.go b/pkg/filesystem/archive_test.go index be65b29..fc61520 100644 --- a/pkg/filesystem/archive_test.go +++ b/pkg/filesystem/archive_test.go @@ -1,6 +1,7 @@ package filesystem import ( + "bytes" "context" "errors" "github.com/cloudreve/Cloudreve/v3/pkg/request" @@ -58,12 +59,11 @@ func TestFileSystem_Compress(t *testing.T) { ) // 查找上传策略 asserts.NoError(cache.Set("policy_1", model.Policy{Type: "local"}, -1)) + w := &bytes.Buffer{} - zipFile, err := fs.Compress(ctx, []uint{1}, []uint{1}, true) + err := fs.Compress(ctx, w, []uint{1}, []uint{1}, true) asserts.NoError(err) - asserts.NotEmpty(zipFile) - asserts.Contains(zipFile, "archive_") - asserts.Contains(zipFile, "tests") + asserts.NotEmpty(w.Len()) } // 上下文取消 @@ -84,9 +84,10 @@ func TestFileSystem_Compress(t *testing.T) { ) asserts.NoError(cache.Set("setting_temp_path", "tests", -1)) - zipFile, err := fs.Compress(ctx, []uint{1}, []uint{1}, true) + w := &bytes.Buffer{} + err := fs.Compress(ctx, w, []uint{1}, []uint{1}, true) asserts.Error(err) - asserts.Empty(zipFile) + asserts.NotEmpty(w.Len()) } // 限制父目录 @@ -108,10 +109,11 @@ func TestFileSystem_Compress(t *testing.T) { ) asserts.NoError(cache.Set("setting_temp_path", "tests", -1)) - zipFile, err := fs.Compress(ctx, []uint{1}, []uint{1}, true) + w := &bytes.Buffer{} + err := fs.Compress(ctx, w, []uint{1}, []uint{1}, true) asserts.Error(err) asserts.Equal(ErrObjectNotExist, err) - asserts.Empty(zipFile) + asserts.Empty(w.Len()) } } diff --git a/pkg/task/compress.go b/pkg/task/compress.go index 50b21e3..5986e26 100644 --- a/pkg/task/compress.go +++ b/pkg/task/compress.go @@ -122,7 +122,7 @@ func (job *CompressTask) Do() { job.zipPath = zipFilePath zipFile.Close() - util.Log().Debug("压缩文件存放至%s,开始上传", zipFile) + util.Log().Debug("压缩文件存放至%s,开始上传", zipFilePath) job.TaskModel.SetProgress(TransferringProgress) // 上传文件 diff --git a/service/explorer/file.go b/service/explorer/file.go index 5899880..f79c2f0 100644 --- a/service/explorer/file.go +++ b/service/explorer/file.go @@ -106,7 +106,7 @@ func (service *ArchiveService) DownloadArchived(ctx context.Context, c *gin.Cont user := userRaw.(model.User) // 创建文件系统 - fs, err := filesystem.NewFileSystemFromContext(c) + fs, err := filesystem.NewFileSystem(&user) if err != nil { return serializer.Err(serializer.CodePolicyNotAllowed, err.Error(), err) } @@ -118,9 +118,6 @@ func (service *ArchiveService) DownloadArchived(ctx context.Context, c *gin.Cont return serializer.Err(404, "归档会话不存在", nil) } - // 清理打包会话 - _ = cache.Deletes([]string{service.ID, "user_" + service.ID}, "archive_") - // 开始打包 c.Header("Content-Disposition", "attachment;") c.Header("Content-Type", "application/zip") @@ -268,7 +265,7 @@ func (service *FileIDService) CreateDownloadSession(ctx context.Context, c *gin. // Download 通过签名URL的文件下载,无需登录 func (service *DownloadService) Download(ctx context.Context, c *gin.Context) serializer.Response { // 创建文件系统 - fs, err := filesystem.NewFileSystem(&user) + fs, err := filesystem.NewFileSystemFromContext(c) if err != nil { return serializer.Err(serializer.CodePolicyNotAllowed, err.Error(), err) }