Vikleoboy / Epub-book-Reader

9 stars 2 forks source link

Handling ePub Files in Backend and Serving Them #3

Closed Vikleoboy closed 2 months ago

Vikleoboy commented 2 months ago

Handling ePub Files in Backend and Serving Them

Summary

Enhance the backend to handle ePub files by copying them to a dedicated folder and serving them statically. Additionally, update the database to include a unique id for each book.

Steps

  1. Setup Folder:

    • Create a folder named EpubBooks in the backend. This folder will store all ePub files.
  2. File Copying and Serving:

    • When a new book or folder is added from the frontend:
      • Copy the ePub file to the EpubBooks folder.
      • Name the copied ePub file using a unique ID (this ID will also be the book's name).
    • Serve the ePub files using express.static('./EpubBooks') to make them accessible via HTTP requests.
  3. Database Update:

    • When adding a book's data to the database, include an id field.
    • The id should be a unique identifier, which also serves as the ePub file name.
  4. Frontend Requests:

    • To access an ePub file from the frontend, use the following URL format:
      http://localhost:3002/${book.id}.epub

Example Book Object

Here’s an example of the book object structure:


const book = {
    id: "uniqueID", // Unique ID, also the ePub file name
    name: "Book Name",
    cover: "path/to/cover/image",
    // Additional fields as needed
};
Vikleoboy commented 2 months ago

Plz Dm me directly if you have any question , on dicord and join our discord server