Skip to content

Commit 66823a1

Browse files
committed
chore: update documentation
1 parent 6566271 commit 66823a1

File tree

10 files changed

+182
-50
lines changed

10 files changed

+182
-50
lines changed

docs.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
["Input", "/storage-image-processing-api/input"],
1212
["Operations", "/storage-image-processing-api/operations"],
1313
["Output", "/storage-image-processing-api/output"],
14-
["Caching", "/storage-image-processing-api/caching"],
15-
["Error Handling", "/storage-image-processing-api/error-handling"],
1614
["Types", "/storage-image-processing-api/types"]
1715
]
1816
]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
### TODO Caching
1+
### Caching
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
### TODO Error Handling
1+
### Error Handling

docs/storage-image-processing-api/index.mdx

Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ During the installation of the extension, you will be prompted to specify a numb
4242

4343
Cloud storage bucket, where the images to be processed are located.
4444

45-
- **Cloud Storage path for caching images:**
46-
47-
A relative path in which the processed images are cached in the specified Cloud Storage bucket. If you prefer to store resized images at the default location, leave this field empty.
48-
4945
- **Allowed CORS origins:**
5046

5147
A comma-delimited value of allowed `CORS` origins. Use the default of `*` to allow all origins. This is useful to lock down 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.
@@ -62,10 +58,74 @@ curl -X GET \
6258
- **`{LOCATION}`**: The Cloud Functions location that was specified during the installation of the extension.
6359
- **`{PROJECT_ID}`**: The Firebase project ID.
6460

65-
### Operations
61+
### Operation usage
6662

6763
The `operations` query parameter is a JSON array of operations to perform. Each operation is a JSON object with an `operation` property specifying the operation to perform and other properties depending on the operation.
64+
The parameter follows a couple of rules:
65+
66+
1. The first operation in the array must be an `input` operation. This operation specifies the image to be processed. Read the [input](/input) operation documentation for more information.
67+
1. The last operation in the array must be an `output` operation. This operation specifies the `format` of the image to be created. Read the [output](/output) operation documentation for more information.
68+
69+
The following example details a remote `input` operation and the `output` type:
70+
71+
```js
72+
[
73+
{
74+
operation: 'input',
75+
type: 'url',
76+
url: 'https://example.com/image.jpg',
77+
},
78+
// Other operations...
79+
{
80+
operation: 'output',
81+
format: 'webp',
82+
},
83+
];
84+
```
6885

69-
The first operation in the array must be an `input` operation. This operation specifies the image to be processed. Read the [input](/input) operation documentation for more information.
86+
Additional operations can be placed inbetween to process the image operation types outline in the [documentation](/operations), for example to flip then rotate the image 90 degrees:
87+
88+
```js
89+
[
90+
{
91+
operation: 'input',
92+
type: 'url',
93+
url: 'https://example.com/image.jpg',
94+
},
95+
{
96+
operation: 'flip',
97+
},
98+
{
99+
operation: 'rotate',
100+
angle: 90,
101+
},
102+
{
103+
operation: 'output',
104+
format: 'webp',
105+
},
106+
];
107+
```
70108

