Skip to content

Union Chat v2 - #14

Merged
devoxin merged 43 commits into
Union-Chat:devfrom
cyyynthia:master
Nov 22, 2018
Merged

devoxin merged 43 commits into
Union-Chat:devfrom
cyyynthia:master

Conversation

@cyyynthia

Copy link
Copy Markdown
Contributor

It's time to update Union backend owo

This PR is a major rewrite of the API (v2) and a v2 of the websocket! OwO
APIv2 implements more consistent endpoints with cleaner path, a brunch of new features and is covered by unit tests
WebSocket is also in a new version with fancy new features!

WARNING: Neither the old API nor the old websocket are supported by this version. Support of the old API is
not complicated, but it's not the case for the current websocket. Partial support would be just a waste of time imo

Features

  • Clean code (as always)
  • Unit tests yarn run test (note: you can skip long test with the env variable SKIP_LONG_TESTS=yes)
  • Stable and consistent
  • Ez installation system & migrator yarn run setup
  • reCAPTCHA support (should work, didn't tested and not covered by unit tests, because I don't know how to test it properly)
  • User & server settings (very basic for now)
  • Docs! :D

Ez installer

The installer will prepare the app to start working quickly and easily

  • Build the beautiful es6 code in ugly but (we all hope) working code
  • Migrates the database (no database required, everything will be created)
  • Download & build union-react (union-website can be used but some adjustments will be probably required)

Endpoints

POST /api/v2/users - Create an user

GET /api/v2/users/self - Get current user
PUT, PATCH /api/v2/users/self - Updates the current user
DELETE /api/v2/users/self - Delete the current user

POST /api/v2/servers - Create a server
PUT, PATCH /api/v2/servers/:serverId - Delete a server
DELETE /api/v2/servers/:serverId/leave - Leave a server
DELETE /api/v2/servers/:serverId - Delete a server

POST /api/v2/servers/:serverId/invites - Create an invite to a server
POST /api/v2/invites/:invite - Accept an invite

POST /api/v2/servers/:serverId/messages - Post a message
PUT/PATCH /api/v2/servers/:serverId/messages/:messageId - Update a message
DELETE /api/v2/servers/:serverId/messages/:messageId - Delete a message

Not implemented endpoints

GET /api/v2/themes - Get a list of all themes, ordered by votes (with pagination)
POST /api/v2/themes/:themeId/vote - Upvote a theme
DELETE /api/v2/themes/:themeId/vote - Remove the upvote for a theme

POST /api/v2/themes - Create a theme
PUT, PATCH /api/v2/themes/:themeId - Update a theme
DELETE /api/v2/themes/:themeId - Delete a theme

GET /api/v2/developers/applications - Get applications
POST /api/v2/developers/applications - Create an application
PUT, PATCH /api/v2/developers/applications/:applicationId - Update an application
DELETE /api/v2/developers/applications/:applicationId - Delete an application

GET /api/v2/oauth2/authorize - Oauth2 classic routes
POST /api/v2/oauth2/token - Oauth2 classic routes
POST /api/v2/oauth2/revoke - Oauth2 classic routes

New WebSocket server

Don't be a Discord. Union websocket is Subscription-based, for the happiness of your network and CPU
See the docs for more details

Some other ideas & stuff to do

  • Snipe but directly in the API (with maybe more advanced behaviour)
  • Channels & DMs
  • Improve scalability of Union

- Controllers and middlewares separated from route declaration
- es6 imports & Babel to transpile everything
- eslint to have a beautiful code
- ez installer
Will resolve conflicts later, too lazy rn
I can't find a clean way to support two versions of the websocket
server. Partial support is just a waste of time, so let's do a breaking
update
These tests are a bit useless. Important tests are in s_core
Comment thread Configuration.json.example Outdated
"maxServersPerUser": 5,
"maxAppsPerUser": 5
},
"recaptcha (Remove this entirely if you don't want to setup it)": {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps the note could be moved to a property within this object to save having to edit this line if the user wants recaptcha (mostly a nitpick here)

Comment thread docs/_pages/api.md Outdated
|---------------|-----------|---------------------------------------|
| id | snowflake | User internal ID |
| username | string | Username |
| discriminator | int | Discriminator fo the user |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| discriminator | int | Discriminator fo the user |
| discriminator | int | Discriminator for the user |

Comment thread docs/_pages/api.md Outdated
| discriminator | int | Discriminator fo the user |
| avatarUrl | string? | Url of the user's avatar |
| servers | int[] | List of the server IDs the user is in |
| online | boolean | Whenever or not the user is online |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| online | boolean | Whenever or not the user is online |
| online | boolean | Whether or not the user is online |

Comment thread docs/_pages/api.md Outdated
<span class='api-endpoint'><span class='sun-flower-text'>POST</span> /servers</span>
<span class='api-auth'>Requires authentication</span>

**Note:** You can't create more server than specified in `maxServersPerUser`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**Note:** You can't create more server than specified in `maxServersPerUser`
**Note:** You can't exceed the `maxServersPerUser` limit

Comment thread docs/_pages/socket.md Outdated
| Field | Type | Description |
|---------------|--------------|--------------------------------------------------------------------|
| id | snowflake | User ID |
| username | string | |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing desc?

@devoxin

devoxin commented Oct 28, 2018

Copy link
Copy Markdown
Member

this is so damn big.

On another note, please lint with the old settings (semicolons, yoda, etc...)

@cyyynthia

Copy link
Copy Markdown
Contributor Author

Done :D

@cyyynthia

Copy link
Copy Markdown
Contributor Author

oof also just notices some stuff:

  • I completely forgot to impement the rate limit documented in api.md
  • s_core.js test is inconsistent and behave weirdly, fails randomly and keeps the process alive, I'll probably remove it too

I'll fix that a bit later and add a comment when it's fixed

s_core was inconsistent and didn't behave like a test should do (random
failures and keeps the process alive)
Rate limiting is here to prevent API abuse and is Cloudflare-proof (IP
detection)
@cyyynthia

Copy link
Copy Markdown
Contributor Author

Fixed and changes pushed. Note that the rate limiter should use a Redis server in the future, to improve reliability and scalability

@cyyynthia

Copy link
Copy Markdown
Contributor Author

And on another note, i'm just wondering, why you prefer yoda syntax?

@devoxin
devoxin changed the base branch from master to dev November 22, 2018 01:54
@devoxin
devoxin merged commit 604a1cb into Union-Chat:dev Nov 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants