How to use the firebase-functions.storage.object function in firebase-functions

To help you get started, we’ve selected a few firebase-functions examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github machinelabs / machinelabs / firebase / functions / src / uploads / add-outputs.ts View on Github external
import * as admin from 'firebase-admin';
import { storage } from 'firebase-functions';

import { ObjectMetadata } from 'firebase-functions/lib/providers/storage';
import { Runnable, TriggerAnnotated } from 'firebase-functions/lib/cloud-functions';

import { UploadType } from './upload-type';

export const bucketChange = storage.object().onFinalize((data, context) => {
  if (
    !data ||
    parseInt(data.metageneration, 10) > 1 ||
    !data.metadata ||
    data.metadata['type'] !== UploadType.ExecutionOutput
  ) {
    return Promise.resolve(true);
  }

  const { execution_id, user_id, name } = data.metadata;

  const id = admin
    .database()
    .ref()
    .push().key;