forked from firebase/firebase-functions-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
63 lines (56 loc) · 1.97 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""
Example Function params & inputs.
"""
from firebase_functions import storage_fn, params
from firebase_admin import initialize_app
initialize_app()
bucket = params.StringParam(
"BUCKET",
label="storage bucket",
description="The bucket to resize images from.",
input=params.ResourceInput(type=params.ResourceType.STORAGE_BUCKET),
default=params.STORAGE_BUCKET,
)
output_path = params.StringParam(
"OUTPUT_PATH",
label="storage bucket output path",
description=
"The path of in the bucket where processed images will be stored.",
input=params.TextInput(
example="/images/processed",
validation_regex=r"^\/.*$",
validation_error_message=
"Must be a valid path starting with a forward slash",
),
default="/images/processed",
)
delete_original = params.BoolParam(
"DELETE_ORIGINAL_FILE",
label="delete the original file",
description=
"Do you want to automatically delete the original file from the Cloud Storage?",
input=params.SelectInput([
params.SelectOption(value=True, label="Delete on any resize attempt"),
params.SelectOption(value=False, label="Don't delete"),
],),
default=True,
)
image_resize_api_secret = params.SecretParam(
"IMAGE_RESIZE_API_SECRET",
label="image resize api secret",
description="The fake secret key to use for the image resize API.",
)
@storage_fn.on_object_finalized(
bucket=bucket,
secrets=[image_resize_api_secret],
)
def resize_images(event: storage_fn.CloudEvent[storage_fn.StorageObjectData]):
"""
This function will be triggered when a new object is created in the bucket.
"""
print("Got a new image:", event)
print("Selected bucket resource:", bucket.value)
print("Selected output location:", output_path.value)
print("Testing a not so secret api key:", image_resize_api_secret.value)
print("Should original images be deleted?:", delete_original.value)
# TODO: Implement your image resize logic