@@ -22,9 +22,7 @@ export const handleProtocolUrl = (url: string) => {
2222 default :
2323 break ;
2424 }
25- }
26-
27-
25+ } ;
2826
2927export const handleOpenOrpheus = async ( url : string ) => {
3028 const data = parseOrpheus ( url ) ;
@@ -48,8 +46,31 @@ const parseOrpheus = (url: string): OrpheusData | undefined => {
4846 // 形如 `{"type":"song","id":"1826361712","cmd":"play"}`
4947
5048 if ( ! url . startsWith ( "orpheus://" ) ) return ;
51- const path = url . replace ( "orpheus://" , "" ) ;
52- const jsonString = atob ( path ) ;
49+ let path = url . replace ( "orpheus://" , "" ) ;
50+ // 移除末尾可能存在的斜杠
51+ if ( path . endsWith ( "/" ) ) {
52+ path = path . slice ( 0 , - 1 ) ;
53+ }
54+ // 尝试 URL 解码
55+ try {
56+ path = decodeURIComponent ( path ) ;
57+ } catch ( e ) {
58+ console . warn ( "URL Decode failed, using original path:" , e ) ;
59+ }
60+ // 处理 URL-safe Base64
61+ path = path . replace ( / - / g, "+" ) . replace ( / _ / g, "/" ) ;
62+ // 补全 Base64 填充
63+ const padding = path . length % 4 ;
64+ if ( padding > 0 ) {
65+ path += "=" . repeat ( 4 - padding ) ;
66+ }
67+ let jsonString : string ;
68+ try {
69+ jsonString = atob ( path ) ;
70+ } catch ( e ) {
71+ console . error ( "❌ Failed to decode base64:" , path , e ) ;
72+ return ;
73+ }
5374 let data : OrpheusData ;
5475 try {
5576 const json = JSON . parse ( jsonString ) ;
@@ -59,4 +80,4 @@ const parseOrpheus = (url: string): OrpheusData | undefined => {
5980 return ;
6081 }
6182 return data ;
62- }
83+ } ;
0 commit comments