resolveEncryptedSubscriptionURL unwraps an RVSUB1-encrypted URL paste. Returns the decrypted URL when the input is encrypted; an empty string when the input is plaintext (caller keeps the original); an error when the payload decrypts to something that isn't a single http(s) URL.
(input string)
| 1969 | // is plaintext (caller keeps the original); an error when the payload decrypts |
| 1970 | // to something that isn't a single http(s) URL. |
| 1971 | func resolveEncryptedSubscriptionURL(input string) (string, error) { |
| 1972 | if !proxy.IsEncryptedSubscription(input) { |
| 1973 | return "", nil |
| 1974 | } |
| 1975 | plain, err := proxy.DecryptSubscription(input) |
| 1976 | if err != nil { |
| 1977 | return "", fmt.Errorf("decrypting subscription URL: %w", err) |
| 1978 | } |
| 1979 | plain = strings.TrimSpace(plain) |
| 1980 | if strings.ContainsAny(plain, "\r\n") { |
| 1981 | return "", fmt.Errorf("decrypted payload contains multiple lines — paste it in the content field, not the URL field") |
| 1982 | } |
| 1983 | lower := strings.ToLower(plain) |
| 1984 | if !strings.HasPrefix(lower, "http://") && !strings.HasPrefix(lower, "https://") { |
| 1985 | return "", fmt.Errorf("decrypted payload is not a URL — paste it in the content field instead") |
| 1986 | } |
| 1987 | return plain, nil |
| 1988 | } |
| 1989 | |
| 1990 | // impioSubscriptionHost is the impio panel host whose subscription endpoint |
| 1991 | // historically required a "/json" path suffix. The panel later dropped the |
no test coverage detected