Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Autodetect a MIME-type of the logo for branding #677

Merged
merged 1 commit into from
Mar 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/

import * as mime from 'mime';
import { injectable } from 'inversify';
import { CheProductService, Product } from '../common/che-protocol';
import * as path from 'path';
Expand Down Expand Up @@ -51,10 +52,10 @@ export class CheProductServiceImpl implements CheProductService {
* Return defaults
*/
return {
icon: svgAsBase64(path.join(__dirname, '/../../src/resource/che-logo.svg')),
icon: asBase64(path.join(__dirname, '/../../src/resource/che-logo.svg')),
logo: {
dark: svgAsBase64(path.join(__dirname, '/../../src/resource/che-logo-dark.svg')),
light: svgAsBase64(path.join(__dirname, '/../../src/resource/che-logo-light.svg'))
dark: asBase64(path.join(__dirname, '/../../src/resource/che-logo-dark.svg')),
light: asBase64(path.join(__dirname, '/../../src/resource/che-logo-light.svg'))
},
name: 'Eclipse Che',
welcome: {
Expand Down Expand Up @@ -84,17 +85,18 @@ export class CheProductServiceImpl implements CheProductService {
}
if (resource.startsWith('/')) {
// absolute path
return svgAsBase64(resource);
return asBase64(resource);
}
// relative path
const productJsonDir = path.dirname(productJsonPath);
return svgAsBase64(path.join(productJsonDir, resource));
return asBase64(path.join(productJsonDir, resource));
}
}

function svgAsBase64(filePath: string): string {
function asBase64(filePath: string): string {
const mimeType = mime.getType(filePath) || '';
const content = fs.readFileSync(filePath);
const header = 'data:image/svg+xml;base64,';
const header = `data:${mimeType};base64,`;
const dataUrl = header + content.toString('base64');
return dataUrl;
}