Skip to content

Commit

Permalink
Merge pull request #12 from FAYStarNext/dev
Browse files Browse the repository at this point in the history
chore: Update HTTP request library to node-fetch
  • Loading branch information
EvarinDev authored Jul 22, 2024
2 parents 6fd181b + cd3ed70 commit 808cfe5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ client.login(process.env.TOKEN);
## ⛏️ Built Using <a name = "built_using"></a>

- [WebSocket](https://github.com/websockets/ws) - WebSocket Client
- [Axios](https://github.com/axios/axios) - HTTP Request
- [node-fetch](https://github.com/node-fetch/node-fetch) - HTTP Request
## Credits

- [Erela.Js](https://github.com/MenuDocs/erela.js)
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "sunday.ts",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"version": "1.0.7-indev",
"version": "1.0.8-indev",
"description": "Sunday a lavalink wrapper",
"license": "MIT",
"author": "FAYStarNext",
Expand Down Expand Up @@ -38,8 +38,8 @@
"@babel/preset-env": "^7.24.8",
"@babel/preset-typescript": "^7.24.7",
"@discordjs/collection": "^2.1.0",
"axios": "^1.7.2",
"discord.js": "^14.15.3",
"node-fetch": "^3.3.2",
"tiny-typed-emitter": "^2.1.0",
"ws": "^8.18.0"
}
Expand Down
2 changes: 1 addition & 1 deletion src/structures/Manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ export interface PlaylistData {
}

export interface ManagerEvents {
NodeCreate: (node: Node) => void;
NodeCreate: (node: Node) => void;
NodeDestroy: (node: Node) => void;
NodeConnect: (node: Node) => void;
NodeReconnect: (node: Node) => void;
Expand Down
23 changes: 10 additions & 13 deletions src/structures/Rest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Node } from "./Node";
import axios, { AxiosRequestConfig } from "axios";
import fetch from "node-fetch";

/** Handles the requests sent to the Lavalink REST API. */
export class Rest {
Expand Down Expand Up @@ -45,19 +45,16 @@ export class Rest {

/* Sends a GET request to the specified endpoint and returns the response data. */
private async request(method: "GET" | "POST" | "PATCH" | "DELETE", endpoint: string, body?: unknown): Promise<unknown> {
const config: AxiosRequestConfig = {
method,
url: this.url + endpoint,
headers: {
"Content-Type": "application/json",
Authorization: this.password,
},
data: body,
};

try {
const response = await axios(config);
return response.data;
const response = await fetch(this.url + endpoint, {
method,
headers: {
"Content-Type": "application/json",
Authorization: this.password,
},
body: JSON.stringify(body),
});
return JSON.parse(await response.text());
} catch(error) {
if (error?.response?.status === 404) {
this.node.destroy();
Expand Down

0 comments on commit 808cfe5

Please sign in to comment.