71-
Also, the last operation in the array must be an `output` operation. This operation specifies the `format` of the image to be created. Read the [output](/output) operation documentation for more information.
109+
### Providing the operations
110+
111+
The `operations` query parameter accepts a strigified JSON object as a value. This should be encoded as a URI component, for example:
112+
113+
```js
114+
const operations = [
115+
{
116+
operation: 'input',
117+
type: 'url',
118+
url: 'https://example.com/image.jpg',
119+
},
120+
{
121+
operation: 'flip',
122+
},
123+
{
124+
operation: 'output',
125+
format: 'webp',
126+
},
127+
];
128+
129+
const encodedOperations = encodeURIComponent(JSON.stringify(operations));
130+
const url = `https://{LOCATION}-{PROJECT_ID}.cloudfunctions.net/ext-storage-image-processing-api-handler/process?operations=${encodedOperations}`;
131+
```

docs/storage-image-processing-api/input.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Input
22

3+
The input operation specifies what image will be used as the source of the image processing. This can either be a path to a file on your storage bucket,
4+
a remote URL, or allow the extension to create an image on the fly.
5+
36
## Google Cloud Storage
47

58
This is a valid google cloud storage url of an existing image. For example:

extensions/storage-image-processing-api/POSTINSTALL.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,36 @@
22

33
You can test out this extension right away!
44

5-
Use the following URL to access the image processing API:
5+
1. Create an operations list, for example:
66

7-
[https://{param:LOCATION}-{param:PROJECT_ID}.cloudfunctions.net/ext-storage-image-processing-api-handler/process](https://{param:LOCATION}-{param:PROJECT_ID}.cloudfunctions.net/ext-storage-image-processing-api-handler/process)
7+
```js
8+
const operations = [
9+
{
10+
operation: 'input',
11+
type: 'url',
12+
url: 'https://images.unsplash.com/photo-1663659552548-25d7771802c9?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=774&q=80',
13+
},
14+
{
15+
operation: 'grayscale',
16+
},
17+
{
18+
operation: 'output',
19+
format: 'webp',
20+
},
21+
];
22+
```
23+
24+
2. Stringify and encode the list:
25+
26+
```js
27+
encodeURIComponent(JSON.stringify(operations))
28+
```
29+
30+
3. Call the deployed `process` Cloud Function:
31+
32+
[https://${PARAM:LOCATION}-${PARAM:PROJECT_ID}.cloudfunctions.net/ext-storage-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-storage-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)
33+
34+
The result will be a grayscaled version of the image, in WebP format.
835

936
### Using the extension
1037

extensions/storage-image-processing-api/PREINSTALL.md

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
11
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.
22

3-
A cloud function called `process` will be added to your project which you can call from your code specifying:
4-
5-
- The image to process
6-
- The operations to perform
7-
- The output image format
8-
9-
The output image will be generated and cashed.
3+
This extension creates a Cloud Function named `process`, which can be called via a GET request, specifiying
4+
the operations to perform via the `operations` query parameter, for example:
5+
6+
```js
7+
const operations = [
8+
{
9+
operation: 'input',
10+
type: 'url',
11+
url: 'https://example.com/image.jpg',
12+
},
13+
{
14+
operation: 'grayscale',
15+
},
16+
{
17+
operation: 'output',
18+
format: 'webp',
19+
},
20+
];
21+
22+
const params = `?operations=${encodeURIComponent(JSON.stringify(operations))}`;
23+
```
24+
25+
View the [official documentation](https://extensions.invertase.dev/storage-image-processing-api) for full usage examples.
1026

1127
#### Additional setup
1228

extensions/storage-image-processing-api/README.md

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,80 @@
22

33
**Author**: Invertase (**[https://invertase.io](https://invertase.io)**)
44

5-
**Description**: The Image Processing API allows you to process images in real-time.
5+
**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.
66

7-
---
87

9-
### Console
108

11-
[![Install the Storage Image Processing API extension](https://github.com/FirebaseExtended/experimental-extensions/raw/next/install-extension.png?raw=true)](https://console.firebase.google.com/project/_/extensions/install?ref=invertase/storage-image-processing-api)
9+
**Details**: 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.
1210

13-
### Firebase CLI
11+
This extension creates a Cloud Function named `process`, which can be called via a GET request, specifiying
12+
the operations to perform via the `operations` query parameter, for example:
1413

15-
```bash
16-
firebase ext:install invertase/storage-image-processing-api --project=projectId-or-alias
14+
```js
15+
const operations = [
16+
{
17+
operation: 'input',
18+
type: 'url',
19+
url: 'https://images.unsplash.com/photo-1663659552548-25d7771802c9?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=774&q=80',
20+
},
21+
{
22+
operation: 'grayscale',
23+
},
24+
{
25+
operation: 'output',
26+
format: 'webp',
27+
},
28+
];
29+
30+
const params = `?operations=${encodeURIComponent(JSON.stringify(operations))}`;
1731
```
1832

