Craiyon Server: From words to wonders
API for generating images from text using different AI image generators. Currently only OpenAI DALLE has been implemented. I have plans to add more services later.
Table of Contents
Technologies Used
- NodeJS
- Express
- MySQL
- Docker
- Typescript
Libraries Used
- bcrypt
- cors
- dotenv
- dotenv-cli
- eslint
- express
- husky
- jsonwebtoken
- lint-staged
- nodemailer
- openai
- prettier
- prisma
- tsx
- typescript
- vitest
- vitest-mock-extended
- winston
API Structure
Currently there are three main endpoints:
/auth
/auth/register
post Used to register a new and send a user verification mail
Verification: Not required
Input:
- name
- password
Output: access and refresh token
/auth/login
post Used to login an existing user
Verification: Not required
Input:
- password
Output: access and refresh token
/auth/refresh-token
post Used to get new tokens using a valid refresh token
Verification: Required
Bearer token sent via headers as Bearer <token>
. This should be a valid refresh token
Input: <none>
Output: access and refresh token
/user
/user/
get Used to get current user details
Verification: Required
Access token sent via headers as Bearer <token>
Input: <none>
Output: User details
/user/new-verificaion-token
patch Used to generate a new account verification token and sends it to registered email.
Verification: Required
Access token sent via headers as Bearer <token>
Input:
- handleUrl: Url that will handle the verification. Preferably a frontend route. By default server url will be used
Output: Success or Error response
/user/verify/:user/:token
get Used to verify the account for token generated using previous API.
Verification: Not required
Input:
- user: User ID
- token: token generated using
/user/new-verificaion-token
Output: Success or Error response
/user/verify
patch Used to verify the account for token generated using previous API.
Verification: Not required
Input:
- user: User ID
- token: token generated using
/user/new-verificaion-token
Output: Success or Error response
/user/password-reset-mail
post Used to send password reset mail to registered email
Verification: Not required
Input:
Output: Success or Error response
/user/reset-password
patch Used to reset user password
Verification: Not required
Input:
- user: User ID
- token: tokenn generated using
/user/password-reset-mail
- newPassword
Output: Success or Error response
/user/generated-images
get Used to get all images generated by current user
Verification: Required
Access token sent via headers as Bearer <token>
Input:
- limit: how many images to get
- page: which page (for pagination)
Output: List of images
/image
/image/public
get Used to fetch all public images
Verification: Optional
If access token is provided, the likedByUser
images will be true
for images favoritd by user
Input:
- limit: for pagination
- page: for pagination
- sort: sort by likes (
like
) or created date (created
) - order:
asc
ordesc
Output: List of public images
/image/get/:id
get Used to fetch a particular image based on ID
Verification: Optional
If access token is not provided, users private image will not be returned.
Input:
- id: Image ID
Output: Image or Error
/image/generate
post Used to generate image using different models.
Verification: Required
Account must be verified
Input:
- prompt: Text used to generate image
- model:
DALLE
- resolution:
256x256
or512x512
or1024x1024
Output: Id of generated image
/image/favorite
patch Used to add or remove image from user's favorite list
Verification: Required
Input:
- id: Image ID
Output: Success or error response
/image/private
patch Used to toggle private state of an image
Verification: Required
Input:
- id: Image ID
Output: Success or error response
/image/:id
delete Used to delete a generated image. Only Menbers and Admin can delete
Verification: Required
Input:
- id: Image ID
Output: Success or error response
Future plans
- Fix sendPasswordResetMail to use email instead of user id
- Fix image favorite to use body instead of params
- Add patch route for account verification
- Add route to make image private
- Add route to delete self generated image
- Add more image generating services
- Add full docker support
- Add "How to run locally" guide for both with and without docker