mirror of
https://github.com/aljazceru/notedeck.git
synced 2026-02-23 17:34:25 +01:00
Add migration logic to fix corrupted relay URLs from old format
When decks_cache.json was saved with the old format, relay URLs like "wss://wot.nostr.net" were split by the ":" delimiter into separate tokens: ["wss", "//wot.nostr.net"]. This commit adds migration logic to detect and reconstruct these corrupted URLs during parsing. Detection heuristic: - If the relay_url token is just "wss" or "ws" (without "://") - AND the next token (hashtags_str) starts with "//" - Then reconstruct the full URL as "wss://..." or "ws://..." - And pull the next token as the actual hashtags This allows existing users with corrupted decks_cache.json files to automatically have their relay URLs fixed on next app restart, without needing to manually delete the cache file.
This commit is contained in:
@@ -447,12 +447,25 @@ impl TimelineKind {
|
||||
|p| {
|
||||
p.parse_token("relay")?;
|
||||
let encoded_relay_url = p.pull_token()?;
|
||||
|
||||
// Try to URL-decode the relay URL (for new format)
|
||||
// If decoding fails, use the token as-is (backward compatibility with old format)
|
||||
let relay_url = urlencoding::decode(encoded_relay_url)
|
||||
let mut relay_url = urlencoding::decode(encoded_relay_url)
|
||||
.map(|s| s.to_string())
|
||||
.unwrap_or_else(|_| encoded_relay_url.to_string());
|
||||
let hashtags_str = p.pull_token()?;
|
||||
|
||||
let mut hashtags_str = p.pull_token()?;
|
||||
|
||||
// Migration: Fix broken relay URLs from old format where the colon delimiter
|
||||
// corrupted URLs like "wss://relay.com" into "wss" + "//relay.com"
|
||||
// If relay URL looks broken (just "wss" or "ws") and next token starts with "//",
|
||||
// reconstruct the full URL
|
||||
if (relay_url == "wss" || relay_url == "ws") && hashtags_str.starts_with("//") {
|
||||
relay_url = format!("{}:{}", relay_url, hashtags_str);
|
||||
// Pull the actual hashtags token now
|
||||
hashtags_str = p.pull_token().unwrap_or("");
|
||||
}
|
||||
|
||||
let hashtags = if hashtags_str.is_empty() {
|
||||
None
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user