UNPKG

@piarre/ts-freebox

Version:

126 lines (123 loc) 3.9 kB
import { submodule_default } from "./chunk-3GGSTR2F.mjs"; import { fetch_default } from "./chunk-4JVQES7H.mjs"; // src/lib/lan.ts var LAN = class extends submodule_default { constructor(freebox) { super(freebox); } /** * Returns the current LanConfig * @link https://mafreebox.freebox.fr/doc/index.html#get-the-current-lan-configuration * @returns {Promise<Response<LanConfig>>} */ async config() { return await fetch_default(`${this.baseUrl}/lan/config/`, this.token); } /** * Update the current LanConfig * @link https://mafreebox.freebox.fr/doc/index.html#update-the-current-lan-configuration * @param config The new partial LanConfig * @returns {Promise<Response<Partial<LanConfig>>>} */ async update(config) { if (!config || Object.keys(config).length === 0) throw new Error("config is required"); return await fetch_default( `${this.baseUrl}/lan/config/`, this.token, { body: config }, "PUT" ); } /** * Getting the list of browsable LAN interfaces * @link https://mafreebox.freebox.fr/doc/index.html#getting-the-list-of-browsable-lan-interfaces * @returns {Promise<Response<LanInterface[]>>} */ async interfaces() { return await fetch_default(`${this.baseUrl}/lan/browser/interfaces/`, this.token); } /** * Getting the list of hosts on a given interface * @link https://mafreebox.freebox.fr/doc/index.html#getting-the-list-of-hosts-on-a-given-interface * @param _interface Returns the list of LanHost on this interface * @returns {Promise<Response<LanHost[]>>} */ async hosts(_interface = "pub") { if (!_interface) throw new Error("interface is required"); return await fetch_default(`${this.baseUrl}/lan/browser/${_interface}/`, this.token); } /** * Getting an host information * @link https://mafreebox.freebox.fr/doc/index.html#getting-an-host-information * @param _interface - The interface to which the host is connected * @param id - The id of the host * @returns {Promise<Response<LanHost>>} */ async host(_interface = "pub", id) { if (!_interface) throw new Error("interface is required"); if (!id) throw new Error("id is required"); return await fetch_default(`${this.baseUrl}/lan/browser/${_interface}/${id}/`, this.token); } /** * Updating an host information * @link https://mafreebox.freebox.fr/doc/index.html#updating-an-host-information * @param _interface The interface to which the host is connected * @param id The id of the host * @param data The data to update * @returns {Promise<Response<Partial<LanHost>>>} */ async updateHost(_interface = "pub", id, data) { if (!_interface) throw new Error("interface is required"); if (!id) throw new Error("id is required"); if (!data || Object.keys(data).length === 0) throw new Error("data is required"); return await fetch_default( `${this.baseUrl}/lan/browser/${_interface}/${id}/`, this.token, { body: data }, "PUT" ); } /** * Send a wake on LAN packet to the specified host with an optional password * @link https://mafreebox.freebox.fr/doc/index.html#send-wake-ok-lan-packet-to-an-host * @param _interface The interface to which the host is connected * @param mac The MAC address of the host * @param password - [OPTIONAL] The password to use to send the WOL packet * @returns */ async WOL(_interface = "pub", mac, password = "") { if (!_interface) throw new Error("interface is required"); if (!mac) throw new Error("mac is required"); return await fetch_default( `${this.baseUrl}/lan/wol/${_interface}/`, this.token, { body: { mac, password } }, "POST" ); } }; export { LAN };