apps: add icon and appStoreIcon to database
This commit is contained in:
+19
-42
@@ -62,7 +62,7 @@ exports = module.exports = {
|
||||
restartAppsUsingAddons,
|
||||
|
||||
getDataDir,
|
||||
getIconPath,
|
||||
getIcon,
|
||||
getMemoryLimit,
|
||||
|
||||
downloadFile,
|
||||
@@ -421,34 +421,20 @@ function removeRestrictedFields(app) {
|
||||
'location', 'domain', 'fqdn', 'manifest', 'portBindings', 'iconUrl', 'creationTime', 'ts', 'tags', 'label', 'enableBackup');
|
||||
}
|
||||
|
||||
function getIconUrlSync(app) {
|
||||
const iconUrl = '/api/v1/apps/' + app.id + '/icon';
|
||||
|
||||
const userIconPath = `${paths.APP_ICONS_DIR}/${app.id}.user.png`;
|
||||
if (safe.fs.existsSync(userIconPath)) return iconUrl;
|
||||
|
||||
const appstoreIconPath = `${paths.APP_ICONS_DIR}/${app.id}.png`;
|
||||
if (safe.fs.existsSync(appstoreIconPath)) return iconUrl;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function getIconPath(app, options, callback) {
|
||||
function getIcon(app, options, callback) {
|
||||
assert.strictEqual(typeof app, 'object');
|
||||
assert.strictEqual(typeof options, 'object');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
const appId = app.id;
|
||||
appdb.getIcons(app.id, function (error, icons) {
|
||||
if (error) return callback(error);
|
||||
|
||||
if (!options.original) {
|
||||
const userIconPath = `${paths.APP_ICONS_DIR}/${appId}.user.png`;
|
||||
if (safe.fs.existsSync(userIconPath)) return callback(null, userIconPath);
|
||||
}
|
||||
if (!options.original && icons.icon) return callback(null, icons.icon);
|
||||
|
||||
const appstoreIconPath = `${paths.APP_ICONS_DIR}/${appId}.png`;
|
||||
if (safe.fs.existsSync(appstoreIconPath)) return callback(null, appstoreIconPath);
|
||||
if (icons.appStoreIcon) return callback(null, icons.appStoreIcon);
|
||||
|
||||
callback(new BoxError(BoxError.NOT_FOUND, 'No icon'));
|
||||
callback(new BoxError(BoxError.NOT_FOUND, 'No icon'));
|
||||
});
|
||||
}
|
||||
|
||||
function getMemoryLimit(app) {
|
||||
@@ -471,8 +457,7 @@ function postProcess(app, domainObjectMap) {
|
||||
result[portName] = app.portBindings[portName].hostPort;
|
||||
}
|
||||
app.portBindings = result;
|
||||
|
||||
app.iconUrl = getIconUrlSync(app);
|
||||
app.iconUrl = app.hasIcon || app.hasAppStoreIcon ? `/api/v1/apps/${app.id}/icon` : null;
|
||||
app.fqdn = domains.fqdn(app.location, domainObjectMap[app.domain]);
|
||||
app.alternateDomains.forEach(function (ad) { ad.fqdn = domains.fqdn(ad.subdomain, domainObjectMap[ad.domain]); });
|
||||
app.aliasDomains.forEach(function (ad) { ad.fqdn = domains.fqdn(ad.subdomain, domainObjectMap[ad.domain]); });
|
||||
@@ -799,10 +784,7 @@ function install(data, auditSource, callback) {
|
||||
|
||||
if (icon) {
|
||||
if (!validator.isBase64(icon)) return callback(new BoxError(BoxError.BAD_FIELD, 'icon is not base64', { field: 'icon' }));
|
||||
|
||||
if (!safe.fs.writeFileSync(path.join(paths.APP_ICONS_DIR, appId + '.png'), Buffer.from(icon, 'base64'))) {
|
||||
return callback(new BoxError(BoxError.FS_ERROR, 'Error saving icon:' + safe.error.message));
|
||||
}
|
||||
icon = Buffer.from(icon, 'base64');
|
||||
}
|
||||
|
||||
const locations = [{ subdomain: location, domain, type: 'primary' }]
|
||||
@@ -833,6 +815,7 @@ function install(data, auditSource, callback) {
|
||||
env,
|
||||
label,
|
||||
tags,
|
||||
icon,
|
||||
runState: exports.RSTATE_RUNNING,
|
||||
installationState: exports.ISTATE_PENDING_INSTALL
|
||||
};
|
||||
@@ -940,17 +923,15 @@ function setIcon(app, icon, auditSource, callback) {
|
||||
|
||||
if (icon) {
|
||||
if (!validator.isBase64(icon)) return callback(new BoxError(BoxError.BAD_FIELD, 'icon is not base64', { field: 'icon' }));
|
||||
|
||||
if (!safe.fs.writeFileSync(path.join(paths.APP_ICONS_DIR, appId + '.user.png'), Buffer.from(icon, 'base64'))) {
|
||||
return callback(new BoxError(BoxError.FS_ERROR, 'Error saving icon:' + safe.error.message));
|
||||
}
|
||||
} else {
|
||||
safe.fs.unlinkSync(path.join(paths.APP_ICONS_DIR, appId + '.user.png'));
|
||||
icon = Buffer.from(icon, 'base64');
|
||||
}
|
||||
|
||||
eventlog.add(eventlog.ACTION_APP_CONFIGURE, auditSource, { appId, app, icon });
|
||||
appdb.update(appId, { icon }, function (error) {
|
||||
if (error) return callback(error);
|
||||
|
||||
callback();
|
||||
eventlog.add(eventlog.ACTION_APP_CONFIGURE, auditSource, { appId, app, iconChanged: true });
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
function setMemoryLimit(app, memoryLimit, auditSource, callback) {
|
||||
@@ -1347,13 +1328,9 @@ function update(app, data, auditSource, callback) {
|
||||
if ('icon' in data) {
|
||||
if (data.icon) {
|
||||
if (!validator.isBase64(data.icon)) return callback(new BoxError(BoxError.BAD_FIELD, 'icon is not base64', { field: 'icon' }));
|
||||
|
||||
if (!safe.fs.writeFileSync(path.join(paths.APP_ICONS_DIR, appId + '.user.png'), Buffer.from(data.icon, 'base64'))) {
|
||||
return callback(new BoxError(BoxError.FS_ERROR, 'Error saving icon:' + safe.error.message));
|
||||
}
|
||||
} else {
|
||||
safe.fs.unlinkSync(path.join(paths.APP_ICONS_DIR, appId + '.user.png'));
|
||||
data.icon = Buffer.from(data.icon, 'base64');
|
||||
}
|
||||
values.icon = data.icon;
|
||||
}
|
||||
|
||||
// do not update apps in debug mode
|
||||
|
||||
Reference in New Issue
Block a user