Skip to content

Archives: extract and compress local files, extract downloads when they finish - #175

Merged
mateof merged 2 commits into
developfrom
feat/archives
Dec 4, 2026
Merged

mateof merged 2 commits into
developfrom
feat/archives

Conversation

@mateof

@mateof mateof commented Dec 4, 2026

Copy link
Copy Markdown
Owner

Compress and extract the server's local files, and extract archives automatically when a download from Telegram finishes (optionally deleting them).

Server

  • Extract: zip, rar (RAR5 included), 7z, tar, gz, bz2, xz, zst and multi-volume sets (.part1.rar, .r00, .7z.001, .z01). Any volume works; the first one is found in the folder. SharpCompress (MIT), sequential reading for solid 7z/rar, stream reading for compressed tars.
  • Compress: zip and tar.gz with .NET; 7z with the 7-Zip CLI when present. The Docker image installs it, INCLUDE_7ZIP=false leaves it out. Written as .partial and renamed when complete; a taken name gets " (1)".
  • Background operations, one at a time (CPU/disk bound on a NAS):
    • POST /api/v1/local/archives/extract|compress, POST .../entries (list without extracting), GET .../info.
    • /api/v1/archive-operations (list, get, cancel) and ArchiveProgress on /hubs/events, throttled like DeleteProgress.
    • A notification when each one ends.
  • Safety:
    • Entries with absolute paths or .. are not written.
    • Links are never created, and nothing is written through an existing link.
    • Every path is confined to the local root.
    • The total written is bounded by the free space minus 256 MB, which also stops compression bombs.
    • Existing files: rename (default), skip or overwrite.
    • Errors carry a code: password_required, wrong_password, not_enough_space, missing_volume, unsupported, corrupt, not_found, tool_missing.
  • Extract when the download finishes: extractArchives, deleteArchivesAfterExtract, archivePassword on POST /api/v1/transfers/downloads and /messages.
    • A single archive is extracted as soon as it is written. A multi-volume set waits until none of its volumes is still downloading in that request, then is extracted once.
    • Each archive goes into a folder named after it. Archives are deleted only when nothing failed.
    • The flag is persisted with the download, so it survives a restart. The password is not persisted: after a restart a protected archive fails with password_required and is kept.
  • Fix: POST /api/v1/transfers/downloads used targetPath as is. A relative folder ended up outside the local root, and with no folder files went to the filesystem root. It is now resolved under the local root, and "keep the channel folders" reproduces them there.
  • Capabilities: local.archives, transfers.autoExtract.

Web

  • Local files:
    • Extract... shows the archive contents (or asks for the password), with options for a new folder, existing files, password and deleting afterwards.
    • Compress... offers name, format (7z only when available) and level.
  • Download to the server (channels, shared collections, chat): an option to extract the archives when they finish, delete them and give the password. Hidden on servers without the capability.
  • Progress: cards next to the delete ones, including the automatic extractions started by the server, plus a summary in the transfers popover. Both card stacks now share one container so they do not overlap.

Checks

  • Server: build OK, 933 tests (60 new) pass. They use real 7z, AES zip, header-encrypted 7z and multi-volume fixtures made with 7-Zip, plus zip-slip, tar symlink, no-space, overwrite and auto-extract scenarios.
  • Web: typecheck and lint clean, 399 tests (30 new). Build at 245.3 KB gzip of 250 KB.
  • Dialogs and cards checked in headless Chrome at desktop and phone sizes.
  • Not run against a live server, and RAR extraction is covered only by SharpCompress itself (no RAR fixture: creating one needs WinRAR).

… when they finish

- /api/v1/local/archives: info, entries, extract and compress (zip, rar, 7z,
  tar, gz, bz2, xz, zst and multi-volume sets), run in the background one at a
  time, with progress on /api/v1/archive-operations and ArchiveProgress.
- Extraction never writes outside the destination, never creates links and
  stops before the disk is full; password, missing volume, damaged and
  unsupported archives fail with a code.
- extractArchives / deleteArchivesAfterExtract / archivePassword on the
  download endpoints: archives are extracted when their download (every
  volume of a set) finishes; the flag survives a restart, the password does not.
- POST /api/v1/transfers/downloads now puts the files under the local root
  (the target path was used as is, outside it).
- Capabilities local.archives and transfers.autoExtract; 7-Zip in the Docker
  image (INCLUDE_7ZIP) to create .7z.
…en they finish

- Local files: Extract... (with the archive contents, password, existing
  files policy, delete afterwards) and Compress... (zip, 7z, tar.gz).
- Download to the server (channels and chat): option to extract the archives
  when they finish and delete them afterwards.
- Progress cards next to the delete ones (also for the automatic extractions)
  and in the transfers popover.
@mateof
mateof merged commit 68c0456 into develop Dec 4, 2026
2 checks passed
@mateof
mateof deleted the feat/archives branch December 4, 2026 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant