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.
Make sure you have Docker and Docker Compose installed on your machine. You can download them from the official Docker website.
-
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
-
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
-
Access the Service
Once the container is running, you can access the service athttp://localhost:8080/image
. Use a query parameterhash
to pass in the encrypted URL.
If you prefer to use Docker Compose, follow these steps:
-
Create a
docker-compose.yml
File
Here’s an example of adocker-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"
-
Run the Services
Navigate to the directory containing yourdocker-compose.yml
file and run:docker-compose up -d
-
Access the Service
Once the container is running, you can access the service athttp://localhost:8080/image
. Use a query parameterhash
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:
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.
-
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. -
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.
- 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.
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.).
- 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.
Here’s how to make a request using the encrypted URL:
GET http://localhost:8080/image?hash=your_encrypted_hexadecimal_url
- 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.
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.