# MyPastebin

**MyPastebin** is an application for creating and sharing text or file pastes with syntax highlighting. You can also access content in raw format and manage it through an API or a Bash client.

## Features

- Create text pastes or upload files with syntax highlighting.
- Supports images, videos, and generic binary files.
- View pastes in HTML or raw format.
- User management: register new users and list existing users (admin only).
- Interact with the application using `curl` or a Bash client.
- List and delete pastes with authentication.
- Deployable with Docker and Kubernetes.

## Technologies Used

- **Python** (Flask) for the backend.
- **SQLite** or **postgresql** as a local database.
- **Pygments** for syntax highlighting.
- **Docker** and **Kubernetes** for deployments.

## Installation and Usage

### Using Docker

1. Build the Docker image:
   ```bash
   docker build -t mypastebin .

2. Start the container with Docker Compose::
   ```bash
   docker-compose up -d
   ```

3. The application will be available at `http://localhost:5000`.

### Using Kubernetes

1. Apply the Kubernetes manifests:
   ```bash
   kubectl apply -f k8s/
   ```

2. Access the service through the Ingress configured in your cluster.

### Acceso a la Aplicación

the app will be available at : [https://paste.priet.us](https://paste.priet.us).

Bash Client
-----------

The Bash client simplifies interaction with the service. Download it here:

[Download Bash Client](https://gitlab.com/teraflops/mypastebin/-/blob/main/pastebin_client.sh) | [GitLab Repository](https://gitlab.com/teraflops/mypastebin)

### Examples

*   **Authentication:**
    
        ./pastebin_client.sh login admin password123
    
*   **Create a Paste (with expiration):**
    
        echo "Hello World" | ./pastebin_client.sh create plaintext yes
    
    Creates a paste in `plaintext` format that expires in 1 day.
    
*   **Upload a File (with expiration):**
    
        ./pastebin_client.sh upload script.py python yes
    
    Uploads `script.py` as a Python paste that expires in 1 day.
    
*   **View a Paste:**
    
        ./pastebin_client.sh view 1
    
*   **View Raw Content:**
    
        ./pastebin_client.sh view_raw 1
    
*   **List Pastes:**
    
        ./pastebin_client.sh list
    
*   **Delete a Paste:**
    
        ./pastebin_client.sh delete 1
    
*   **Search Paste Contents:**
    
        ./pastebin_client.sh search "search term"
    
*   **User Details:**
    
        ./pastebin_client.sh details
    
*   **Mark a Paste as Favorite:**
    
        ./pastebin_client.sh favorite 1
    
*   **Remove a Paste from Favorites:**
    
        ./pastebin_client.sh unfavorite 1
    
*   **Download a Paste:**
    
        ./pastebin_client.sh download 1
    
*   **List Favorites:**
    
        ./pastebin_client.sh list_favorites
    
*   **List Pastes Shared With Others:**
    
        ./pastebin_client.sh shared_with_others
    
*   **List Pastes Shared With Me:**
    
        ./pastebin_client.sh shared_with_me
    
*   **Share a Paste:**
    
        ./pastebin_client.sh share 1 username true
    
    Shares paste with ID 1 with `username`, allowing edit if `true` is passed.
    
*   **Unshare a Paste:**
    
        ./pastebin_client.sh unshare 1 test
    
*   **Edit a Paste (via Editor):**
    
        ./pastebin_client.sh edit 1
    
    Opens paste with ID 1 in your default editor. Upon saving and exiting, the updated content is sent to the server.
    

Curl Examples
-------------

Interact directly with the service using `curl`.

*   **Authentication:**
    
        curl -X POST {{ request.host_url }}api/token \
                        -H "Content-Type: application/json" \
                        -d '{"username":"admin","password":"password123"}'
    
*   **Create a Paste (with expiration):**
    
        echo "Hello World" | curl -X POST {{ request.host_url }}paste \
                        -H "Authorization: Bearer <YOUR_TOKEN>" \
                        -F "c=@-" \
                        -F "lang=plaintext" \
                        -F "expire=yes"
    
    Creates a paste that expires in 1 day. Use `expire=no` for permanent pastes.
    
*   **Upload a File (with expiration):**
    
        curl -X POST {{ request.host_url }}paste \
                        -H "Authorization: Bearer <YOUR_TOKEN>" \
                        -F "c=@script.py" \
                        -F "lang=python" \
                        -F "expire=yes"
    
    Uploads `script.py` as a Python paste that expires in 1 day.
    
*   **View a Paste:**
    
        curl {{ request.host_url }}paste/1/json \
        -H "Authorization: Bearer <YOUR_TOKEN>"
    
*   **View Raw Content:**
    
        curl {{ request.host_url }}paste/1/raw \
        -H "Authorization: Bearer <YOUR_TOKEN>"
    
*   **List Pastes:**
    
        curl -H "Authorization: Bearer <YOUR_TOKEN>" {{ request.host_url }}pastes
    
*   **Delete a Paste:**
    
        curl -X DELETE {{ request.host_url }}paste/1 \
        -H "Authorization: Bearer <YOUR_TOKEN>"
    
*   **Search Paste Contents:**
    
        curl -X GET {{ request.host_url }}pastes/search?q="search term" \
        -H "Authorization: Bearer <YOUR_TOKEN>"
    
*   **User Details:**
    
        curl -X GET {{ request.host_url }}user/details \
        -H "Authorization: Bearer <YOUR_TOKEN>"
    
*   **Mark a Paste as Favorite:**
    
        curl -X POST {{ request.host_url }}api/paste/1/favorite \
        -H "Authorization: Bearer <YOUR_TOKEN>"
    
*   **Remove a Paste from Favorites:**
    
        curl -X POST {{ request.host_url }}api/paste/1/unfavorite \
        -H "Authorization: Bearer <YOUR_TOKEN>"
    
*   **Download a Paste:**
    
        curl -X GET {{ request.host_url }}api/paste/1/download \
        -H "Authorization: Bearer <YOUR_TOKEN>" \
        -J -O
    
*   **List Favorites:**
    
        curl -X GET {{ request.host_url }}api/favorites \
        -H "Authorization: Bearer <YOUR_TOKEN>"
    
*   **List Pastes Shared With Others:**
    
        curl -X GET {{ request.host_url }}api/shared_with_others \
        -H "Authorization: Bearer <YOUR_TOKEN>"
    
*   **List Pastes Shared With Me:**
    
        curl -X GET {{ request.host_url }}api/shared_with_me \
        -H "Authorization: Bearer <YOUR_TOKEN>"
    
*   **Share a Paste:**
    
        curl -X POST {{ request.host_url }}api/paste/1/share \
        -H "Authorization: Bearer <YOUR_TOKEN>" \
        -H "Content-Type: application/json" \
        -d '{
          "username": "test_user",
          "can_edit": true
        }'
    
    Shares paste with ID 1 with `test_user`, allowing edit if `can_edit` is `true`.
    
*   **Unshare a Paste:**
    
        curl -X POST {{ request.host_url }}api/paste/1/unshare \
        -H "Authorization: Bearer <YOUR_TOKEN>" \
        -H "Content-Type: application/json" \
        -d '{
          "username": "test"
        }'
    
*   **Edit a Paste:**
    
        curl -X PUT {{ request.host_url }}api/paste/1 \
        -H "Authorization: Bearer <YOUR_TOKEN>" \
        -H "Content-Type: application/json" \
        -d '{
          "content": "Updated content here"
        }'
    
    Overwrites the content of paste with ID 1 using JSON. Make sure the authenticated user has edit permission.
