@@ -161,19 +161,63 @@ pub async fn get_app_addons_endpoint(
161
161
return Ok ( HttpResponse :: NotFound ( ) . json ( error_response) ) ;
162
162
}
163
163
164
- let mut all_addons: Vec < GetAppAddonsSingleResponseData > = state_read
165
- . pkgs_cache
166
- . get ( & request_payload. base_dir )
167
- . unwrap ( )
168
- . iter ( )
169
- . map ( convert_pkg_info_to_addon)
170
- . collect ( ) ;
171
-
172
- all_addons. retain ( |addon| addon. addon_type != PkgType :: App . to_string ( ) ) ;
173
-
174
- // Filter by addon_type if provided.
175
- if let Some ( addon_type) = & request_payload. addon_type {
176
- all_addons. retain ( |addon| & addon. addon_type == addon_type) ;
164
+ let mut all_addons: Vec < GetAppAddonsSingleResponseData > = Vec :: new ( ) ;
165
+
166
+ // Get the BaseDirPkgInfo and extract only the requested packages from it.
167
+ if let Some ( base_dir_pkg_info) =
168
+ state_read. pkgs_cache . get ( & request_payload. base_dir )
169
+ {
170
+ let addon_type_filter = request_payload. addon_type . as_deref ( ) ;
171
+
172
+ // Only process these packages if no addon_type filter is specified or
173
+ // if it matches "extension"
174
+ if addon_type_filter. is_none ( ) || addon_type_filter == Some ( "extension" )
175
+ {
176
+ // Extract extension packages if they exist.
177
+ if let Some ( extensions) = & base_dir_pkg_info. extension_pkg_info {
178
+ for ext in extensions {
179
+ all_addons. push ( convert_pkg_info_to_addon ( ext) ) ;
180
+ }
181
+ }
182
+ }
183
+
184
+ // Only process these packages if no addon_type filter is specified or
185
+ // if it matches "protocol"
186
+ if addon_type_filter. is_none ( ) || addon_type_filter == Some ( "protocol" )
187
+ {
188
+ // Extract protocol packages if they exist.
189
+ if let Some ( protocols) = & base_dir_pkg_info. protocol_pkg_info {
190
+ for protocol in protocols {
191
+ all_addons. push ( convert_pkg_info_to_addon ( protocol) ) ;
192
+ }
193
+ }
194
+ }
195
+
196
+ // Only process these packages if no addon_type filter is specified or
197
+ // if it matches "addon_loader".
198
+ if addon_type_filter. is_none ( )
199
+ || addon_type_filter == Some ( "addon_loader" )
200
+ {
201
+ // Extract addon loader packages if they exist.
202
+ if let Some ( addon_loaders) =
203
+ & base_dir_pkg_info. addon_loader_pkg_info
204
+ {
205
+ for loader in addon_loaders {
206
+ all_addons. push ( convert_pkg_info_to_addon ( loader) ) ;
207
+ }
208
+ }
209
+ }
210
+
211
+ // Only process these packages if no addon_type filter is specified or
212
+ // if it matches "system".
213
+ if addon_type_filter. is_none ( ) || addon_type_filter == Some ( "system" ) {
214
+ // Extract system packages if they exist.
215
+ if let Some ( systems) = & base_dir_pkg_info. system_pkg_info {
216
+ for system in systems {
217
+ all_addons. push ( convert_pkg_info_to_addon ( system) ) ;
218
+ }
219
+ }
220
+ }
177
221
}
178
222
179
223
// Filter by addon_name if provided.
0 commit comments