Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const express = require('express');
const cors = require('cors');
const app = express();
app.use(cors({ origin: true }));
var serviceAccount = require("./permissions.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://fir-api-9a206.firebaseio.com"
});
const db = admin.firestore();
// create
app.post('/api/create', (req, res) => {
(async () => {
try {
await db.collection('items').doc('/' + req.body.id + '/').create({item: req.body.item});
return res.status(200).send();
} catch (error) {
console.log(error);
return res.status(500).send(error);
}
})();
});
// read item
app.get('/api/read/:item_id', (req, res) => {
const admin = require('firebase-admin')
const chalk = require('chalk')
var Airtable = require('airtable');
// init firebase
const serviceAccount = require('../credentials/serviceAccountKey.json')
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://jpvcdb.firebaseio.com"
})
const db = require('firebase-admin').firestore()
db.settings({timestampsInSnapshots: true}) // Using Timestamps
const airTableAccount = require('../credentials/airTableKey.json')
var base = new Airtable({apiKey: airTableAccount.apiKey}).base(airTableAccount.appKey);
// add seed posts
console.log(chalk.blue(`Adding seed post data...`))
base('Table 2').select({
// Selecting the first 3 records in Grid view:
// maxRecords: 3,
pageSize: 10,
view: "Grid view",
cellFormat: 'json'
}).eachPage(function page(records, fetchNextPage) {
// This function (`page`) will get called for each page of records.
export const initFirestore = () => {
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
})
return admin.firestore()
}
const defaultDomains = [`${process.env.GCLOUD_PROJECT}.firebaseapp.com`, `${process.env.GCLOUD_PROJECT}.web.app`];
console.log(`[createDefaultSiteInfo] ${defaultDomains}`);
const siteInfoData: SiteInformation = {
id: siteId,
defaultLanguage: 'en',
languages: ['en'],
isCustomDomain: false,
domains: defaultDomains,
primaryDomain: defaultDomains[0],
analytics: '',
theme: 'default',
title: process.env.GCLOUD_PROJECT
};
return admin.firestore().collection('tanam').doc(siteId).set(siteInfoData);
}
const fs = require('fs');
const ffmpeg = require('fluent-ffmpeg');
const ffmpeg_static = require('ffmpeg-static');
const UUID = require('uuid-v4');
const serviceAccount = require('./config/service_account.json');
const {Storage} = require('@google-cloud/storage');
const gcs = new Storage({keyFilename: './config/service_account.json'});
const admin = require('firebase-admin');
try {
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://fir-reacty-videos.firebaseio.com"
});
admin.firestore().settings({timestampsInSnapshots: true});
} catch (error) {
console.log(error);
}
function promisifyCommand(command) {
return new Promise((resolve, reject) => {
command.on('end', resolve).on('error', reject).run();
});
}
async function saveVideoMetadata(userToken, metadata) {
const decodedToken = await admin.auth().verifyIdToken(userToken);
const user_id = decodedToken.uid;
const videoRef = admin.firestore().doc(`users/${user_id}`).collection('videos').doc();
metadata = Object.assign(metadata, { uid: videoRef.id });
async function removeRelationOldTargets() {
const targetCollection = await admin
.firestore()
.collection(targetCollectionName)
.where(targetProperty, 'array-contains', record.id)
.get();
const promises = targetCollection.docs.map(
async (doc) => {
if (doc.id === record[sourceProperty]) {
return;
}
await AbstractEntityRepository.executeOrAddToBatch(
'update',
doc.ref,
{
[targetProperty]: admin.firestore.FieldValue.arrayRemove(
export function snapshotConstructor(event: Event): DocumentSnapshot {
if (!firestoreInstance) {
firestoreInstance = firebase.firestore(apps().admin);
}
const valueProto = _getValueProto(
event.data,
event.context.resource.name,
'value'
);
const readTime = dateToTimestampProto(_.get(event, 'data.value.readTime'));
return firestoreInstance.snapshot_(valueProto, readTime, 'json');
}
async function userOnboardingHandler(agent) {
const db = admin.firestore();
const profile = db.collection('users').doc('jeffd23');
const { name, color } = result.parameters;
await profile.set({ name, color })
agent.add(`Welcome aboard my friend!`);
}