-
Notifications
You must be signed in to change notification settings - Fork 471
feat(pikpak): 引入 PikPak 云端离线下载作为 BT 备选方案 #2978
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
StageGuard
merged 14 commits into
open-ani:main
from
NihilDigit:feat/pikpak-cloud-offline
May 6, 2026
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
8580fb6
feat(pikpak): 引入 PikPak 云端离线下载作为 BT 备选方案
NihilDigit 9deadc8
fix(pikpak): 保留 password 作为 refresh token 失效时的恢复路径
NihilDigit b45c3ee
fix(pikpak): 修复 #2978 引入的 CI 回归
NihilDigit 84d912d
fix(pikpak): 让 BT 自动缓存按 resolve 结果而非 media kind 判断
NihilDigit fad45a3
fix(pikpak): rethrow CancellationException in testPikPakLogin
claude 4b6654d
feat(utils-io): add AES-CTR obscure utility for credential persistence
NihilDigit 8e81f9e
feat(pikpak): obscure persisted PikPakConfig credentials
NihilDigit 4b9ad9f
Merge remote-tracking branch 'upstream/main' into feat/pikpak-cloud-o…
NihilDigit 689a3e3
fix(utils-io): import kotlinx.cinterop.addressOf in Obscure.native.kt
claude 698d82a
fix(settings): exclude PikPak credentials from settings backup
claude f6b2ec2
Merge remote-tracking branch 'upstream/main' into claude/sync-upstrea…
claude c9f5ff2
Merge pull request #9 from NihilDigit/claude/sync-upstream-feat-soyKT
NihilDigit 0ac8d1d
Mask pikpak config.
StageGuard f8e663e
Merge branch 'main' into fork/NihilDigit/feat/pikpak-cloud-offline
StageGuard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
app/shared/app-data/src/commonMain/kotlin/data/models/preference/PikPakConfig.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| /* | ||
| * Copyright (C) 2024-2026 OpenAni and contributors. | ||
| * | ||
| * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. | ||
| * Use of this source code is governed by the GNU AGPLv3 license, which can be found at the following link. | ||
| * | ||
| * https://github.com/open-ani/ani/blob/main/LICENSE | ||
| */ | ||
|
|
||
| package me.him188.ani.app.data.models.preference | ||
|
|
||
| import kotlinx.serialization.KSerializer | ||
| import kotlinx.serialization.Serializable | ||
| import kotlinx.serialization.descriptors.PrimitiveKind | ||
| import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor | ||
| import kotlinx.serialization.descriptors.SerialDescriptor | ||
| import kotlinx.serialization.encoding.Decoder | ||
| import kotlinx.serialization.encoding.Encoder | ||
| import me.him188.ani.app.data.models.preference.PikPakConfig.Companion.SLOT_QUEUE_MAX_NUMERIC | ||
| import me.him188.ani.app.data.models.preference.PikPakConfig.Companion.SLOT_QUEUE_UNLIMITED | ||
| import me.him188.ani.utils.io.obscure | ||
| import me.him188.ani.utils.io.tryReveal | ||
|
|
||
| /** | ||
| * User-configurable settings for the PikPak offline-download backend. | ||
| * | ||
| * The engine runs a server-side slot cache: completed offline tasks stay in a | ||
| * well-known working folder on the user's PikPak drive, keyed by source | ||
| * bucket, so replays of the same magnet are served straight from the cache. | ||
| * Old buckets are evicted to honor [slotQueueLength] — they are *not* deleted | ||
| * immediately after each resolve. See `PikPakOfflineDownloadEngine` for the | ||
| * full eviction policy. | ||
| * | ||
| * [refreshToken] is written by the engine after a successful signin/refresh | ||
| * (not user-editable). It lets the next app launch skip the rate-limited | ||
| * `/v1/auth/signin` endpoint and go straight to a cheap refresh. | ||
| * | ||
| * [password] is accepted from the settings UI to bootstrap the first signin | ||
| * and stays on disk so the engine can silently re-signin if the stored | ||
| * refresh token gets revoked server-side (Test / playback would otherwise | ||
| * fail until the user re-typed the password). To keep credentials out of | ||
| * casual reads of the on-disk JSON, both [password] and [refreshToken] are | ||
| * persisted via [ObscuredStringSerializer] — AES-CTR with a hardcoded key, | ||
| * the same approach `rclone obscure` takes. This blocks eyedropping; it is | ||
| * not real encryption (the key is in the binary). The settings UI also | ||
| * never echoes [password] back. | ||
| */ | ||
| @Serializable | ||
| data class PikPakConfig( | ||
| val enabled: Boolean = false, | ||
| val username: String = "", | ||
| @Serializable(with = ObscuredStringSerializer::class) | ||
| val password: String = "", | ||
| @Serializable(with = ObscuredStringSerializer::class) | ||
| val refreshToken: String = "", | ||
| /** | ||
| * How many distinct source buckets the engine keeps cached in its | ||
| * working folder ("Animeko-Playing"). Real numeric values 1..13 are | ||
| * bucket caps; the UI also offers a final "unlimited" stop (stored as | ||
| * [SLOT_QUEUE_UNLIMITED]) that disables eviction entirely. | ||
| */ | ||
| val slotQueueLength: Int = 1, | ||
| ) { | ||
| override fun toString(): String { | ||
| return "PikPakConfig(enabled=$enabled, username=$username, password.hash=${password.hashCode()}, " + | ||
| "refreshToken.hash=${refreshToken.let { if (it.isNotEmpty()) it.hashCode() else "" }}, " + | ||
| "slotQueueLength=$slotQueueLength)" | ||
| } | ||
|
|
||
| companion object { | ||
| val Default = PikPakConfig() | ||
|
|
||
| /** Last numeric step on the slider. */ | ||
| const val SLOT_QUEUE_MAX_NUMERIC: Int = 13 | ||
|
|
||
| /** | ||
| * One step past [SLOT_QUEUE_MAX_NUMERIC]: the dedicated "no eviction" | ||
| * stop. Any value ≥ this is treated as unlimited by the engine. | ||
| */ | ||
| const val SLOT_QUEUE_UNLIMITED: Int = SLOT_QUEUE_MAX_NUMERIC + 1 | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Encodes [String] values via [obscure] / [tryReveal] so the JSON written to | ||
| * DataStore contains an `ob1:`-tagged AES-CTR payload instead of plaintext. | ||
| * | ||
| * Decoding falls back to treating the raw value as plaintext when the magic | ||
| * prefix is absent — that path covers the migration from PR #2978's V2, which | ||
| * persisted [PikPakConfig.password] and [PikPakConfig.refreshToken] in the | ||
| * clear. The next [SerializablePreference.update] then writes the obscured | ||
| * form back automatically. | ||
| */ | ||
| internal object ObscuredStringSerializer : KSerializer<String> { | ||
| override val descriptor: SerialDescriptor = | ||
| PrimitiveSerialDescriptor("ObscuredString", PrimitiveKind.STRING) | ||
|
|
||
| override fun serialize(encoder: Encoder, value: String) { | ||
| encoder.encodeString(obscure(value)) | ||
| } | ||
|
|
||
| override fun deserialize(decoder: Decoder): String { | ||
| val raw = decoder.decodeString() | ||
| return tryReveal(raw) ?: raw | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.