Skip to content

Commit

Permalink
dev: add fallback for missing icons
Browse files Browse the repository at this point in the history
  • Loading branch information
KernelDeimos committed Dec 18, 2024
1 parent 7ec6621 commit f032faa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/backend/src/services/AppIconService.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ const { HLWrite } = require("../filesystem/hl_operations/hl_write");
const { LLMkdir } = require("../filesystem/ll_operations/ll_mkdir");
const { LLRead } = require("../filesystem/ll_operations/ll_read");
const { NodePathSelector } = require("../filesystem/node/selectors");
const { get_app } = require("../helpers");
const { Endpoint } = require("../util/expressutil");
const { buffer_to_stream } = require("../util/streamutil");
const BaseService = require("./BaseService");

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

const DEFAULT_APP_ICON = require('./default-app-icon.js');

/**
* AppIconService handles icon generation and serving for apps.
*
Expand Down Expand Up @@ -51,7 +54,20 @@ class AppIconService extends BaseService {
// Get icon file node
const dir_app_icons = await this.get_app_icons();
const node = await dir_app_icons.getChild(`${app_uid}-${size}.png`);
await node.fetchEntry();
if ( ! await node.exists() ) {
// Use database-stored icon as a fallback
const app = await get_app({ uid: app_uid });
if ( ! app.icon ) {
app.icon = DEFAULT_APP_ICON;
}
const [metadata, app_icon] = app.icon.split(',');
console.log('METADATA', metadata);
const mime = metadata.split(';')[0].split(':')[1];
const img = Buffer.from(app_icon, 'base64');
res.set('Content-Type', mime);
res.send(img);
return;
}

const svc_su = this.services.get('su');
const ll_read = new LLRead();
Expand Down
1 change: 1 addition & 0 deletions src/backend/src/services/default-app-icon.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f032faa

Please sign in to comment.