dockge/backend/models/agent.ts
Louis Lam d655a8cc21 WIP
2023-12-20 23:29:24 +08:00

33 lines
832 B
TypeScript

import { BeanModel } from "redbean-node/dist/bean-model";
import { R } from "redbean-node";
import { LooseObject } from "../../common/util-common";
import User from "./user";
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,
password: this.password,
endpoint: this.endpoint,
};
}
}
export default Agent;