在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):firebase/functions-samples开源软件地址(OpenSource Url):https://github.com/firebase/functions-samples开源编程语言(OpenSource Language):JavaScript 71.4%开源软件介绍(OpenSource Introduction):Cloud Functions for Firebase Sample LibraryThis repository contains a collection of samples showcasing some typical uses of Cloud Functions for Firebase.
What's Cloud Functions for Firebase?Cloud Functions is a hosted, private, and scalable Node.js environment where you can run JavaScript code. Cloud Functions for Firebase integrates the Firebase platform by letting you write code that responds to events and invokes functionality exposed by other Firebase features. PrerequisitesTo learn how to get started with Cloud Functions for Firebase by having a look at our Getting Started Guide, trying the quickstart samples and looking at the documentation. Samples OverviewThis repository contains a few categories of samples:
QuickstartsHere is a set of minimal samples for each Cloud Functions trigger types. Realtime Database or FirestoreQuickstart: Uppercaser forThis quickstart sample demonstrates using Cloud Functions triggered by Firebase Realtime Database or Firestore events. The function transforms message text written to Firestore to uppercase. HTTPS trigger quickstart: Time ServerThis quickstart sample demonstrates using Cloud Functions triggered by HTTPS requests. The function returns the current server time and allows for date time formatting. Hosting triggered HTTPS function quickstart: Big BenThis quickstart demonstrates using Cloud Functions with an HTTPS trigger that's triggered through a Firebase Hosting URL. The function will display a repeated number of "BONG"s depending on the hour of the day. Cloud Storage trigger quickstart: Thumbnail generatorThis quickstart sample demonstrates using Cloud Functions triggered by Firebase Storage events. The function generates a thumbnail of uploaded images. Auth trigger quickstart: Welcome EmailThis quickstart sample demonstrates using Cloud Functions triggered by Firebase Auth events. The function sends a Welcome Email when user accounts are created (or when users sign-in using an Identity Provider for the first time) and sends a Goodbye Email when user accounts are deleted. PubSub trigger quickstart: Hello WorldThis quickstart sample demonstrates using Cloud Functions triggered by PubSub events. The functions log the PubSub payload in a Hello world message. Test Lab trigger quickstart: Log when a matrix completesThis quickstart demonstrates how to trigger a function in response to the completion of a test matrix in Firebase Test Lab. Cloud Functions v2 public preview
See the Firebase docs for more information about the v2 public preview. HTTPS: Time ServerA minimal HTTPS example. Task Queues: Back-up images from an APISee how to use Task Queues to meter traffic to a rate-limited API. Firebase Alerts: Send crash reports to DiscordTrigger a function based on a Firebase Alert, and send information about the alert to a channel in a Discord server. Custom Events: Save image metadataLearn how to trigger a function based on an event sent by an extension Callables: Add numbers and sanitize textSee how to write a v2 function that can easily be triggered from an app. PubSub: Hello worldA minimal PubSub example. Storage: Generate image thumbnailsResize images after they're added to a Storage bucket. Unit testingDevelopment BoilerplatesThe Firebase CLI generates sample code for Cloud Functions using JavaScript or TypeScript. Server-side generated pages w/ Handlebars templating and user sessionsThis sample shows how to serve server-side generated HTML pages using the HandlebarsJs templating system and serve user-specific content by always passing the Firebase ID token in a Image ProcessingHere are a few samples that show how you can process or analyze images using Cloud Functions. Image MakerThis sample demonstrates how to create various customized images such as sparkline or sphere charts through Cloud Functions and Hosting and serve it to the client. Uses an HTTP trigger. Convert images after uploadDemonstrates how to automatically convert images that are uploaded to Firebase Storage to JPEG using ImageMagick. Uses a Firebase Storage trigger. Generate image thumbnails using ImageMagickDemonstrates how to automatically generate a thumbnail for images that are uploaded to Firebase Storage using ImageMagick and generate a public download link for the images. Uses a Firebase Storage trigger. Generate image thumbnails using Node.js Stream & SharpDemonstrates how to use Node.js Stream to read image from Cloud Storage, generate a thumbnail image using Sharp and upload it back to Cloud Storage. Uses a Firebase Storage trigger. Moderate offensive imagesDemonstrates how to automatically moderate offensive images that are uploaded to Firebase Storage by using the Google Cloud Vision API to detect offensive images and ImageMagick to blur these images. Uses a Firebase Storage trigger. Extract image metadataDemonstrates how to automatically extract image's metadata using ImageMagick for images that are uploaded to Firebase Storage. Uses a Firebase Storage trigger. Firebase Realtime Database Data ConsistencyThese samples show how to implement automatic data consistency such as keeping a count of children, having a max amount of node childs, cleaning up old data etc... LastModified Firebase Database trackingTracking when the Firebase Database (or a subset) was last modified. Uses a Realtime Database trigger. Firebase Database child nodes countKeeps track of the number of child nodes of a Firebase Database element allowing clients to filter or order results using the child count. This can be useful to keep track of the number of "likes" or "followers" of something shared through social media. Uses a Realtime Database trigger. Limit number of child nodesMakes sure that the number of child nodes stays below a certain threshold. This can be useful to limit the number of lines of logs or chat history below a given number. Uses a Realtime Database trigger. Removing old items from a listThis sample shows how to remove child nodes older than 2 hours from a Firebase Database list. This can be useful for removing outdated items from a collection. Uses a Realtime Database trigger. Solve other common use casesSend FCM notificationsThis sample demonstrates how to send a Firebase Cloud Messaging (FCM) notification from a Realtime Database triggered Function when users get new followers. The sample also features a Web UI to experience the FCM notification. Uses a Realtime Database trigger. Google Assistant says ordinal of given numberThis sample shows how to create an action for the Google Home/Assistant using the Actions SDK hosted on Cloud Functions. The sample action asks users to say a number and reads out the ordinal of that number. Uses an HTTP trigger. Authenticated JSON APIThis sample shows how to authenticate access to a JSON API to only allow access to data for a specific Firebase user. Uses an HTTP trigger. Authorized HTTP endpointThis sample shows how to restrict an HTTPS Function to only the Firebase users of your app.
Only users who pass a valid Firebase ID token as a Bearer token in the Okta, LinkedIn, Spotify, Instagram, or Basic AuthAuthorize withDemonstrates how to authorize with a 3rd party sign-in mechanism, create a Firebase custom auth token, update the user's profile and authorize Firebase. Uses an HTTP trigger. Post GitHub commits to Slack channelDemonstrates how to automatically post GitHub commits to a Slack channel using an HTTPS triggered Function. Stripe or PaypalCreate and charge customers withDemonstrates hows to integrate Firebase Auth and the Realtime database with Stripe via the Stripe Node.js library and shows how to create HTTP endpoints to charge customers via Paypal. Text moderationDemonstrates how to moderate user input text for bad words. This can be used to moderate usernames, chat or forum messages. Uses a Realtime Database trigger. Email confirmationSends email confirmation after users subscribed to a mailing list. Uses a Realtime Database trigger. Automatic message translationIntegrates the Google Translate API to perform automatic text translation across any number of languages. Language codes can be stored in Firebase for on the fly changes. Uses a Realtime Database trigger. Automatic URL shortenerIntegrates the Bit.ly API to shorten URLs automatically as they are added to the database. Uses a Realtime Database trigger. Realtime Database or FirestoreFull-text search forEnable full-text search on Firebase Database data or Firestore documents by using a hosted search service. Uses a Realtime Database or Firestore trigger. User data cleanupDeletes all associated user data in the Realtime database when a user deletes his Firebase account. Uses an Auth trigger. This code has moved to its own repo at https://github.com/firebase/user-data-protection Export your data to a Google SpreadsheetThis sample demonstrates how to sync new data written to a Firebase database to a Google Sheet. It includes a method for obtaining, storing, and using Oauth2 tokens for Google API access. Uses HTTPS triggers and Realtime Database triggers. Export your data to Big QueryCopies Firebase Database elements into BigQuery automatically. This can be useful for instance for further logs analysis. Uses a Realtime Database trigger. Webhook upon Firebase Database writesWriting to the Firebase Database triggers a request to a callback URL (a Webhook). The content of the modified Data is sent to the Webhook. Uses a Realtime Database trigger. Send a survey when users update your appThis sample shows how to send a survey to your users who have updated your app. App Update is detected using a Firebase Analytics event. Uses an Analytics trigger. Send a coupon to user who have completed a purchaseThis sample shows how to send a coupon to your users who have just purchased something. 10% off on your next purchase! Uses an Analytics trigger. Delete inactive users accounts via cronPeriodically deletes the accounts of users who have not signed in in the last month. Uses an HTTPS trigger. Developer MotivatorThis sample demonstrates how to send a Firebase Cloud Messaging (FCM) notification to the developer device each time your app gains or loses a user. Uses an Analytics trigger. Audio Files ConversionThis sample uses ffmpeg / fluent-ffmpeg and automatically converts audio files that are uploaded to Cloud Storage to FLAC file format with mono-channel audio @ 16000hz. Uses a Storage trigger. Presence for FirestoreBuild a simple online / offline status indicator for your users by leveraging Firestore and Realtime Database together. Uses a Realtime Database trigger. Publish Models to Firebase MLAutomatically publishes models to Firebase ML for each TensorFlow Lite file that is uploaded to Firebase Storage. Get information about a YouTube channelThis sample shows how to query the Youtube Data API. Uses an HTTPS trigger. ContributingWe'd love that you contribute to the project. Before doing so please read our Contributor guide. License© Google, 2015-2020. Licensed under an Apache-2 license. Build Status |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论