This is an ExpressJS app that exposes an API that mimics a virtual file system. It allows creating directories and storing files in them. It also implements a minimal session auth system. Users can share files with others and users can either make a file public or private. A queue system was also set up on a separate process for endpoints that require file processing so as not to block the application.
Clone this repository
Run npm install
you have to have redis and mongodb installed locally to run this app
start the server by running start_server.sh
Returns the status of the API.
GET /status Response:
{ "redis": "true", "db": "true" }
Returns the number of users and number of files.
GET /stats Response:
{ "users": 10, "files": 100 }
Creates a new user.
POST /users Payload:
email: The email of the user (required). password: The password of the user (required). Response:
{ "id": "user-id", "email": "user-email" }
Logs the user in and creates a session using Redis and returns the session token.
GET /connect Response:
{ "token": "your-session-token" }
Logs a user out and deletes their session.
GET /disconnect
Creates a new file or directory.
POST /file Payload:
name: The name of the file (required). type: The type of the file (required). parentId: The ID of the parent directory (optional), defaults to 0 - root. data: The data to store in the file (optional). Response:
{ "userId": "file-id", "name": "file-name", "type": "file-type", "parentId": "parent-directory-id", "isPublic": boolean, }
Retrieves the details of a file by its ID.
GET /files/:id Response:
{ "userId": "file-id", "name": "file-name", "type": "file-type", "parentId": "parent-directory-id", "isPublic": boolean, }
Makes a file public.
PUT /files/:id/publish Response:
{ "userId": "file-id", "name": "file-name", "type": "file-type", "parentId": "parent-directory-id", "isPublic": true, }
Makes a file private.
PUT /files/:id/unpublish Response:
{ "userId": "file-id", "name": "file-name", "type": "file-type", "parentId": "parent-directory-id", "isPublic": false, }
Retrieves saved files contents.
GET /files/:id/data Response: Raw bytes
Returns a paginated (20 pages limit) list of all files info belonging to a user.
GET /files?page=number&parentId=number
Response:
[ { "userId": "file-id", "name": "file-name", "type": "file-type", "parentId": "parent-directory-id", "isPublic": boolean, }, ... ]