Skip to content

Commit f032faa

Browse files
committed
dev: add fallback for missing icons
1 parent 7ec6621 commit f032faa

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/backend/src/services/AppIconService.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ const { HLWrite } = require("../filesystem/hl_operations/hl_write");
22
const { LLMkdir } = require("../filesystem/ll_operations/ll_mkdir");
33
const { LLRead } = require("../filesystem/ll_operations/ll_read");
44
const { NodePathSelector } = require("../filesystem/node/selectors");
5+
const { get_app } = require("../helpers");
56
const { Endpoint } = require("../util/expressutil");
67
const { buffer_to_stream } = require("../util/streamutil");
78
const BaseService = require("./BaseService");
89

910
const ICON_SIZES = [16,32,64,128,256,512];
1011

12+
const DEFAULT_APP_ICON = require('./default-app-icon.js');
13+
1114
/**
1215
* AppIconService handles icon generation and serving for apps.
1316
*
@@ -51,7 +54,20 @@ class AppIconService extends BaseService {
5154
// Get icon file node
5255
const dir_app_icons = await this.get_app_icons();
5356
const node = await dir_app_icons.getChild(`${app_uid}-${size}.png`);
54-
await node.fetchEntry();
57+
if ( ! await node.exists() ) {
58+
// Use database-stored icon as a fallback
59+
const app = await get_app({ uid: app_uid });
60+
if ( ! app.icon ) {
61+
app.icon = DEFAULT_APP_ICON;
62+
}
63+
const [metadata, app_icon] = app.icon.split(',');
64+
console.log('METADATA', metadata);
65+
const mime = metadata.split(';')[0].split(':')[1];
66+
const img = Buffer.from(app_icon, 'base64');
67+
res.set('Content-Type', mime);
68+
res.send(img);
69+
return;
70+
}
5571

5672
const svc_su = this.services.get('su');
5773
const ll_read = new LLRead();

src/backend/src/services/default-app-icon.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)