Skip to content

ETC-development/etc-library-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ETC-Library website's backend


Geting started

Installation:

git clone https://github.com/ETC-development/etc-library-server
cd etc-library-server
yarn #or npm install

Setup:

1- Follow the instructions in the Google Drive API's documentations on how to create you oAuth2 credentials (Client_ID, Client_Secret) and how to use them to generate your Refresh_Token.

2- Create a Mongodb database and get its URL (example host: Mongodb Atlas)

3- After that, create your .env file where you'll put the secrets and credentials: cp .env.example .env

4- Fill the .env file with all the required keys

How it works?

Endpoints:

Endpoint Method Description Request Response
/ GET A simple endpoint that just returns a hardcoded text to indicate that the API is working / "works"
/search GET Receives query parameters that provide the search query filters, validates them, and then sends paginated results Query parameters:

name: names of files or part of them (the API will return the files that have this as a substring of their names)

type: type of the file (exams, tests, worksheets, resources, courses)

year: the grade level of the file (1, 2, 3, 4 or 5)

semester: the semester (1 or 2) that the file belongs to, requires to provide the "year" param

module: name of the module that the files belong to (analysis 1, ...)


limit: number of file objects to return (for pagination purpose)
page: the page of the file objects to return according to the specified limit
Returns a json object that has these properties:
files: array of File objects
totalFileCounts: the total number of files that match the request query
totalPages: the amount of pages that are made by splitting the results of the query with the provided limit
currentPage: returns the same page given by the query
error: an error message in case if something is wrong

What it does:

  • When the server starts, it runs a recursive function that traverses all the folders in the given Google Drive API.
  • Whenever the recursive function finds files (mimeType != folder), it passes them to a callback function which parses the path of the file into a File object and pushes it to an indexedFiles array.
  • When all the folders are traversed, the files collection will get dropped, in order to avoid cases when our database would have info of files that have been deleted from the Drive.
  • Finally, the indexedFiles array will be inserted into the files collection and the server Express will start listening to API calls.

License Information: AGPL3

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published