Skip to content

Relative path urls #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions extensions/image-processing-api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Version 0.2.1

feat - support relative URLs

chore - modernize/fix tests

## Version 0.2.0

chore - bump node runtime to nodejs20
2 changes: 1 addition & 1 deletion extensions/image-processing-api/POSTINSTALL.md
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ encodeURIComponent(JSON.stringify(operations));

3. Call the deployed `process` Cloud Function:

[https://${param:LOCATION}-${param:PROJECT_ID}.cloudfunctions.net/ext-${param:EXT_INSTANCE_ID}-handler/process?operations=%5B%7B%22operation%22%3A%22input%22%2C%22type%22%3A%22url%22%2C%22url%22%3A%22https%3A%2F%2Fimages.unsplash.com%2Fphoto-1663659552548-25d7771802c9%3Fixlib%3Drb-1.2.1%26ixid%3DMnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8%26auto%3Dformat%26fit%3Dcrop%26w%3D774%26q%3D80%22%7D%2C%7B%22operation%22%3A%22grayscale%22%7D%2C%7B%22operation%22%3A%22output%22%2C%22format%22%3A%22webp%22%7D%5D](https://${param:LOCATION}-${param:PROJECT_ID}.cloudfunctions.net/ext-image-processing-api-handler/process?operations=%5B%7B%22operation%22%3A%22input%22%2C%22type%22%3A%22url%22%2C%22url%22%3A%22https%3A%2F%2Fimages.unsplash.com%2Fphoto-1663659552548-25d7771802c9%3Fixlib%3Drb-1.2.1%26ixid%3DMnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8%26auto%3Dformat%26fit%3Dcrop%26w%3D774%26q%3D80%22%7D%2C%7B%22operation%22%3A%22grayscale%22%7D%2C%7B%22operation%22%3A%22output%22%2C%22format%22%3A%22webp%22%7D%5D)
[https://${param:LOCATION}-${param:PROJECT_ID}.cloudfunctions.net/ext-${param:EXT_INSTANCE_ID}-handler/process?operations=%5B%7B%22operation%22%3A%22input%22%2C%22type%22%3A%22url%22%2C%22url%22%3A%22https%3A%2F%2Fimages.unsplash.com%2Fphoto-1663659552548-25d7771802c9%3Fixlib%3Drb-1.2.1%26ixid%3DMnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8%26auto%3Dformat%26fit%3Dcrop%26w%3D774%26q%3D80%22%7D%2C%7B%22operation%22%3A%22grayscale%22%7D%2C%7B%22operation%22%3A%22output%22%2C%22format%22%3A%22webp%22%7D%5D](https://${param:LOCATION}-${param:PROJECT_ID}.cloudfunctions.net/ext-${param:EXT_INSTANCE_ID}-handler/process?operations=%5B%7B%22operation%22%3A%22input%22%2C%22type%22%3A%22url%22%2C%22url%22%3A%22https%3A%2F%2Fimages.unsplash.com%2Fphoto-1663659552548-25d7771802c9%3Fixlib%3Drb-1.2.1%26ixid%3DMnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8%26auto%3Dformat%26fit%3Dcrop%26w%3D774%26q%3D80%22%7D%2C%7B%22operation%22%3A%22grayscale%22%7D%2C%7B%22operation%22%3A%22output%22%2C%22format%22%3A%22webp%22%7D%5D)

The result will be a grayscaled version of the image, in WebP format.

33 changes: 31 additions & 2 deletions extensions/image-processing-api/PREINSTALL.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Image Processing Extension
# Image Processing Extension
Use this extension to optimize and transform images via a powerful HTTP API with over 30 image operations for enhancing and manipulating your images.

How It Works
## How It Works
When you install this extension, it deploys a Cloud Function that exposes an HTTP API. All requests must be sent to the /process endpoint of the function. You perform image operations by passing an operations query parameter—a URL-encoded JSON string defining the operations to execute.

Example
@@ -32,6 +32,35 @@ Then, make your GET request to your Cloud Function using the correct endpoint. F
https://<your-configured-region>-<your-project-id>.cloudfunctions.net/<extension-instance-id>/process${params}
```

### Using Relative URLs (type: 'path')

In addition to fetching images via remote URLs, this extension also supports relative paths through the type: 'path' input type. This is useful when you're serving images from your own domain (e.g. through a CDN, proxy, or local server during development).

When you use type: 'path', the extension will prepend the hostname of the incoming request to the path to construct the full image URL.

```ts
const operations = [
{
operation: 'input',
type: 'path',
path: '/images/photo.jpg',
},
{
operation: 'resize',
width: 800,
height: 600,
},
{
operation: 'output',
format: 'jpeg',
},
];

const params = `?operations=${encodeURIComponent(JSON.stringify(operations))}`;
```

### Javascript Utility Library

The extension also comes with a JavaScript utility library for simplifying the creation of operations:

```ts
60 changes: 52 additions & 8 deletions extensions/image-processing-api/README.md
Original file line number Diff line number Diff line change
@@ -4,10 +4,12 @@

**Description**: Use this extension to optimize and transform images via a powerful HTTP API with over 30 different image operations to enhance and manipulate your images.

**Details**: Image Processing Extension


**Details**: # Image Processing Extension
Use this extension to optimize and transform images via a powerful HTTP API with over 30 image operations for enhancing and manipulating your images.

How It Works
## How It Works
When you install this extension, it deploys a Cloud Function that exposes an HTTP API. All requests must be sent to the /process endpoint of the function. You perform image operations by passing an operations query parameter—a URL-encoded JSON string defining the operations to execute.

Example
@@ -38,6 +40,35 @@ Then, make your GET request to your Cloud Function using the correct endpoint. F
https://<your-configured-region>-<your-project-id>.cloudfunctions.net/<extension-instance-id>/process${params}
```

### Using Relative URLs (type: 'path')

In addition to fetching images via remote URLs, this extension also supports relative paths through the type: 'path' input type. This is useful when you're serving images from your own domain (e.g. through a CDN, proxy, or local server during development).

When you use type: 'path', the extension will prepend the hostname of the incoming request to the path to construct the full image URL.

```ts
const operations = [
{
operation: 'input',
type: 'path',
path: '/images/photo.jpg',
},
{
operation: 'resize',
width: 800,
height: 600,
},
{
operation: 'output',
format: 'jpeg',
},
];

const params = `?operations=${encodeURIComponent(JSON.stringify(operations))}`;
```

### Javascript Utility Library

The extension also comes with a JavaScript utility library for simplifying the creation of operations:

```ts
@@ -70,24 +101,37 @@ To install an extension, your project must be on the [Blaze (pay as you go) plan
- Cloud Storage
- Cloud Functions (Node.js 10+ runtime. [See FAQs](https://firebase.google.com/support/faq#extensions-pricing))




**Configuration Parameters:**

- Cloud Functions location: Where do you want to deploy the functions created for this extension? You usually want a location close to your Storage bucket. For help selecting a location, refer to the [location selection guide](https://firebase.google.com/docs/functions/locations).
* Cloud Functions location: Where do you want to deploy the functions created for this extension? You usually want a location close to your Storage bucket. For help selecting a location, refer to the [location selection guide](https://firebase.google.com/docs/functions/locations).

* Cloud Storage bucket for images: The Cloud Storage bucket where images that are to be processed are located. API requests with input urls or paths that are not inside this bucket will be dropped.


* Allowed CORS origins: A comma delimited value of allowed CORS origins. Use the default of '*' to allow all origins. This is useful to lockdown your API and only allow your own website to embed the images directly. Note this will not prevent non-browser requests from accessing your API.


- Cloud Storage bucket for images: The Cloud Storage bucket where images that are to be processed are located. API requests with input urls or paths that are not inside this bucket will be dropped.

- Allowed CORS origins: A comma delimited value of allowed CORS origins. Use the default of '\*' to allow all origins. This is useful to lockdown your API and only allow your own website to embed the images directly. Note this will not prevent non-browser requests from accessing your API.

**Cloud Functions:**

- **handler:** Serves a API accepting incoming HTTP requests.
* **handler:** Serves a API accepting incoming HTTP requests.



**APIs Used**:

- storage-component.googleapis.com (Reason: Needed to use Cloud Storage)
* storage-component.googleapis.com (Reason: Needed to use Cloud Storage)



**Access Required**:



This extension will operate with the following project IAM roles:

- storage.admin (Reason: Allows the extension to read images in Cloud Storage)
* storage.admin (Reason: Allows the extension to read images in Cloud Storage)
2 changes: 1 addition & 1 deletion extensions/image-processing-api/extension.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: image-processing-api
version: 0.2.0
version: 0.2.1
specVersion: v1beta

displayName: Image Processing API

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading