dockge/backend/models/agent.ts
stroskler c0fc76a0c8
feat: dockge agent friendly name
Add the option to set a friendly name to a dockge remote
agent. If the field is not used the `agent.url` will be
displayed
2024-02-01 07:21:35 +00:00

32 lines
812 B
TypeScript

import { BeanModel } from "redbean-node/dist/bean-model";
import { R } from "redbean-node";
import { LooseObject } from "../../common/util-common";
export class Agent extends BeanModel {
static async getAgentList() : Promise<Record<string, Agent>> {
let list = await R.findAll("agent") as Agent[];
let result : Record<string, Agent> = {};
for (let agent of list) {
result[agent.endpoint] = agent;
}
return result;
}
get endpoint() : string {
let obj = new URL(this.url);
return obj.host;
}
toJSON() : LooseObject {
return {
url: this.url,
username: this.username,
endpoint: this.endpoint,
friendlyname: this.friendlyname
};
}
}
export default Agent;