11const { HLWrite } = require ( "../filesystem/hl_operations/hl_write" ) ;
22const { LLMkdir } = require ( "../filesystem/ll_operations/ll_mkdir" ) ;
3+ const { LLRead } = require ( "../filesystem/ll_operations/ll_read" ) ;
34const { NodePathSelector, NodeChildSelector, RootNodeSelector } = require ( "../filesystem/node/selectors" ) ;
5+ const { Endpoint } = require ( "../util/expressutil" ) ;
46const { buffer_to_stream } = require ( "../util/streamutil" ) ;
57const BaseService = require ( "./BaseService" ) ;
68
@@ -11,6 +13,52 @@ class AppIconService extends BaseService {
1113 sharp : require ( 'sharp' ) ,
1214 }
1315
16+ async [ '__on_install.routes' ] ( _ , { app } ) {
17+ Endpoint ( {
18+ route : '/app-icon/:app_uid/:size' ,
19+ methods : [ 'GET' ] ,
20+ handler : async ( req , res ) => {
21+ // Validate parameters
22+ let { app_uid, size } = req . params ;
23+ if ( ! ICON_SIZES . includes ( Number ( size ) ) ) {
24+ res . status ( 400 ) . send ( 'Invalid size' ) ;
25+ return ;
26+ }
27+ if ( ! app_uid . startsWith ( 'app-' ) ) {
28+ app_uid = `app-${ app_uid } ` ;
29+ }
30+
31+ // Get icon file node
32+ const dir_app_icons = await this . get_app_icons ( ) ;
33+ const node = await dir_app_icons . getChild ( `${ app_uid } -${ size } .png` ) ;
34+ await node . fetchEntry ( ) ;
35+
36+ const svc_su = this . services . get ( 'su' ) ;
37+ const ll_read = new LLRead ( ) ;
38+ const stream = await ll_read . run ( {
39+ fsNode : node ,
40+ actor : await svc_su . get_system_actor ( ) ,
41+ } ) ;
42+
43+ res . set ( 'Content-Type' , 'image/png' ) ;
44+ stream . pipe ( res ) ;
45+ } ,
46+ } ) . attach ( app ) ;
47+ }
48+
49+ async get_app_icons ( ) {
50+ if ( this . dir_app_icons ) {
51+ return this . dir_app_icons ;
52+ }
53+
54+ const svc_fs = this . services . get ( 'filesystem' ) ;
55+ const dir_app_icons = await svc_fs . node (
56+ new NodePathSelector ( '/system/app_icons' )
57+ ) ;
58+
59+ this . dir_app_icons = dir_app_icons ;
60+ }
61+
1462 async [ '__on_user.system-user-ready' ] ( ) {
1563 const svc_su = this . services . get ( 'su' ) ;
1664 const svc_fs = this . services . get ( 'filesystem' ) ;
@@ -30,6 +78,7 @@ class AppIconService extends BaseService {
3078 actor : await svc_su . get_system_actor ( ) ,
3179 } ) ;
3280 }
81+ this . dir_app_icons = dir_app_icons ;
3382
3483 // Listen for new app icons
3584 const svc_event = this . services . get ( 'event' ) ;
0 commit comments