Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1385,8 +1385,12 @@ docker/ # Docker image of `ketch server` (Dockerfile, entrypoint, compose
may save at (`DestinationGuard.checkMove`, 403 `path_rejected`). A copy between volumes whose
original cannot be deleted afterwards still counts as moved, with a warning, and a moved task
removed with its files before it runs again takes them as its own first (`v1Store` and
`v2Store` with `adopt`). The
apps have no control for it yet
`v2Store` with `adopt`). In
the apps, a finished torrent's row menu offers Move files… (`RowAction.MoveFiles`,
`RowCommands.moveFiles`, `TaskCommand.MoveFiles`) on this device where the system's folder
dialog names a file path (`FilePicker.picksFilePaths`: not Android's document trees, nor the
web): it asks for a folder, starting where the torrent is saved, and moves the files there.
Remote devices have no control for it yet
- Editing trackers: `TorrentController.editTrackers(taskId, TorrentTrackerEdit(add, remove))`
(REST `PUT /api/torrents/{id}/trackers`, answering the list; capability `tracker-edit`) removes
the trackers at the endpoints `remove` names and appends each announce URL of `add` as a tier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ private class AndroidFilePicker(
private val torrentLauncher: ManagedActivityResultLauncher<Array<String>, List<Uri>>,
) : FilePicker {
override val canPickFolder: Boolean = true
override val picksFilePaths: Boolean = false

override suspend fun pickFolder(initialFolder: String?): String? {
val initial = initialFolder?.takeIf { it.startsWith(CONTENT_SCHEME) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@
<string name="downloads_failed_files">Dateien für %1$s konnten auf %2$s nicht geändert werden</string>
<string name="downloads_failed_seeding">Seeden für %1$s konnte auf %2$s nicht geändert werden</string>
<string name="downloads_failed_check_files">Dateien von %1$s konnten auf %2$s nicht geprüft werden</string>
<string name="downloads_failed_move_files">Dateien von %1$s konnten auf %2$s nicht verschoben werden</string>

<plurals name="downloads_batch_paused">
<item quantity="one">%1$d Download pausiert</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
<string name="action_row_download_all_files">Alle Dateien herunterladen</string>
<string name="action_row_stop_seeding">Seeden beenden</string>
<string name="action_row_check_files">Dateien prüfen</string>
<string name="action_row_move_files">Dateien verschieben…</string>
<string name="action_row_seed">Seeden</string>
<plurals name="batch_pause">
<item quantity="one">%1$d Download pausieren</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@
<string name="downloads_failed_files">Error al cambiar los archivos de %1$s en %2$s</string>
<string name="downloads_failed_seeding">Error al cambiar el sembrado de %1$s en %2$s</string>
<string name="downloads_failed_check_files">Error al comprobar los archivos de %1$s en %2$s</string>
<string name="downloads_failed_move_files">Error al mover los archivos de %1$s en %2$s</string>

<plurals name="downloads_batch_paused">
<item quantity="one">Se pausó %1$d descarga</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
<string name="action_row_download_all_files">Descargar todos los archivos</string>
<string name="action_row_stop_seeding">Dejar de sembrar</string>
<string name="action_row_check_files">Comprobar archivos</string>
<string name="action_row_move_files">Mover archivos…</string>
<string name="action_row_seed">Sembrar</string>
<plurals name="batch_pause">
<item quantity="one">Pausar %1$d descarga</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@
<string name="downloads_failed_files">Impossible de modifier les fichiers de %1$s sur %2$s</string>
<string name="downloads_failed_seeding">Impossible de modifier le partage de %1$s sur %2$s</string>
<string name="downloads_failed_check_files">Impossible de vérifier les fichiers de %1$s sur %2$s</string>
<string name="downloads_failed_move_files">Impossible de déplacer les fichiers de %1$s sur %2$s</string>

<plurals name="downloads_batch_paused">
<item quantity="one">%1$d téléchargement mis en pause</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
<string name="action_row_download_all_files">Télécharger tous les fichiers</string>
<string name="action_row_stop_seeding">Arrêter le partage</string>
<string name="action_row_check_files">Vérifier les fichiers</string>
<string name="action_row_move_files">Déplacer les fichiers…</string>
<string name="action_row_seed">Partager</string>
<plurals name="batch_pause">
<item quantity="one">Mettre en pause %1$d téléchargement</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@
<string name="downloads_failed_files">%2$sで%1$sのファイルを変更できませんでした</string>
<string name="downloads_failed_seeding">%2$sで%1$sのシードを変更できませんでした</string>
<string name="downloads_failed_check_files">%2$sで%1$sのファイルを確認できませんでした</string>
<string name="downloads_failed_move_files">%2$sで%1$sのファイルを移動できませんでした</string>

<plurals name="downloads_batch_paused">
<item quantity="other">%1$d件のダウンロードを一時停止しました</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
<string name="action_row_download_all_files">すべてのファイルをダウンロード</string>
<string name="action_row_stop_seeding">シードを停止</string>
<string name="action_row_check_files">ファイルを確認</string>
<string name="action_row_move_files">ファイルを移動…</string>
<string name="action_row_seed">シード</string>
<plurals name="batch_pause">
<item quantity="other">%1$d件のダウンロードを一時停止</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@
<string name="downloads_failed_files">%2$s에서 %1$s의 파일을 변경할 수 없음</string>
<string name="downloads_failed_seeding">%2$s에서 %1$s의 시딩을 변경할 수 없음</string>
<string name="downloads_failed_check_files">%2$s에서 %1$s의 파일을 검사할 수 없음</string>
<string name="downloads_failed_move_files">%2$s에서 %1$s의 파일을 이동할 수 없음</string>

<plurals name="downloads_batch_paused">
<item quantity="other">다운로드 %1$d개 일시정지됨</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
<string name="action_row_download_all_files">모든 파일 다운로드</string>
<string name="action_row_stop_seeding">시딩 중지</string>
<string name="action_row_check_files">파일 검사</string>
<string name="action_row_move_files">파일 이동…</string>
<string name="action_row_seed">시드</string>
<plurals name="batch_pause">
<item quantity="other">다운로드 %1$d개 일시정지</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@
<string name="downloads_failed_files">Não foi possível alterar os arquivos de %1$s (%2$s)</string>
<string name="downloads_failed_seeding">Não foi possível alterar o semeio de %1$s (%2$s)</string>
<string name="downloads_failed_check_files">Não foi possível verificar os arquivos de %1$s (%2$s)</string>
<string name="downloads_failed_move_files">Não foi possível mover os arquivos de %1$s (%2$s)</string>

<plurals name="downloads_batch_paused">
<item quantity="one">%1$d download pausado</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
<string name="action_row_download_all_files">Baixar todos os arquivos</string>
<string name="action_row_stop_seeding">Parar de semear</string>
<string name="action_row_check_files">Verificar arquivos</string>
<string name="action_row_move_files">Mover arquivos…</string>
<string name="action_row_seed">Semear</string>
<plurals name="batch_pause">
<item quantity="one">Pausar %1$d download</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@
<string name="downloads_failed_files">Не удалось изменить файлы %1$s на устройстве «%2$s»</string>
<string name="downloads_failed_seeding">Не удалось изменить раздачу %1$s на устройстве «%2$s»</string>
<string name="downloads_failed_check_files">Не удалось проверить файлы %1$s на устройстве «%2$s»</string>
<string name="downloads_failed_move_files">Не удалось переместить файлы %1$s на устройстве «%2$s»</string>

<plurals name="downloads_batch_paused">
<item quantity="one">Приостановлена %1$d загрузка</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
<string name="action_row_download_all_files">Скачать все файлы</string>
<string name="action_row_stop_seeding">Остановить раздачу</string>
<string name="action_row_check_files">Проверить файлы</string>
<string name="action_row_move_files">Переместить файлы…</string>
<string name="action_row_seed">Раздавать</string>
<plurals name="batch_pause">
<item quantity="one">Приостановить %1$d загрузку</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@
<string name="downloads_failed_files">無法在 %2$s 上變更 %1$s 的檔案</string>
<string name="downloads_failed_seeding">無法在 %2$s 上變更 %1$s 的做種</string>
<string name="downloads_failed_check_files">無法在 %2$s 上檢查 %1$s 的檔案</string>
<string name="downloads_failed_move_files">無法在 %2$s 上移動 %1$s 的檔案</string>

<plurals name="downloads_batch_paused">
<item quantity="other">已暫停 %1$d 個下載項目</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
<string name="action_row_download_all_files">下載全部檔案</string>
<string name="action_row_stop_seeding">停止做種</string>
<string name="action_row_check_files">檢查檔案</string>
<string name="action_row_move_files">移動檔案…</string>
<string name="action_row_seed">做種</string>
<plurals name="batch_pause">
<item quantity="other">暫停 %1$d 個下載項目</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@
<string name="downloads_failed_files">无法在 %2$s 上更改 %1$s 的文件</string>
<string name="downloads_failed_seeding">无法在 %2$s 上更改 %1$s 的做种</string>
<string name="downloads_failed_check_files">无法在 %2$s 上校验 %1$s 的文件</string>
<string name="downloads_failed_move_files">无法在 %2$s 上移动 %1$s 的文件</string>

<plurals name="downloads_batch_paused">
<item quantity="other">已暂停 %1$d 个下载</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
<string name="action_row_download_all_files">下载全部文件</string>
<string name="action_row_stop_seeding">停止做种</string>
<string name="action_row_check_files">校验文件</string>
<string name="action_row_move_files">移动文件…</string>
<string name="action_row_seed">做种</string>
<plurals name="batch_pause">
<item quantity="other">暂停 %1$d 个下载</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@
<string name="downloads_failed_files">Couldn't change files for %1$s on %2$s</string>
<string name="downloads_failed_seeding">Couldn't change seeding for %1$s on %2$s</string>
<string name="downloads_failed_check_files">Couldn't check the files of %1$s on %2$s</string>
<string name="downloads_failed_move_files">Couldn't move the files of %1$s on %2$s</string>

<!-- What a command did to several downloads, parts joined by " · ". %1$d is how many. -->
<plurals name="downloads_batch_paused">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
<string name="action_row_stop_seeding">Stop seeding</string>
<!-- Checks a finished torrent's files against its hashes again and downloads what is missing. -->
<string name="action_row_check_files">Check files</string>
<string name="action_row_move_files">Move files…</string>
<string name="action_row_seed">Seed</string>
<!-- Menu labels of actions on several selected downloads. %1$d is how many. -->
<plurals name="batch_pause">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ interface FilePicker {
/** Whether [pickFolder] can choose a folder here; the web cannot. */
val canPickFolder: Boolean

/**
* Whether [pickFolder] answers a file path, which a download's files can be moved into, rather
* than a document tree, as on Android.
*/
val picksFilePaths: Boolean get() = true

/**
* Asks the user for a folder to save downloads in.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.linroid.ketch.app.util.isTorrent
import com.linroid.ketch.app.util.toCopy
import ketch.app.shared.generated.resources.Res
import ketch.app.shared.generated.resources.action_row_check_files
import ketch.app.shared.generated.resources.action_row_move_files
import ketch.app.shared.generated.resources.action_row_choose_files
import ketch.app.shared.generated.resources.action_row_connections
import ketch.app.shared.generated.resources.action_row_copy_details
Expand Down Expand Up @@ -149,6 +150,9 @@ sealed class RowAction(val label: UiText, val destructive: Boolean = false) {
*/
data object CheckFiles : RowAction(Res.string.action_row_check_files.text())

/** Moves a finished torrent's files into a folder chosen with the system's folder dialog. */
data object MoveFiles : RowAction(Res.string.action_row_move_files.text())

/** Cancels the task after confirmation; its progress cannot be resumed. */
data object StopAndDiscard :
RowAction(Res.string.action_row_stop_and_discard.text(), destructive = true)
Expand Down Expand Up @@ -323,6 +327,7 @@ private fun completed(
// comes with its torrent snapshot, which the inspector follows and rows do not.
RowAction.StopSeeding.takeIf { seeding },
RowAction.CheckFiles.takeIf { torrent },
RowAction.MoveFiles.takeIf { torrent && local },
RowAction.CopyLink,
RowAction.CopyPath,
RowAction.SendTo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.linroid.ketch.app.i18n.verbatim
import com.linroid.ketch.app.instance.InstanceEntry
import com.linroid.ketch.app.platform.FileActions
import com.linroid.ketch.app.platform.rememberFileActions
import com.linroid.ketch.app.platform.rememberFilePicker
import com.linroid.ketch.app.platform.rememberSystemClipboard
import com.linroid.ketch.app.state.AppState
import com.linroid.ketch.app.state.LocalAppState
Expand Down Expand Up @@ -570,8 +571,9 @@ internal fun rememberRowCommands(state: AppState): RowCommands {
val clipboard = rememberSystemClipboard()
val uriHandler = LocalUriHandler.current
val scope = rememberCoroutineScope()
return remember(state, files, clipboard, uriHandler, scope) {
RowCommands(state, files, clipboard, scope, uriHandler::openUri)
val picker = rememberFilePicker()
return remember(state, files, clipboard, uriHandler, scope, picker) {
RowCommands(state, files, clipboard, scope, picker, uriHandler::openUri)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ internal val RowAction.icon: KetchIcon
RowAction.StopSeeding -> KetchIcon.Stop
RowAction.Seed -> KetchIcon.Send
RowAction.CheckFiles -> KetchIcon.CheckCircle
RowAction.MoveFiles -> KetchIcon.Folder
RowAction.StopAndDiscard -> KetchIcon.Stop
RowAction.Remove -> KetchIcon.Trash
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ import com.linroid.ketch.app.i18n.load
import com.linroid.ketch.app.i18n.text
import com.linroid.ketch.app.i18n.verbatim
import com.linroid.ketch.app.platform.FileActions
import com.linroid.ketch.app.platform.FilePicker
import com.linroid.ketch.app.platform.SystemClipboard
import com.linroid.ketch.app.state.AppState
import com.linroid.ketch.app.state.DiscoverRequest
import com.linroid.ketch.app.state.IntakeRequest
import com.linroid.ketch.app.state.IntakeSeed
import com.linroid.ketch.app.state.LOCAL_DEVICE_ID
import com.linroid.ketch.app.state.RowAction
import com.linroid.ketch.app.state.TaskKey
import com.linroid.ketch.app.state.TaskRow
import com.linroid.ketch.app.state.catchingUnlessCancelled
import com.linroid.ketch.app.state.isDocumentTree
import com.linroid.ketch.app.util.errorDetails
import com.linroid.ketch.app.util.referer
import com.linroid.ketch.torrent.api.TorrentCommandContext
Expand Down Expand Up @@ -51,6 +54,7 @@ import ketch.app.shared.generated.resources.downloads_failed_resume
import ketch.app.shared.generated.resources.downloads_failed_retry
import ketch.app.shared.generated.resources.downloads_failed_reveal
import ketch.app.shared.generated.resources.downloads_failed_check_files
import ketch.app.shared.generated.resources.downloads_failed_move_files
import ketch.app.shared.generated.resources.downloads_failed_seeding
import ketch.app.shared.generated.resources.downloads_failed_speed_limit
import ketch.app.shared.generated.resources.downloads_open_source_failed
Expand Down Expand Up @@ -90,7 +94,10 @@ internal enum class TaskCommand(val key: String, private val failure: StringReso
Seed("seed", Res.string.downloads_failed_seeding),

/** Checks a finished torrent's files again. */
CheckFiles("check-files", Res.string.downloads_failed_check_files);
CheckFiles("check-files", Res.string.downloads_failed_check_files),

/** Moves a torrent's files into another folder. */
MoveFiles("move-files", Res.string.downloads_failed_move_files);

/**
* The failure of this command on [what], a task's name or a number of downloads, on [device]:
Expand Down Expand Up @@ -143,13 +150,15 @@ internal enum class CopiedText(
* @property files opens and reveals downloaded files; `null` where they are out of reach.
* @property clipboard receives copied links, paths and error details; `null` where there is none.
* @property scope runs clipboard writes.
* @property picker chooses the folder a torrent's files move into; `null` where there is none.
* @param openUri opens a web page, such as the page a link was captured from.
*/
internal class RowCommands(
val state: AppState,
val files: FileActions?,
val clipboard: SystemClipboard?,
val scope: CoroutineScope,
val picker: FilePicker? = null,
private val openUri: (String) -> Unit,
) {
/** Whether [action] can run on [row] here; files need [files] and copies a clipboard. */
Expand All @@ -162,6 +171,10 @@ internal class RowCommands(
RowAction.FindAnotherSource -> row.device.capabilities.canDiscover
RowAction.StopSeeding, RowAction.Seed, RowAction.CheckFiles ->
state.torrentControllerOf(row.key.deviceId) != null
// On this device only, where the system's dialog names a folder its files can move into.
RowAction.MoveFiles -> picker?.canPickFolder == true && picker.picksFilePaths &&
row.key.deviceId == LOCAL_DEVICE_ID && row.outputFile?.let(::isDocumentTree) == false &&
state.torrentControllerOf(row.key.deviceId) != null
else -> true
}

Expand Down Expand Up @@ -211,6 +224,7 @@ internal class RowCommands(
RowAction.StopSeeding -> setSeeding(row, seeding = false)
RowAction.Seed -> setSeeding(row, seeding = true)
RowAction.CheckFiles -> checkFiles(row)
RowAction.MoveFiles -> moveFiles(row)
RowAction.EditLink,
RowAction.RetryWithOptions,
RowAction.EnterCredentials -> state.openIntake(retryRequest(row))
Expand Down Expand Up @@ -274,6 +288,24 @@ internal class RowCommands(
}
}

/**
* Asks for a folder, starting where [row]'s torrent is saved, and moves its files there
* through its device's [TorrentController]; nothing happens when no folder is chosen.
*/
fun moveFiles(row: TaskRow): Job {
val app = state
val picker = picker
return scope.launch {
val saved = row.outputFile?.let(::folderHolding)
val folder = picker?.pickFolder(saved) ?: return@launch
command(row, TaskCommand.MoveFiles) {
val controller = app.torrentControllerOf(row.key.deviceId)
?: throw UnsupportedOperationException()
controller.relocate(taskId, folder)
}
}
}

private fun command(
row: TaskRow,
command: TaskCommand,
Expand Down Expand Up @@ -373,6 +405,13 @@ private val WEB_SCHEMES = listOf("https://", "http://")
private fun folderPath(row: TaskRow): String? =
row.outputFile ?: row.request.destination?.takeUnless(Destination::isName)?.value

/** The folder holding [path], with either separator; `null` when it names none. */
private fun folderHolding(path: String): String? {
val trimmed = path.trimEnd('/', '\\')
return trimmed.take(trimmed.lastIndexOfAny(charArrayOf('/', '\\')).coerceAtLeast(0))
.ifEmpty { null }
}

/** A new idempotency key for a [TorrentController] command. */
@OptIn(ExperimentalUuidApi::class)
internal fun newCommandKey(): String = Uuid.random().toString()
Loading
Loading