mirror of
https://github.com/Sebclem/hassio-nextcloud-backup.git
synced 2024-11-24 02:02:59 +01:00
41 lines
1007 B
TypeScript
41 lines
1007 B
TypeScript
|
import { DateTime } from "luxon";
|
||
|
import { Message, MessageType } from "../types/message.js";
|
||
|
|
||
|
const maxMessageLength = 255;
|
||
|
|
||
|
class MessageManager {
|
||
|
private messages: Message[] = [];
|
||
|
|
||
|
public addMessage(type: MessageType, message: string, detail?: string) {
|
||
|
this.messages.push({
|
||
|
message: message,
|
||
|
type: type,
|
||
|
time: DateTime.now(),
|
||
|
detail: detail
|
||
|
});
|
||
|
if (this.messages.length > maxMessageLength) {
|
||
|
this.messages.shift();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public error(message: string, detail?: string) {
|
||
|
this.addMessage(MessageType.ERROR, message, detail);
|
||
|
}
|
||
|
|
||
|
public warn(message: string, detail?: string) {
|
||
|
this.addMessage(MessageType.WARN, message, detail);
|
||
|
}
|
||
|
|
||
|
public info(message: string, detail?: string) {
|
||
|
this.addMessage(MessageType.INFO, message, detail);
|
||
|
}
|
||
|
|
||
|
public success(message: string, detail?: string) {
|
||
|
this.addMessage(MessageType.SUCCESS, message, detail);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
const messageManager = new MessageManager();
|
||
|
export default messageManager;
|