[Status Page] wip, upload logo and status page listing

This commit is contained in:
Louis Lam
2022-03-17 16:42:26 +08:00
parent bb1c951a96
commit e87cdf4d09
5 changed files with 82 additions and 60 deletions

View File

@@ -22,7 +22,7 @@ class StatusPage extends BeanModel {
slug: this.slug,
title: this.title,
description: this.description,
icon: this.icon,
icon: this.getIcon(),
theme: this.theme,
published: !!this.published,
showTags: !!this.show_tags,
@@ -34,7 +34,7 @@ class StatusPage extends BeanModel {
slug: this.slug,
title: this.title,
description: this.description,
icon: this.icon,
icon: this.getIcon(),
theme: this.theme,
published: !!this.published,
showTags: !!this.show_tags,
@@ -47,6 +47,14 @@ class StatusPage extends BeanModel {
]);
}
getIcon() {
if (!this.icon) {
return "/icon.svg";
} else {
return this.icon;
}
}
}
module.exports = StatusPage;

View File

@@ -90,9 +90,17 @@ module.exports.statusPageSocketHandler = (socket) => {
try {
checkLogin(socket);
apicache.clear();
// Save Config
let statusPage = await R.findOne("status_page", " slug = ? ", [
slug
]);
if (!statusPage) {
throw new Error("No slug?");
}
const header = "data:image/png;base64,";
// Check logo format
@@ -103,23 +111,16 @@ module.exports.statusPageSocketHandler = (socket) => {
throw new Error("Only allowed PNG logo.");
}
const filename = `logo${statusPage.id}.png`;
// Convert to file
await ImageDataURI.outputFile(imgDataUrl, Database.uploadDir + "logo.png");
config.logo = "/upload/logo.png?t=" + Date.now();
await ImageDataURI.outputFile(imgDataUrl, Database.uploadDir + filename);
config.logo = `/upload/${filename}?t=` + Date.now();
} else {
config.icon = imgDataUrl;
}
// Save Config
let statusPage = await R.findOne("status_page", " slug = ? ", [
slug
]);
if (!statusPage) {
throw new Error("No slug?");
}
statusPage.slug = config.slug;
statusPage.title = config.title;
statusPage.description = config.description;