Skip to content

Commit

Permalink
Merge pull request erictik#6 from erictik:queue
Browse files Browse the repository at this point in the history
Queue
  • Loading branch information
zcpua authored Apr 28, 2023
2 parents 9e15d10 + 7c260ac commit 898aa39
Show file tree
Hide file tree
Showing 18 changed files with 862 additions and 307 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/releases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ on:
workflow_dispatch:
push:
branches:
- 'main'
- "main"
paths:
- '**.ts'
- "**.ts"
jobs:
publish-gpr:
runs-on: ubuntu-latest
Expand All @@ -17,8 +17,8 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/[email protected]
with:
node-version: '16.x'
registry-url: 'https://registry.npmjs.org'
node-version: "16.x"
registry-url: "https://registry.npmjs.org"
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
- run: yarn install
Expand All @@ -29,4 +29,4 @@ jobs:
uses: softprops/[email protected]
with:
tag_name: ${{ env.APPVERSION }}
target_commitish: ${{ github.sha }}
target_commitish: ${{ github.sha }}
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
libs
node_modules
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# midjourney-api

Node.js client for the unofficial MidJourney API.

<div align="center">
<p>
<a href="https://discord.gg/dP95gZ8z"><img src="https://img.shields.io/discord/1082500871478329374?color=5865F2&logo=discord&logoColor=white" alt="Discord server" /></a>
Expand Down Expand Up @@ -30,12 +31,16 @@ yarn add midjourney
## Usage

```typescript
import { Midjourney } from 'midjourney'
const client = new Midjourney(process.env.SERVER_ID, process.env.CHANNEL_ID, process.env.SALAI_TOKEN)
import { Midjourney } from "midjourney";
const client = new Midjourney(
process.env.SERVER_ID,
process.env.CHANNEL_ID,
process.env.SALAI_TOKEN
);
const msg = await client.Imagine("A little pink elephant", (uri: string) => {
console.log("loading", uri)
})
console.log({ msg })
console.log("loading", uri);
});
console.log({ msg });
```

## Example
Expand Down Expand Up @@ -71,9 +76,11 @@ Then, run the example with the following command:
```bash
npx tsx example/imagine.ts
```

```bash
npx tsx example/upscale.ts
```

```bash
npx tsx example/variation.ts
```
27 changes: 16 additions & 11 deletions example/imagine.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
import 'dotenv/config'
import { Midjourney } from '../src';
import "dotenv/config";
import { Midjourney } from "../src";
/**
*
*
* a simple example of how to use the imagine command
* ```
* npx tsx example/imagine.ts
* ```
*/
async function main() {
const client = new Midjourney(<string>process.env.SERVER_ID, <string>process.env.CHANNEL_ID, <string>process.env.SALAI_TOKEN, true)
const msg = await client.Imagine("A little pink elephant", (uri: string) => {
console.log("loading", uri)
})
console.log({ msg })
const client = new Midjourney(
<string>process.env.SERVER_ID,
<string>process.env.CHANNEL_ID,
<string>process.env.SALAI_TOKEN,
true
);
const msg = await client.Imagine("A little pink elephant", (uri: string) => {
console.log("loading", uri);
});
console.log({ msg });
}
main().catch((err) => {
console.error(err);
process.exit(1);
});
console.error(err);
process.exit(1);
});
43 changes: 27 additions & 16 deletions example/upscale.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
import 'dotenv/config'
import { Midjourney } from '../src';
import "dotenv/config";
import { Midjourney } from "../src";
/**
*
*
* a simple example of how to use the Upscale command
* ```
* npx tsx example/upscale.ts
* ```
*/
async function main() {
const client = new Midjourney(<string>process.env.SERVER_ID, <string>process.env.CHANNEL_ID, <string>process.env.SALAI_TOKEN, true)
const msg = await client.Imagine("a cool cat, blue ears, red hat")
console.log({ msg })
if (!msg) {
console.log("no message")
return
const client = new Midjourney(
<string>process.env.SERVER_ID,
<string>process.env.CHANNEL_ID,
<string>process.env.SALAI_TOKEN,
true
);
const msg = await client.Imagine("a cool cat, blue ears, red hat");
console.log({ msg });
if (!msg) {
console.log("no message");
return;
}
const msg2 = await client.Upscale(
msg.content,
2,
msg.id,
msg.hash,
(uri: string) => {
console.log("loading", uri);
}
const msg2 = await client.Upscale(msg.content, 2, msg.id, msg.hash, (uri: string) => {
console.log("loading", uri)
})
console.log({ msg2 })
);
console.log({ msg2 });
}
main().catch((err) => {
console.error(err);
process.exit(1);
});
console.error(err);
process.exit(1);
});
43 changes: 27 additions & 16 deletions example/variation.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
import 'dotenv/config'
import { Midjourney } from '../src';
import "dotenv/config";
import { Midjourney } from "../src";
/**
*
*
* a simple example of how to use the Variation command
* ```
* npx tsx example/variation.ts
* ```
*/
async function main() {
const client = new Midjourney(<string>process.env.SERVER_ID, <string>process.env.CHANNEL_ID,<string>process.env.SALAI_TOKEN,true)
const msg = await client.Imagine("a dog, blue ears, and a red nose")
console.log({msg})
if (!msg) {
console.log("no message")
return
const client = new Midjourney(
<string>process.env.SERVER_ID,
<string>process.env.CHANNEL_ID,
<string>process.env.SALAI_TOKEN,
true
);
const msg = await client.Imagine("a dog, blue ears, and a red nose");
console.log({ msg });
if (!msg) {
console.log("no message");
return;
}
const msg2 = await client.Variation(
msg.content,
2,
msg.id,
msg.hash,
(uri: string) => {
console.log("loading", uri);
}
const msg2 = await client.Variation(msg.content,2,msg.id,msg.hash,(uri:string)=>{
console.log("loading",uri)
})
console.log({msg2})
);
console.log({ msg2 });
}
main().catch((err) => {
console.error(err);
process.exit(1);
});
console.error(err);
process.exit(1);
});
Loading

0 comments on commit 898aa39

Please sign in to comment.