Skip to content

Commit 6d500a4

Browse files
HassanBahatitad3j
andauthored
feat(storage-resize-images): Add onStartResize event and trigger for onStart event (#2562)
* fix(storage-resize-images): add missing recordStartEvent call * feat(storage-resize-images): add onStorageResize event * docs(storage-resize-images): update changelog * chore(storage-resize-images): add onStartResize * chore(storage-resize-images): add onStartResize event --------- Co-authored-by: Tadej <tadej.dev@gmail.com>
1 parent e65ac01 commit 6d500a4

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

storage-resize-images/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## Version 0.3.1
2+
3+
fix - add missing recordStartEvent call (#2546)
4+
feat - add new onStartResize event
5+
16
## Version 0.3.0
27

38
fix! - remove backfill, due to architectural flaws.

storage-resize-images/extension.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
name: storage-resize-images
16-
version: 0.3.0
16+
version: 0.3.1
1717
specVersion: v1beta
1818

1919
displayName: Resize Images
@@ -426,6 +426,12 @@ events:
426426
description:
427427
Occurs when the function is settled. Provides no customized data other
428428
than the context.
429+
430+
- type: firebase.extensions.storage-resize-images.v1.onStartResize
431+
description:
432+
Occurs when an image resize operation completes successfully. This event
433+
is only triggered when shouldResize returns true and the resize operation
434+
succeeds.
429435
# Lifecycle events disabled - backfill feature commented out
430436
# lifecycleEvents:
431437
# onInstall:

storage-resize-images/functions/src/events.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,19 @@ export const recordCompletionEvent = async (data: string | object) => {
6060
data,
6161
});
6262
};
63+
64+
export const recordStartResizeEvent = async ({
65+
subject,
66+
data,
67+
}: {
68+
subject: string;
69+
data: string | object;
70+
}) => {
71+
if (!eventChannel) return;
72+
73+
return eventChannel.publish({
74+
type: getEventType("onStartResize"),
75+
subject,
76+
data,
77+
});
78+
};

storage-resize-images/functions/src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ const generateResizedImageHandler = async (
5959
return;
6060
}
6161

62+
await events.recordStartResizeEvent({
63+
subject: object.name,
64+
data: { input: object },
65+
});
66+
6267
const bucket = admin.storage().bucket(object.bucket);
6368
const filePath = object.name; // File path in the bucket.
6469
const parsedPath = path.parse(filePath);
@@ -149,6 +154,7 @@ const generateResizedImageHandler = async (
149154
export const generateResizedImage = functions.storage
150155
.object()
151156
.onFinalize(async (object, context) => {
157+
await events.recordStartEvent(object);
152158
await generateResizedImageHandler(object);
153159
await events.recordCompletionEvent({ context });
154160
});

0 commit comments

Comments
 (0)