UNPKG

@kotori-bot/tools

Version:
77 lines (76 loc) 3.4 kB
/** * @Package @kotori-bot/tools * @Version 1.5.2 * @Author Hotaru <me@hotaru.icu> * @Copyright 2024-2025 Hotaru. All rights reserved. * @License BAN-ZHINESE-USING * @Link https://github.com/kotorijs/kotori * @Date 17:26:22 */ "use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var http_exports = {}; __export(http_exports, { Http: () => Http, default: () => http_default }); module.exports = __toCommonJS(http_exports); var import_axios = __toESM(require("axios")); class Http { instance; config; method = async (url, params, config, method = "get") => (await this.instance[method](url, Object.assign(this.config, config || {}, { params }))).data; constructor(config) { this.config = config || {}; this.instance = import_axios.default.create(this.config); this.request = this.instance.interceptors.request.use.bind(this.instance.interceptors.request); this.response = this.instance.interceptors.response.use.bind(this.instance.interceptors.response); } extend(config) { const NewHttp = new Http(Object.assign(this.config, config)); return NewHttp; } get = (url, params, config) => this.method(url, params, config, "get"); post = async (url, params, config) => (await import_axios.default.post(url, params, Object.assign(this.config, config))).data; patch = async (url, params, config) => (await import_axios.default.patch(url, params, Object.assign(this.config, config))).data; put = async (url, params, config) => (await import_axios.default.put(url, params, Object.assign(this.config, config))).data; delete = (url, params, config) => this.method(url, params, config, "delete"); head = (url, params, config) => this.method(url, params, config, "head"); options = (url, params, config) => this.method(url, params, config, "options"); ws(address, protocols) { return new WebSocket(`${this.config.baseURL ?? ""}${address}`, protocols); } request; response; } var http_default = Http; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { Http });