Skip to content

SafePDF API that is inspired by SafePDF CLI & App. A self-hosted API that allows you to manage your important PDF documents in a local PocketBase database collection. Leveraging services like ngrok or cloudflared allows you to securely access and manage your PDF documents from any remote location.

License

Notifications You must be signed in to change notification settings

CoderRony955/safepdf-api

Repository files navigation

SafePDF API (Inspired by SafePDF CLI & App)

SafePDF API is a self-hosted API that allows you to manage your important PDF documents in a local PocketBase database collection. You can perform CRUD (Create, Read, Update, Delete) operations on your PDF collection, making it easy to store, retrieve, and manage your documents.

Features

  • List all PDFs: Retrieve a list of all PDFs stored in your PocketBase collection.
  • Get specific PDF: Retrieve a specific PDF by its title or ID.
  • Get PDFs by author: Retrieve a list of all PDFs by a specific author.
  • Upload PDF: Upload a new PDF by selecting a file from your local machine or by providing a URL.
  • Re-upload PDF: Update an existing PDF by re-uploading it.
  • Delete PDF: Delete a PDF from your collection by its title or ID.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

  • Python 3.8+
  • PocketBase
  • An active PocketBase instance.
  • A PocketBase collection with the following fields:
    • title (text)
    • description (text)
    • author (text)
    • pdf (file)

Installation

  1. Clone the repository:
    git clone https://github.com/CoderRony955/safepdf-api.git

Then Navigate to the cloned directory.

  1. Install the dependencies:

    pip install -r requirements.txt
  2. Rename .env.example to .safepdfapi.env file in the root directory of the project and add the following environment variables:

    POCKETBASE_URL="<your-pocketbase-url>"
    COLLECTION="<your-collection-name>"
    POCKETBASE_EMAIL="<your-pocketbase-admin-email>"
    POCKETBASE_PASS="<your-pocketbase-admin-password>"
    

Running the API

To run the API, execute the following command in the root directory of the project:

uvicorn main:app --reload

The API will be available at http://localhost:8000. You can access the API documentation at http://localhost:8000/docs.

Exposing the API to the Internet

Leveraging services like ngrok or cloudflared allows you to securely access and manage your PDF documents from any remote location, enabling seamless interaction with your self-hosted PocketBase database over the internet.

If you want to access your SafePDF API from a remote location, you can use services like ngrok or cloudflared to expose your local server to the internet.

Using ngrok

  1. Install ngrok: Follow the instructions on the ngrok website to download and install ngrok.

  2. Start your local server: Make sure your SafePDF API is running on localhost:8000.

  3. Expose your local server: Open a new terminal window and run the following command:

    ngrok http 8000

    ngrok will generate a public URL that you can use to access your API from anywhere.

Using cloudflared

  1. Install cloudflared: Follow the instructions on the Cloudflare Tunnel documentation to install cloudflared.

  2. Start your local server: Make sure your SafePDF API is running on localhost:8000.

  3. Expose your local server: Open a new terminal window and run the following command:

    cloudflared tunnel --url http://localhost:8000

    cloudflared will generate a public URL that you can use to access your API from anywhere.

API Endpoints

Here is a list of the available API endpoints:

  • GET /: Get a list of all PDFs.
  • GET /pdftitle/{title}: Get a specific PDF by title.
  • GET /pdfid/{id}: Get a specific PDF by ID.
  • GET /pdfauthor/{author}: Get a list of all PDFs by a specific author.
  • POST /uploadbyselecting: Upload a new PDF by selecting a file.
  • POST /uploadbyurl/{url}: Upload a new PDF from a URL.
  • PUT /reuploadbytitle/{title}: Re-upload (update) a PDF by title.
  • PUT /reuploadbyid/{id}: Re-upload (update) a PDF by ID.
  • DELETE /deletebytitle/{title}: Delete a PDF by title.
  • DELETE /deletebyid/{id}: Delete a PDF by ID.

For detailed information about each endpoint, please refer to the API documentation at http://localhost:8000/docs.

About

SafePDF API that is inspired by SafePDF CLI & App. A self-hosted API that allows you to manage your important PDF documents in a local PocketBase database collection. Leveraging services like ngrok or cloudflared allows you to securely access and manage your PDF documents from any remote location.

Topics

Resources

License

Stars

Watchers

Forks

Languages