CloudLockr is an innovative data storage system. This repo contains the backend server code, which accepts requests from both the React Native application and the DE1 firmware to facilitates user authentication, file management, and database CRUD operations.
- Node.js
- TypeScript
- Express.js
- PostgreSQL
- TypeORM
- Redis
- Jest
- Clone this repository and cd into it
- Create a
.envfile in directory which containspackage.jsonand fill in the following fields
NODE_ENV={server state, probably "dev"}PORT={desired server port}DB_URL={URL of dockerized postgres development database, port must be 5433 to match docker-compose.yml}DB_AUTH_TEST_URL={URL of dockerized postgres integration test database 0, expect to be similar to DB_URL except database name is different}DB_FILE_TEST_URL={URL of dockerized postgres integration test database 1, expect to be similar to DB_URL except database name is different}REDIS_PORT=6000TOKEN_SECRET={your access token secret}REFRESH_SECRET={your refresh token secret}
- Create a
database.envfile in the same directory and fill in the following fields such that they match the.env DB_URLfield
POSTGRES_USER={matching username as DB_URL}POSTGRES_PASSWORD={matching password as DB_URL}POSTGRES_DB={matching database as DB_URL}
- Run
docker-compose -f docker-compose.yml up -d - Run
yarn install - Run
yarn build && yarn start
- The server should now be started, please refer to API Documentation for instructions on how to call server API endpoints
- Create the 2 dockerized PostgreSQL test databases, matching
DB_AUTH_TEST_URLandDB_FILE_TEST_URL - Run
yarn test
- Or run
yarn test --coverageto see test coverage, should be 100% statement and branch coverage except forsrc/index.tsandsrc/config/*.ts, as these are configuration files for the server, and the test files have their own configuration
Note: The server port will be the PORT you chose in .env, the following documentation assumes port 5000
POST http://localhost:5000/user/register- Creates a new user account
- Request requirements:
- Header:
email: Email the user wants to register with, must not be used for another account alreadypassword: Desired password, must be at least 10 characters longpassword1: Confirmation password, must matchpassword
- Header:
- Response:
- Success:
- Status code:
201 - Body:
userId: ID associated with the newly created accountaccessToken: Authorization token that must be sent in the request header for some API endpointsrefreshToken: Token that can be sent to therefreshAPI endpoint to acquire a new access tokentoken_type: Authorization token type, should be "bearer"expires: Number of seconds until access token expiresmessage: A success message
- Status code:
- Fail:
- Status code:
422 - Body: List of errors if any of the request requirements are violated
- Status code:
- Success:
POST http://localhost:5000/user/login- Logs in a user
- Request requirements:
- Header:
email: Email of the user, must be associated with an accountpassword: Password of the user, must be the same as the password used to register for the account
- Header:
- Response:
- Success:
- Status code:
200 - Body: Exactly the same as
registerendpoint
- Status code:
- Fail:
- Status code:
422 - Body: List of errors if any of the request requirements are violated
- Status code:
- Success:
POST http://localhost:5000/user/logout- Logs out a user
- Requires authorized permission
- Request requirements:
- Header:
authorization:{token_type} {accessToken}(from the response body ofregister,login, orrefresh)refreshtoken:{refreshToken}(from the response body ofregisterorlogin)
- Header:
- Response:
- Success:
- Status code:
200 - Body: Success message
- Status code:
- Fail:
- Status code:
401: If noauthorizationheader403: If access token inauthorizationheader is invalid/expired/malformed/forged422: If norefreshtokenheader
- Body: List of errors if any of the request requirements are violated
- Status code:
- Success:
POST http://localhost:5000/user/refresh- Grants a new access token
- Request requirements:
- Header:
refreshtoken:{refreshToken}(from response body ofregisterorlogin)userid:{userId}(from response body ofregisterorlogin). Must match the user ID associated with the refresh token
- Header:
- Response:
- Success:
- Status code:
200 - Body:
accessToken: Authorization token that must be sent in the request header for some API endpointstoken_type: Authorization token type, should be "bearer"expires: Number of seconds until access token expiresmessage: A success message
- Status code:
- Fail:
- Status code:
401: If any required headers are missing403: If refresh token is invalid/expired/malformed/forged
- Body: List of errors if any of the request requirements are violated
- Status code:
- Success:
DELETE http://localhost:5000/user- Deletes a user and all files owned by user
- Requires authorized permission
- Request requirements:
- Header:
authorization:{token_type} {accessToken}(from the response body ofregister,login, orrefresh)refreshtoken:{refreshToken}(from the response body ofregisterorlogin)
- Header:
- Response:
- Success:
- Status code:
200 - Body: Success message
- Status code:
- Fail:
- Status code:
401: If noauthorizationheader403: If access token inauthorizationheader is invalid/expired/malformed/forged422: If norefreshtokenheader
- Body: List of errors if any of the request requirements are violated
- Status code:
- Success:
GET http://localhost:5000/user/files- Retrieves the metadata of the files owned by a user
- Requires authorized permission
- Request requirements:
- Header:
authorization:{token_type} {accessToken}(from the response body ofregister,login, orrefresh)
- Header:
- Response:
- Success:
- Status code:
200 - Body:
filesMetadata: Array of files (just the metadata) that the user ownsmessage: A success message
- Status code:
- Fail:
- Status code:
401: If any required headers are missing403: If refresh token is invalid/expired/malformed/forged422: If no user is associated with the access token. Possible if user deletes account while getting files
- Body: List of errors if any of the request requirements are violated
- Status code:
- Success:
POST http://localhost:5000/file- Creates the base metadata for a new file
- Requires authorized permission
- Request requirements:
- Header:
authorization:{token_type} {accessToken}(from the response body ofregister,login, orrefresh)
- Body:
fileName: Name of the filefileType: Extension of the file
- Header:
- Response:
- Success:
- Status code:
200 - Body:
fileId: ID associated with newly created filefileName: Name of the filefileType: Extension of the file
- Status code:
- Fail:
- Status code:
401: If noauthorizationheader403: If access token inauthorizationheader is invalid/expired/malformed/forged404: If any of the required request body fields are missing, or if no user is associated with the access token. Possible if user deletes account while creating file
- Body: List of errors if any of the request requirements are violated
- Status code:
- Success:
POST http://localhost:5000/file/{fileId}/{blobNumber}- Stores a new blob of data associated with the fileId for the given blobNumber
- Request requirements:
- Query parameter:
fileId: Must be a valid UUID, and must be associated with a file in the databaseblobNumber: The index of the file blob to retrieve file data from, must be a valid index to the blob array (not negative and not too big)
- Body:
fileData: The file data to be stored in the blob
- Query parameter:
- Response:
- Success:
- Status code:
200 - Body: Success message
- Status code:
- Fail:
- Status code:
404: IffileIdis not valid UUID, or iffileIdis not assocated with a file in the database, or ifblobNumberis invalid (negative or too large) - Body: List of errors if any of the request requirements are violated
- Status code:
- Success:
GET http://localhost:5000/file/{fileId}- Retrieves the base metadata of a file
- Request requirements:
- Query parameter:
fileId: Must be a valid UUID, and must be associated with a file in the database
- Query parameter:
- Response:
- Success:
- Status code:
200 - Body:
numBlobs: Number of total file blobs
- Status code:
- Fail:
- Status code:
404: IffileIdis not valid UUID, or iffileIdis not assocated with a file in the database
- Status code:
- Success:
GET http://localhost:5000/file/{fileId}/{blobNumber}- Retrieves a blob of data associated with the fileId for the given blobNumber
- Request requirements:
- Query parameter:
fileId: Must be a valid UUID, and must be associated with a file in the databaseblobNumber: The index of the file blob to retrieve file data from, must be a valid index to the blob array (not negative and not too big)
- Query parameter:
- Response:
- Success:
- Status code:
200 - Body:
fileData: The file data associated with thefileIdandblobNumber
- Status code:
- Fail:
- Status code:
404: IffileIdis not valid UUID, or iffileIdis not assocated with a file in the database, or ifblobNumberis invalid (negative or too large) - Body: List of errors if any of the request requirements are violated
- Status code:
- Success:
DELETE http://localhost:5000/file/{fileId}- Deletes a file
- Requires authorized permission
- Request requirements:
- Header:
authorization:{token_type} {accessToken}(from the response body ofregister,login, orrefresh)
- Query parameter:
fileId: Must be a valid UUID
- Header:
- Response:
- Success:
- Status code:
200 - Body: Success message
- Status code:
- Fail:
- Status code:
401: If noauthorizationheader403: If access token inauthorizationheader is invalid/expired/malformed/forged404: IffileIdis not valid UUID
- Body: List of errors if any of the request requirements are violated
- Status code:
- Success: