Skip to content

Commit

Permalink
init repo
Browse files Browse the repository at this point in the history
  • Loading branch information
bao-io committed Dec 28, 2023
0 parents commit 4fd27cb
Show file tree
Hide file tree
Showing 64 changed files with 12,683 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: bao-io
78 changes: 78 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: CI

on:
push:
branches:
- main

pull_request:
branches:
- main

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install pnpm
uses: pnpm/action-setup@v2

- name: Set node
uses: actions/setup-node@v3
with:
node-version: lts/*

- name: Install
run: pnpm i

- name: Lint
run: pnpm lint

check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install pnpm
uses: pnpm/action-setup@v2

- name: Set node
uses: actions/setup-node@v3
with:
node-version: lts/*

- name: Install
run: pnpm i

- name: Check
run: pnpm check

test:
runs-on: ${{ matrix.os }}

strategy:
matrix:
node: [lts/*]
os: [ubuntu-latest, windows-latest, macos-latest]
fail-fast: false

steps:
- uses: actions/checkout@v3

- name: Install pnpm
uses: pnpm/action-setup@v2

- name: Set node ${{ matrix.node }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}

- name: Install
run: pnpm i

- name: Build
run: pnpm build

- name: Test
run: pnpm test
29 changes: 29 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Release

permissions:
contents: write

on:
push:
tags:
- 'v*'

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Install pnpm
uses: pnpm/action-setup@v2

- name: Set node
uses: actions/setup-node@v3
with:
node-version: lts/*

- run: npx changelogithub
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
dist
.DS_Store
43 changes: 43 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
// Enable the ESlint flat config support
"eslint.experimental.useFlatConfig": true,

// Disable the default formatter, use eslint instead
"prettier.enable": false,
"editor.formatOnSave": false,

// Auto fix
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit",
"source.organizeImports": "never"
},

// Silent the stylistic rules in you IDE, but still auto fix them
"eslint.rules.customizations": [
{ "rule": "style/*", "severity": "off" },
{ "rule": "format/*", "severity": "off" },
{ "rule": "*-indent", "severity": "off" },
{ "rule": "*-spacing", "severity": "off" },
{ "rule": "*-spaces", "severity": "off" },
{ "rule": "*-order", "severity": "off" },
{ "rule": "*-dangle", "severity": "off" },
{ "rule": "*-newline", "severity": "off" },
{ "rule": "*quotes", "severity": "off" },
{ "rule": "*semi", "severity": "off" }
],

// Enable eslint for all supported languages
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
"vue",
"html",
"markdown",
"json",
"jsonc",
"yaml",
"toml"
]
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright © 2023 BaoBao (https://github.com/bao-io)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
110 changes: 110 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# MidJourney-SDK <a href="https://www.npmjs.com/package/midjourney-sdk"><img src="https://img.shields.io/npm/v/midjourney-sdk.svg?maxAge=3600" alt="npm version" /></a>

MidJourney in Discord API for Node.js.

## Demo

[Live demo](https://midjourney-sdk-playground-next.vercel.app)

![](assets/2671694615683.png)
![](assets/241131694080315_.png)
![](assets/[email protected])
![](assets/[email protected])
![](assets/2661694615634.png)

## Support

- Command
- [x] `/imagine`
- [x] `/info`
- [x] `/settings`
- [x] `/fast`
- [x] `/relax`
- Button Action
- [x] `upscale`
- [x] `variation`
- [x] `reroll`
- [x] `zoomout`
- [x] `vary(Region)`
- Remix Mode

## Install

```bash
pnpm i midjourney-sdk
```

## Usage

```typescript
import { MidJourney } from 'midjourney-sdk'
const ins = new MidJourney({
token: process.env.NEXT_PUBLIC_TOKEN,
guild_id: process.env.NEXT_PUBLIC_GUILD_ID,
channel_id: process.env.NEXT_PUBLIC_CHANNEL_ID,
skipHeartbeat: true
})
;(async () => {
await ins.init()
// trigger image job
const msg1 = await ins.api.imagine('apple --q 5', ({ url, progress }) => {
console(url, progress)
})
// trigger button job
const msg2 = await ins.api.action(
'msgId',
'customId',
'msgFlags',
({ url, progress }) => {
console(url, progress)
}
)
// trigger remix job
const msg3 = await ins.api.remixSubmit(
'modalMsgId',
'customId',
'components',
({ url, progress }) => {
console(url, progress)
}
)
// trigger vary(region) job
const msg4 = await ins.api.varyRegion(
'customId',
'prompt',
'mask',
({ url, progress }) => {
console(url, progress)
}
)
})()
```

## Development

- edit environment `.env` file

```
# playground/.env
NEXT_PUBLIC_TOKEN=
NEXT_PUBLIC_GUILD_ID=
NEXT_PUBLIC_CHANNEL_ID=
# discord api proxy url
NEXT_PUBLIC_API_BASE_URL=
# discord websocket proxy url
NEXT_PUBLIC_IMG_BASE_URL=
# discord websocket proxy url
NEXT_PUBLIC_WS_BASE_URL=
```

- run `play` script

```bash
pnpm play
```

- open `http://localhost:3000`

## License

[MIT](./LICENSE) License © 2023-PRESENT [BaoBao](https://github.com/bao-io)
Binary file added assets/241131694080315_.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/2661694615634.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/2671694615683.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { antfu } from '@antfu/eslint-config'

export default antfu({
rules: {
'no-useless-call': 'off',
'no-console': 'off',
},
})
83 changes: 83 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
"name": "midjourney-sdk",
"type": "module",
"version": "3.1.0",
"packageManager": "[email protected]",
"description": "MidJourney in Discord API for Node.js.",
"author": "BaoBao <[email protected]>",
"license": "MIT",
"homepage": "https://github.com/LaiBaoYuan/midjourney-sdk/#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/LaiBaoYuan/midjourney-sdk.git"
},
"bugs": {
"url": "https://github.com/LaiBaoYuan/midjourney-sdk/issues"
},
"keywords": [
"midjourney",
"midjourney-api",
"midjourney-sdk",
"custom-zoom",
"vary-region",
"zoom-out",
"vary-strong",
"vary-subtle"
],
"exports": {
".": {
"import": "./dist/index.js",
"require": "./dist/index.cjs"
},
"./package.json": "./package.json"
},
"main": "dist/index.cjs",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"engines": {
"node": ">=16.20.0"
},
"scripts": {
"dev": "tsup --watch",
"build": "tsup",
"test": "vitest",
"lint": "eslint .",
"check": "tsc --noEmit",
"play": "pnpm -F playground dev",
"prepublishOnly": "pnpm run build",
"release": "bumpp && pnpm publish",
"format": "prettier --write .",
"prepare": "simple-git-hooks"
},
"dependencies": {
"chalk": "^5.3.0",
"eventemitter3": "^5.0.1",
"isomorphic-fetch": "^3.0.0",
"isomorphic-ws": "^5.0.0",
"snowyflake": "^2.0.0",
"ws": "^8.16.0"
},
"devDependencies": {
"@antfu/eslint-config": "^2.4.6",
"@bbao/prettier-config": "^0.0.2",
"@types/isomorphic-fetch": "^0.0.39",
"@types/node": "^20.10.5",
"@types/ws": "^8.5.10",
"bumpp": "^9.2.1",
"lint-staged": "^15.2.0",
"prettier": "^3.1.1",
"simple-git-hooks": "^2.9.0",
"tsup": "^8.0.1",
"typescript": "^5.3.3",
"vitest": "^1.1.0"
},
"simple-git-hooks": {
"pre-commit": "pnpm lint-staged && pnpm check"
},
"lint-staged": {
"*": "eslint --fix"
}
}
6 changes: 6 additions & 0 deletions playground/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
NEXT_PUBLIC_TOKEN=
NEXT_PUBLIC_GUILD_ID=
NEXT_PUBLIC_CHANNEL_ID=
NEXT_PUBLIC_API_BASE_URL=
NEXT_PUBLIC_IMG_BASE_URL=
NEXT_PUBLIC_WS_BASE_URL=
Loading

0 comments on commit 4fd27cb

Please sign in to comment.