Skip to content

Commit

Permalink
Merge pull request #13 from erictik:queue
Browse files Browse the repository at this point in the history
remove axios & use fetch
  • Loading branch information
zcpua authored Apr 30, 2023
2 parents 10a8cd2 + 7a711e5 commit 1f211d2
Show file tree
Hide file tree
Showing 6 changed files with 343 additions and 69 deletions.
116 changes: 116 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
"midjourney-api",
"midjourney"
],
"engines": {
"node": ">=18"
},
"author": "Eric Yang <yanghao@10d.xin>",
"license": "ISC",
"bugs": {
Expand All @@ -33,11 +36,11 @@
"@types/node": "^18.16.0",
"dotenv": "^16.0.3",
"prettier": "^2.8.8",
"ts-node": "^10.9.1",
"tsx": "^3.12.6",
"typescript": "^5.0.4"
},
"dependencies": {
"axios": "^1.3.6",
"p-queue": "^6.6.2",
"throat": "^6.0.2",
"tslib": "^2.5.0"
Expand Down
10 changes: 6 additions & 4 deletions src/midjourney.message.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import axios from "axios";
import { MJMessage } from "./interfaces";
import { CreateQueue } from "./queue";
import { sleep } from "./utls";
Expand Down Expand Up @@ -90,10 +89,13 @@ export class MidjourneyMessage {
}
async RetrieveMessages(limit = 50) {
const headers = { authorization: this.SalaiToken };
const response = await axios.get(
const response = await fetch(
`https://discord.com/api/v10/channels/${this.ChannelId}/messages?limit=${limit}`,
{ headers: headers }
{
headers: headers,
}
);
return response.data;
const data = await response.json();
return data;
}
}
18 changes: 9 additions & 9 deletions src/midjourney.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import axios from "axios";
import { MidjourneyMessage } from "./midjourney.message";
import { CreateQueue } from "./queue";
import { random, sleep } from "./utls";
Expand Down Expand Up @@ -44,15 +43,16 @@ export class Midjourney extends MidjourneyMessage {
payload: any,
callback?: (result: number) => void
) {
const headers = { authorization: this.SalaiToken };
try {
const response = await axios.post(
"https://discord.com/api/v9/interactions",
payload,
{
headers,
}
);
const headers = {
"Content-Type": "application/json",
Authorization: this.SalaiToken,
};
const response = await fetch("https://discord.com/api/v9/interactions", {
method: "POST",
body: JSON.stringify(payload),
headers: headers,
});
callback && callback(response.status);
//discord api rate limit
await sleep(950);
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
"lib": [
"es2021",
"DOM",
"esnext.asynciterable"
] /* Specify a set of bundled library declaration files that describe the target runtime environment. */,
// "jsx": "preserve", /* Specify what JSX code is generated. */
Expand Down
Loading

0 comments on commit 1f211d2

Please sign in to comment.