19-
> Learn more about installing extensions in the Firebase Extensions documentation: [console](https://firebase.google.com/docs/extensions/install-extensions?platform=console), [CLI](https://firebase.google.com/docs/extensions/install-extensions?platform=cli)
33+
View the [official documentation](https://extensions.invertase.dev/storage-image-processing-api) for full usage examples.
34+
35+
#### Additional setup
36+
37+
Before installing this extension, make sure that you've [set up a Cloud Storage bucket](https://firebase.google.com/docs/storage) in your Firebase project.
38+
39+
#### Billing
40+
41+
To install an extension, your project must be on the [Blaze (pay as you go) plan](https://firebase.google.com/pricing)
42+
43+
- You will be charged a small amount (typically around $0.01/month) for the Firebase resources required by this extension (even if it is not used).
44+
- This extension uses other Firebase and Google Cloud Platform services, which have associated charges if you exceed the service’s no-cost tier:
45+
- Cloud Storage
46+
- Cloud Functions (Node.js 10+ runtime. [See FAQs](https://firebase.google.com/support/faq#extensions-pricing))
47+
48+
2049

21-
---
2250

2351
**Configuration Parameters:**
2452

25-
- 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).
53+
* 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).
54+
55+
* 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.
56+
57+
58+
* 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.
2659

27-
- 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.
2860

29-
- 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.
3061

31-
- Cloud Storage path where processed images will be cached.: A relative path in which to store cached images. For example, `cache`. If you prefer to store resized images at the default location, leave this field empty.
3262

3363
**Cloud Functions:**
3464

35-
- **api:** TODO
65+
* **handler:** Serves a API accepting incoming HTTP requests.
66+
67+
3668

3769
**APIs Used**:
3870

39-
- storage-component.googleapis.com (Reason: Needed to use Cloud Storage)
71+
* storage-component.googleapis.com (Reason: Needed to use Cloud Storage)
72+
73+
4074

4175
**Access Required**:
4276

77+
78+
4379
This extension will operate with the following project IAM roles:
4480

45-
- storage.admin (Reason: Allows the extension to store resized images in Cloud Storage)
81+
* storage.admin (Reason: Allows the extension to read images in Cloud Storage)

extensions/storage-image-processing-api/extension.yaml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ version: 0.0.2
33
specVersion: v1beta
44

55
displayName: Image Processing API
6-
description: TODO
6+
description: >-
7+
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.
78
89
license: Apache-2.0
910

@@ -27,13 +28,13 @@ apis:
2728

2829
roles:
2930
- role: storage.admin
30-
reason: Allows the extension to store resized images in Cloud Storage
31+
reason: Allows the extension to read images in Cloud Storage
3132

3233
resources:
3334
- name: handler
3435
type: firebaseextensions.v1beta.function
3536
description: >-
36-
TODO
37+
Serves a API accepting incoming HTTP requests.
3738
properties:
3839
location: ${param:LOCATION}
3940
runtime: nodejs14
@@ -118,12 +119,3 @@ params:
118119
example: '*.example.com,invertase.io'
119120
default: '*'
120121
required: true
121-
122-
- param: CACHED_IMAGES_PATH
123-
label: Cloud Storage path where processed images will be cached.
124-
description: >
125-
A relative path in which to store cached images. For example,
126-
`cache`. If you prefer to store resized images at the default
127-
location, leave this field empty.
128-
example: processed_images_cache
129-
required: false

extensions/storage-image-processing-api/functions/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import { AssertionError } from 'assert';
1818
import a2a from 'a2a';
1919
import cors from 'cors';
20-
import express, { Response } from 'express';
20+
import express, { Request, Response } from 'express';
2121
import * as firebase from 'firebase-admin';
2222
import * as functions from 'firebase-functions';
2323
import helmet from 'helmet';
@@ -168,7 +168,7 @@ app.get(
168168
// Express requires the function to have 4 arguments for a handler
169169
// to be treated as an error handler.
170170
// eslint-disable-next-line @typescript-eslint/no-unused-vars
171-
app.use(function handleError(error, req, res, next) {
171+
app.use(function handleError(error: Error, req: Request, res: Response) {
172172
if (error instanceof StructError || error instanceof AssertionError) {
173173
functions.logger.warn(error.message, {
174174
url: req.url,

0 commit comments

Comments
 (0)