Skip to content

WardenCode/holbertonschool-files_manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MIT License

Files Manager

This project is a summary of this back-end trimester at holberton School about: authentication, NodeJS, MongoDB, Redis, pagination and background processing

Table of contents

Installation

Clone the repository

git clone https://github.com/WardenCode/holbertonschool-files_manager.git

Enter to the directory

cd holbertonschool-files_manager

Install dependencies

npm install

Features

  • User authentication via a token
  • List all files
  • Upload a new file
  • Change permission of a file
  • View a file
  • Generate thumbnails for images

Code Style

On this project was used the airbnb style guide for JavaScript.

Tech and frameworks used

Usage

Turn on the worker

npm run start-worker

Turn on the server

npm run start-server

Check the status of the server

curl 0.0.0.0:5000/status ; echo ""

Check the stats of the files of the application

curl 0.0.0.0:5000/stats ; echo ""

Create a user

curl 0.0.0.0:5000/users -XPOST -H "Content-Type: application/json" -d '{ "email": "bob@dylan.com", "password": "toto1234!" }' ; echo ""
{"id":"5f1e7d35c7ba06511e683b21","email":"bob@dylan.com"}

Authenticate a user

bob@dylan:~$ curl 0.0.0.0:5000/connect -H "Authorization: Basic Ym9iQGR5bGFuLmNvbTp0b3RvMTIzNCE=" ; echo ""
{"token":"031bffac-3edc-4e51-aaae-1c121317da8a"}

Check the log in

bob@dylan:~$ curl 0.0.0.0:5000/users/me -H "X-Token: 031bffac-3edc-4e51-aaae-1c121317da8a" ; echo ""
{"id":"5f1e7cda04a394508232559d","email":"bob@dylan.com"}

Upload a file

bob@dylan:~$ curl -XPOST 0.0.0.0:5000/files -H "X-Token: f21fb953-16f9-46ed-8d9c-84c6450ec80f" -H "Content-Type: application/json" -d '{ "name": "myText.txt", "type": "file", "data": "SGVsbG8gV2Vic3RhY2shCg==" }' ; echo ""
{"id":"5f1e879ec7ba06511e683b22","userId":"5f1e7cda04a394508232559d","name":"myText.txt","type":"file","isPublic":false,"parentId":0}

Get the list of files

bob@dylan:~$ curl -XGET 0.0.0.0:5000/files -H "X-Token: f21fb953-16f9-46ed-8d9c-84c6450ec80f" ; echo ""
[{"id":"5f1e879ec7ba06511e683b22","userId":"5f1e7cda04a394508232559d","name":"myText.txt","type":"file","isPublic":false,"parentId":0},]

Publish the files

curl -XPUT 0.0.0.0:5000/files/5f1e879ec7ba06511e683b22/publish -H "X-Token: f21fb953-16f9-46ed-8d9c-84c6450ec80f" ; echo ""
{"id":"5f1e879ec7ba06511e683b22","userId":"5f1e7cda04a394508232559d","name":"myText.txt","type":"file","isPublic":true,"parentId":0}

Get the data

curl -XGET 0.0.0.0:5000/files/5f1e879ec7ba06511e683b22/data ; echo ""
Hello Webstack!

Endpoints

General Endpoints

GET /status
Returns if Redis is alive and if the DB is alive

GET /stat
Return the number of users and files in DB

POST /users
Creates a new user in DB. Also starts a background process for generating a welcome message to the user in the console

Users Endpoints

Every authenticated endpoint of the API will look at a token inside the header X-Token

GET /connect
Signs-in the user by generating a new authentication token, reading the users credentials in an Authorization header coded in Base64

GET /disconnect
Signs-out the user based on the token

GET /users/me
Retrieve the user base on the token used

Files Endpoints

POST /files
Create a new file in DB and in disk. Also starts a background process for generating thumbnails for files of type `image`

GET /files/:id
Retrieves the file document based on the ID

GET /files
Retrieves all users file documents for a specific `parentId` and with pagination

PUT /files/:id/publish
Set a file document to public based on the ID

PUT /files/:id/unpublish
Set a file document to private based on the ID

GET /files/:id/data
Return the content of the file document based on the ID

Tests

For run tests use the following command

npm run test

Test libraries

Authors

License

MIT

About

This project is a summary of this back-end trimester: authentication, NodeJS, MongoDB, Redis, pagination and background processing.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors