Skip to content

Conversation

@totza2010
Copy link

@totza2010 totza2010 commented Jan 27, 2026

Description / 描述

This PR introduces critical improvements to the Teldrive driver for better reliability and feature parity with Teldrive's capabilities:

  1. Concurrent Pagination Support: Implemented a loop mechanism in the List function to fetch files in batches of 500 per page (following the [Teldrive API Documentation](https://teldrive-docs.pages.dev/docs/api#tag/files/get/files)). It uses errgroup to fetch multiple pages concurrently, ensuring that directories containing thousands of items are listed completely and efficiently.
  2. Random Chunk Naming: Added support for the RandomChunkName configuration. When enabled, each uploaded file chunk is assigned a random MD5 hash as its name instead of the default part naming scheme. This aligns with Teldrive's native support for randomized part names to prevent potential naming pattern conflicts.

Motivation and Context / 背景

  • Incomplete Listing: Previously, the driver could only see the first page of results, meaning users couldn't see more than 1000 files in a single folder.
  • Feature Gap: Teldrive supports randomized chunk names for better anonymity and avoiding filename collisions, which was missing in our driver implementation.

How Has This Been Tested? / 测试

  • Large Directory Test: Tested with a folder containing 6,000+ items. Verified that the pagination logic correctly fetches all items and they are all visible in the file manager.
  • Upload Verification: Conducted uploads with random_chunk_name enabled. Confirmed on the server-side that the uploaded parts are named using random hashes as expected.
  • Performance: Verified that concurrent page fetching significantly reduces wait time for large directory listings.

Checklist / 检查清单

  • I have read the CONTRIBUTING document.
    我已阅读 CONTRIBUTING 文档。
  • I have formatted my code with go fmt or prettier.
    我已使用 go fmtprettier 格式化提交的代码。
  • I have added appropriate labels to this PR (or mentioned needed labels in the description if lacking permissions).
    我已为此 PR 添加了适当的标签(如无权限或需要的标签不存在,请在描述中说明,管理员将后续处理)。
  • I have requested review from relevant code authors using the "Request review" feature when applicable.
    我已在适当情况下使用"Request review"功能请求相关代码作者进行审查。
  • I have updated the repository accordingly (If it’s needed).
    我已相应更新了相关仓库(若适用)。

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances the Teldrive driver’s listing and upload behavior to better match Teldrive’s API capabilities and large-folder workloads.

Changes:

  • Adds paginated, concurrent listing in List, fetching all pages from /api/files with a limit of 500 items per page using errgroup.
  • Introduces RandomChunkName configuration and wiring so single- and multi-part uploads can use random MD5-based part names instead of deterministic *.part.XXX.
  • Adjusts upload behavior, including progress reporting and retry configuration, and increases the default chunk_size to 500 MiB in the driver’s metadata.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
drivers/teldrive/driver.go Implements paginated, concurrent listing in List and propagates maxRetried into the single-upload path in Put.
drivers/teldrive/upload.go Adds random chunk naming, threads context.Context through low-level upload requests, tweaks single-upload chunking and progress semantics, and aligns single- and multi-part upload behavior.
drivers/teldrive/meta.go Updates Teldrive driver metadata to increase the chunk_size default to 500 MiB and introduces the random_chunk_name boolean option.
Comments suppressed due to low confidence (1)

drivers/teldrive/upload.go:371

  • In uploadSingleChunk, the same task.reader is reused across retries without ever seeking back to the start of the chunk, so after a failed attempt subsequent retries will read from the end of the section and effectively send an empty body. This differs from doSingleUpload, which explicitly seeks its section reader to offset 0 before each retry. To ensure retries resend the full chunk data, reset task.reader (e.g., Seek(0, io.SeekStart)) before constructing the request body for each attempt.
		err := d.singleUploadRequest(ctx, fileId, func(req *resty.Request) {
			uploadParams := map[string]string{
				"partName": partName,
				"partNo":   strconv.Itoa(task.chunkIdx),
				"fileName": task.fileName,
			}
			req.SetQueryParams(uploadParams)
			req.SetBody(driver.NewLimitedUploadStream(ctx, task.reader))
			req.SetHeader("Content-Length", strconv.Itoa(int(task.chunkSize)))
		}, filePart)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@totza2010
Copy link
Author

What should I do next?

@xrgzs xrgzs added bug Module: Driver Driver-Related Issue/PR labels Jan 28, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Chaloemchai <chaloemchai.yy@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Module: Driver Driver-Related Issue/PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants