Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions 2nd-gen/custom-events/firebase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"functions": {
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint"
]
}
}
18 changes: 18 additions & 0 deletions 2nd-gen/custom-events/functions/ README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Firebase Custom Events sample
================================================

A custom event trigger function that handles `firebase.extensions.storage-resize-images.v1.complete` and adds custom workflow.


Getting Started
---------------

1. Install the [Resize Images
](https://firebase.google.com/products/extensions/firebase-storage-resize-images)
1. Install dependencies with `npm install` and deploy with `firebase deploy --only functions`
1. Upload a test image to the storage bucket configured for the extension.

License
-------

© Google, 2022. Licensed under an [Apache-2](../../../LICENSE) license.
14 changes: 14 additions & 0 deletions 2nd-gen/custom-events/functions/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
root: true,
env: {
es6: true,
node: true,
},
extends: [
"eslint:recommended",
"google",
],
rules: {
quotes: ["error", "double"],
},
};
37 changes: 37 additions & 0 deletions 2nd-gen/custom-events/functions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// [START import]
const {onCustomEventPublished} = require("firebase-functions/v2/eventarc");
const logger = require("firebase-functions/logger");
const { initializeApp } = require('firebase-admin/app');
const { getStorage } = require('firebase-admin/storage');
// [END import]

initializeApp();

// [START imageresizedEvent]
exports.onimageresized = onCustomEventPublished(
"firebase.extensions.storage-resize-images.v1.complete",
(event) => {
logger.info("Received image resize completed event", event);
// For example, delete the original.
return getStorage()
.bucket("my-project.appspot.com")
.file(event.subject)
.delete();
});
// [END imageresizedEvent]
26 changes: 26 additions & 0 deletions 2nd-gen/custom-events/functions/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "functions-custom-events",
"description": "Custom event handler for Image Resizer extension.",
"scripts": {
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"serve": "firebase emulators:start --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "16"
},
"main": "index.js",
"dependencies": {
"firebase-admin": "^10.0.0",
"firebase-functions": "^3.20.1"
},
"devDependencies": {
"eslint": "^8.9.0",
"eslint-config-google": "^0.14.0"
},
"private": true
}