Improved Certificate class
This commit is contained in:
parent
774de8365e
commit
dcb0c014f2
2 changed files with 24 additions and 9 deletions
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "oohost.js",
|
"name": "oohost.js",
|
||||||
"version": "0.0.4",
|
"version": "0.0.5",
|
||||||
"description": "TypeScript library for accessing the oohost API",
|
"description": "TypeScript library for accessing the oohost API",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"author": "oohost.cz",
|
"author": "oohost.cz",
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { API, Response } from "../API";
|
import { API, Response } from "../API";
|
||||||
import { APIList } from "../APIList";
|
import { APIList } from "../APIList";
|
||||||
import { PromisedData } from "./Base";
|
|
||||||
import { UserInclude } from "./User";
|
import { UserInclude } from "./User";
|
||||||
|
|
||||||
export class Certificate {
|
export class Certificate {
|
||||||
|
@ -11,9 +10,10 @@ export class Certificate {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getDetails(): PromisedData<CertificateDetails> {
|
public async getDetails() {
|
||||||
let r = await API.get("certs/details", {id: this.id});
|
let res = await API.get("certs/details", {id: this.id});
|
||||||
return [ r.get().details ?? null, r.getErrors() ];
|
let details: CertificateDetails | null = res.get().details ?? null;
|
||||||
|
return {details, res};
|
||||||
}
|
}
|
||||||
|
|
||||||
public async remove(): Promise<Response> {
|
public async remove(): Promise<Response> {
|
||||||
|
@ -28,16 +28,31 @@ export class Certificate {
|
||||||
return await API.get("certs/edit", {id: this.id, ...data});
|
return await API.get("certs/edit", {id: this.id, ...data});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async add(name: string, private_key: string, certificate: string) {
|
||||||
|
let res = await API.get("certs/add", {name, private_key, certificate});
|
||||||
|
let id: number | null = res.success ? res.get().info.id : null;
|
||||||
|
return {id, res};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async generate(domains: string) {
|
||||||
|
let res = await API.get("certs/generate", {domains});
|
||||||
|
let data: CertificateData | null = res.success ? res.get().certificate : null;
|
||||||
|
return {data, res};
|
||||||
|
}
|
||||||
|
|
||||||
public static getList(): APIList<CertificateListItem> {
|
public static getList(): APIList<CertificateListItem> {
|
||||||
return new APIList("certs/list");
|
return new APIList("certs/list");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CertificateEdit {
|
export interface CertificateData {
|
||||||
name?: string,
|
private_key: string,
|
||||||
private_key?: string,
|
certificate: string
|
||||||
certificate?: string
|
}
|
||||||
|
|
||||||
|
export interface CertificateEdit extends Partial<CertificateData> {
|
||||||
|
name?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CertificateListItem {
|
export interface CertificateListItem {
|
||||||
|
|
Loading…
Reference in a new issue