File tree Expand file tree Collapse file tree 2 files changed +34
-4
lines changed Expand file tree Collapse file tree 2 files changed +34
-4
lines changed Original file line number Diff line number Diff line change 1
1
using IXICore ;
2
- using System . Linq ;
3
2
using System . Text ;
4
3
5
4
namespace SPIXI . MiniApps
@@ -30,7 +29,7 @@ public class MiniApp
30
29
public byte [ ] signature = null ;
31
30
public Dictionary < MiniAppCapabilities , bool > capabilities = null ;
32
31
33
- public MiniApp ( string [ ] app_info )
32
+ public MiniApp ( string [ ] app_info , string ? app_url = null )
34
33
{
35
34
foreach ( string command in app_info )
36
35
{
@@ -110,6 +109,31 @@ public MiniApp(string[] app_info)
110
109
break ;
111
110
}
112
111
}
112
+
113
+ // If an app url is provided, this app metadata is likely from a remote source
114
+ if ( app_url != null )
115
+ {
116
+ // Attempt to resolve relative URLs
117
+ if ( ! contentUrl . StartsWith ( "http" , StringComparison . OrdinalIgnoreCase ) )
118
+ {
119
+ int last_index = app_url . LastIndexOf ( '/' ) ;
120
+ if ( last_index != - 1 )
121
+ {
122
+ contentUrl = app_url . Substring ( 0 , last_index + 1 ) + contentUrl ;
123
+ }
124
+
125
+ }
126
+
127
+ if ( ! image . StartsWith ( "http" , StringComparison . OrdinalIgnoreCase ) )
128
+ {
129
+ int last_index = app_url . LastIndexOf ( '/' ) ;
130
+ if ( last_index != - 1 )
131
+ {
132
+ image = app_url . Substring ( 0 , last_index + 1 ) + image ;
133
+ }
134
+ }
135
+ }
136
+
113
137
}
114
138
115
139
private Dictionary < MiniAppCapabilities , bool > parseCapabilities ( string value )
Original file line number Diff line number Diff line change @@ -104,9 +104,9 @@ public void stop()
104
104
}
105
105
106
106
string content = Encoding . UTF8 . GetString ( data ) ;
107
- string [ ] app_info = content . Split ( new [ ] { Environment . NewLine } , StringSplitOptions . None ) ;
107
+ string [ ] app_info = content . Replace ( " \r \n " , " \n " ) . Split ( ' \n ' ) ;
108
108
109
- return new MiniApp ( app_info ) ;
109
+ return new MiniApp ( app_info , url ) ;
110
110
}
111
111
catch ( HttpRequestException e )
112
112
{
@@ -138,6 +138,12 @@ public string install(MiniApp fetchedAppInfo)
138
138
{
139
139
File . WriteAllBytes ( source_app_file_path , client . GetByteArrayAsync ( fetchedAppInfo . contentUrl ) . Result ) ;
140
140
fetchedAppInfo . contentSize = new FileInfo ( source_app_file_path ) . Length ;
141
+ string file_checksum = Crypto . sha256 ( source_app_file_path ) ;
142
+
143
+ if ( file_checksum != fetchedAppInfo . checksum )
144
+ {
145
+ throw new InvalidOperationException ( $ "Checksum mismatch for downloaded app file. Expected { fetchedAppInfo . checksum } got { file_checksum } ") ;
146
+ }
141
147
}
142
148
catch ( Exception e )
143
149
{
You can’t perform that action at this time.
0 commit comments