Skip to content

Digital39999/img-fetch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Image Fetch Service

This service allows you to proxy images by passing an encrypted URL as a query parameter. It fetches the image from the provided URL and returns it as a response. If the image is not found, it returns a fallback image.

Prerequisites

Make sure you have Docker and Docker Compose installed on your machine. You can download them from the official Docker website.

Getting Started with Docker

  1. Pull the Image
    To start using the image-fetch service, pull the latest image from the Docker registry:

    docker pull ghcr.io/digital39999/img-fetch:latest
  2. Run the Container
    You can run the container using the following command, making sure to set the necessary environment variables:

    docker run -e FALLBACK_IMAGE_URL="https://example.com/logo.png" -e PORT=8080 -e SECRET_KEY="123456789" -e MAX_CACHE_SIZE_MB=100 -p 8080:8080 ghcr.io/digital39999/img-fetch
  3. Access the Service
    Once the container is running, you can access the service at http://localhost:8080/image. Use a query parameter hash to pass in the encrypted URL.

Running with Docker Compose

If you prefer to use Docker Compose, follow these steps:

  1. Create a docker-compose.yml File
    Here’s an example of a docker-compose.yml that includes the image-fetch service with the necessary environment variables:

    version: '3.8'
    
    services:
      image-fetch:
        image: ghcr.io/digital39999/img-fetch:latest
        environment:
          FALLBACK_IMAGE_URL: "https://crni.xyz/static/logo.gif"
          PORT: 8080
          SECRET_KEY: "123456789"
          MAX_CACHE_SIZE_MB: 100
        ports:
          - "8080:8080"
  2. Run the Services
    Navigate to the directory containing your docker-compose.yml file and run:

    docker-compose up -d
  3. Access the Service
    Once the container is running, you can access the service at http://localhost:8080/image. Use a query parameter hash to pass in the encrypted URL.

Certainly! Here’s an updated section for the README that includes details about the IV (Initialization Vector) and how the key is automatically adjusted:

Decryption Process and Required Input

The Image Fetch Service utilizes an encryption mechanism to securely handle image URLs. This section outlines how the decryption works and what format the encrypted URLs should be in.

Encryption Method

  1. AES Encryption: The service uses AES (Advanced Encryption Standard) in CBC (Cipher Block Chaining) mode for encrypting the image URLs. The encryption key is defined by the SECRET_KEY environment variable, which is automatically adjusted to ensure it meets the required length.

  2. Hexadecimal Output: Encrypted URLs are returned as hexadecimal strings. This ensures that the encrypted data is URL-safe and can be easily transmitted over HTTP without issues.

Initialization Vector (IV)

  • Static IV: The IV used for encryption and decryption is a fixed byte array initialized with zeros. This means that the same IV is used for every encryption operation. While this may not be the most secure approach for all use cases, it simplifies the decryption process for this service.

Required Input Format

When making a request to the image-fetch service, the following query parameter is required:

  • hash: This parameter should contain the encrypted URL string that corresponds to the image you want to fetch. Ensure that this is a properly encrypted hexadecimal string generated by the service or your own encryption mechanism using the same AES settings (key, IV, etc.).

Key Validation

  • Automatic Key Adjustment: The SECRET_KEY is automatically adjusted by the service to ensure it is exactly 32 bytes in length. If the provided key is shorter than 32 bytes, it is padded with zeros. If it is longer, it is truncated. This allows for consistent and reliable encryption and decryption.

Example Usage

Here’s how to make a request using the encrypted URL:

GET http://localhost:8080/image?hash=your_encrypted_hexadecimal_url

Notes

  • Make sure the encrypted URL provided matches the expected format and is generated using the same encryption method as the service.
  • If the encrypted URL is malformed or does not conform to the expected structure, the service will respond with an error indicating that the URL is invalid or corrupted.

Conclusion

You can now use the image-fetch service with Docker and Docker Compose to fetch images easily using encrypted URLs, with support for fallback images and caching settings. For further details or custom configurations, feel free to modify the Docker Compose settings or environment variables as needed.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages