From bce56114496cee3ceeceb493417d68aa65e2e21e Mon Sep 17 00:00:00 2001 From: Filip Znachor Date: Wed, 3 Jul 2024 22:39:42 +0200 Subject: [PATCH] Added storages, accesses & websites, other changes --- .npmignore | 2 +- package.json | 2 +- src/API.ts | 2 +- src/index.ts | 4 ++- src/models/Base.ts | 4 --- src/models/Certificate.ts | 12 +++++-- src/models/Storage.ts | 59 +++++++++++++++++++++++++++++++++ src/models/StorageAccess.ts | 49 ++++++++++++++++++++++++++++ src/models/Website.ts | 65 +++++++++++++++++++++++++++++++++++++ 9 files changed, 188 insertions(+), 11 deletions(-) delete mode 100644 src/models/Base.ts create mode 100644 src/models/Storage.ts create mode 100644 src/models/StorageAccess.ts create mode 100644 src/models/Website.ts diff --git a/.npmignore b/.npmignore index b394908..a85353f 100644 --- a/.npmignore +++ b/.npmignore @@ -1,2 +1,2 @@ src/ -!lib/** \ No newline at end of file +!lib/** diff --git a/package.json b/package.json index e85ae8d..e47af5b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "oohost.js", - "version": "0.0.6", + "version": "0.0.7", "description": "TypeScript library for accessing the oohost API", "license": "MIT", "author": "oohost.cz", diff --git a/src/API.ts b/src/API.ts index 480a266..75f6a66 100644 --- a/src/API.ts +++ b/src/API.ts @@ -64,7 +64,7 @@ export class Response { } /** - * Get Reponse meta keys + * Get Response meta keys * @returns meta keys */ getMeta() { diff --git a/src/index.ts b/src/index.ts index 4219d75..15aafdc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,8 @@ export * from "./API"; export * from "./APIList"; -export * from "./models/Base"; export * from "./models/User"; export * from "./models/Domain"; +export * from "./models/Storage"; +export * from "./models/StorageAccess"; export * from "./models/Certificate"; +export * from "./models/Website"; diff --git a/src/models/Base.ts b/src/models/Base.ts deleted file mode 100644 index 3594813..0000000 --- a/src/models/Base.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { Response } from "../API"; - -export type PromisedData = Promise>; -export type Data = [T | null, Response.ExtendedError[]]; diff --git a/src/models/Certificate.ts b/src/models/Certificate.ts index 3fbc24e..bf6777e 100644 --- a/src/models/Certificate.ts +++ b/src/models/Certificate.ts @@ -55,15 +55,21 @@ export interface CertificateEdit extends Partial { name?: string } -export interface CertificateListItem { +export interface CertificateInclude { id: number, name: string, - domain: string, + domain: string +} + +export interface CertificateExtendedInclude extends CertificateInclude { auto_renew: boolean, expiration_date: string, created_at: string, updated_at: string, - user_id: number, + user_id: number +} + +export interface CertificateListItem extends CertificateExtendedInclude { User: UserInclude } diff --git a/src/models/Storage.ts b/src/models/Storage.ts new file mode 100644 index 0000000..c3d3d53 --- /dev/null +++ b/src/models/Storage.ts @@ -0,0 +1,59 @@ +import { API, Response } from "../API"; +import { APIList } from "../APIList"; +import { UserInclude } from "./User"; + +export class Storage { + + public readonly id: number; + + constructor(id: number) { + this.id = id; + } + + public async getDetails() { + let res = await API.get("storages/details", {id: this.id}); + let details: StorageDetails | null = res.get().details ?? null; + return {details, res}; + } + + public async remove(): Promise { + return await API.get("storages/remove", {id: this.id}); + } + + public async edit(data: StorageEdit): Promise { + return await API.get("storages/edit", {id: this.id, ...data}); + } + + public static async add(name: string, size: number, server: string) { + let res = await API.get("storages/add", {name, size, server}); + let id: number | null = res.success ? res.get().info.id : null; + return {id, res}; + } + + public static getList(): APIList { + return new APIList("storages/list"); + } + +} + +export interface StorageEdit { + name?: string +} + +export interface StorageInclude { + id: number, + name: string, + status: number, + size: number, + max_size: number, + server_id: string, +} + +export interface StorageListItem extends StorageInclude { + created_at: string, + updated_at: string, + user_id: number, + User: UserInclude +} + +export type StorageDetails = StorageListItem; diff --git a/src/models/StorageAccess.ts b/src/models/StorageAccess.ts new file mode 100644 index 0000000..678a186 --- /dev/null +++ b/src/models/StorageAccess.ts @@ -0,0 +1,49 @@ +import { API, Response } from "../API"; +import { APIList } from "../APIList"; +import { StorageInclude } from "./Storage"; +import { UserInclude } from "./User"; + +export class StorageAccess { + + public readonly id: number; + + constructor(id: number) { + this.id = id; + } + + public async getDetails() { + let res = await API.get("webdav/details", {id: this.id}); + let details: StorageAccessDetails | null = res.get().details ?? null; + return {details, res}; + } + + public async remove(): Promise { + return await API.get("webdav/remove", {id: this.id}); + } + + public static async add(username: string, password: string, storage_id: number, path: string = "/") { + let res = await API.get("webdav/add", {username, password, storage_id, path}); + let id: number | null = res.success ? res.get().info.id : null; + return {id, res}; + } + + public static getList(): APIList { + return new APIList("webdav/list"); + } + +} + +export interface StorageAccessListItem { + id: number, + username: string, + server_id: string, + storage_id: number, + path: string + created_at: string, + updated_at: string, + user_id: number, + User: UserInclude, + Storage: StorageInclude +} + +export type StorageAccessDetails = StorageAccessListItem; diff --git a/src/models/Website.ts b/src/models/Website.ts new file mode 100644 index 0000000..29d3272 --- /dev/null +++ b/src/models/Website.ts @@ -0,0 +1,65 @@ +import { API, Response } from "../API"; +import { APIList } from "../APIList"; +import { CertificateExtendedInclude } from "./Certificate"; +import { StorageInclude } from "./Storage"; +import { UserInclude } from "./User"; + +export class Website { + + public readonly id: number; + + constructor(id: number) { + this.id = id; + } + + public async getDetails() { + let res = await API.get("websites/details", {id: this.id}); + let details: WebsiteDetails | null = res.get().details ?? null; + return {details, res}; + } + + public async remove(): Promise { + return await API.get("websites/remove", {id: this.id}); + } + + public async edit(data: WebsiteEdit): Promise { + return await API.get("websites/edit", {id: this.id, ...data}); + } + + public static async add(name: string) { + let res = await API.get("websites/add", {name}); + let id: number | null = res.success ? res.get().info.id : null; + return {id, res}; + } + + public static getList(): APIList { + return new APIList("websites/list"); + } + +} + +export interface WebsiteEdit { + name?: string, + storage_id?: number, + root?: string, + domain?: string, + cert_id?: number, + enabled?: boolean +} + +export interface WebsiteListItem { + id: number, + name: string, + status: number, + domain: string, + root: string, + server_id: string, + created_at: string, + updated_at: string, + user_id: number, + User: UserInclude, + Storage: StorageInclude | null, + Certificate: CertificateExtendedInclude | null +} + +export type WebsiteDetails = WebsiteListItem;