當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript firebase-functions.https類代碼示例

本文整理匯總了TypeScript中firebase-functions.https的典型用法代碼示例。如果您正苦於以下問題:TypeScript https類的具體用法?TypeScript https怎麽用?TypeScript https使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了https類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: getUsersDQ

import * as functions from 'firebase-functions';
import * as admin from "firebase-admin";
import { getUsersDQ } from "../getUsers";
import { getDaysCurrent } from "../util/getDaysCurrent";
import { getPeriodicityQuestion } from "./getPeriodicityQuestion";

export const activeQuestions = functions.https.onRequest((req, response) => {
  let isFlag = false;
  getUsersDQ().then((DQs:Array<any>) => {
    if(isFlag)
      return
    isFlag = true;
    for (const dq of DQs) {
      if (!dq)
        return;
      if(dq.answers) {
        for (let i = 0; i < dq.answers.length; i++)
          if(getDaysCurrent(dq,i) >= getPeriodicityQuestion(dq,i)) 
            admin.database().ref(`/${dq['uidCT']}/users/${dq['id']}/questions/${i}`).update({isActive: true})
      }
    }
    response.send("Questoes ativadas!");
  }).catch(() => console.log('Error para ativar as questĂľes'));
});
開發者ID:dekonunes,項目名稱:ConneCT-App,代碼行數:24,代碼來源:index.ts

示例2: verifyAuthentication

import * as functions from 'firebase-functions';
import { playBilling, verifyAuthentication, contentManager } from '../shared'

const BASIC_PLAN_SKU = functions.config().app.basic_plan_sku;
const PREMIUM_PLAN_SKU = functions.config().app.premium_plan_sku;

/* This file contains implementation of functions related to content serving.
 * Each functions checks if the active user have access to the subscribed content,
 * and then returns the content to client app.
 */

/* Callable that serves basic content to the client
 */
export const content_basic = functions.https.onCall(async (data, context) => {
  verifyAuthentication(context);
  await verifySubscriptionOwnershipAsync(context, [BASIC_PLAN_SKU, PREMIUM_PLAN_SKU]);

  return contentManager.getBasicContent()
})

/* Callable that serves premium content to the client
 */
export const content_premium = functions.https.onCall(async (data, context) => {
  verifyAuthentication(context);
  await verifySubscriptionOwnershipAsync(context, [PREMIUM_PLAN_SKU]);

  return contentManager.getPremiumContent()
})

// Util function that verifies if current user owns at least one active purchases listed in skus
async function verifySubscriptionOwnershipAsync(context: functions.https.CallableContext, skus: Array<string>): Promise<void> {
  const purchaseList = await playBilling.users().queryCurrentSubscriptions(context.auth.uid)
開發者ID:StarshipVendingMachine,項目名稱:android-play-billing,代碼行數:32,代碼來源:content.ts

示例3: require

const { AppServerModuleNgFactory, LAZY_MODULE_MAP } = require('./app/main');

const engine = ngExpressEngine({
  bootstrap: AppServerModuleNgFactory,
  providers: [
    provideModuleMap(LAZY_MODULE_MAP)
  ]
});

const document: string = fs.readFileSync(__dirname + '/app/index.html', 'utf8').toString();

const app = express();
app.get('**', (req, res) => {
  const url: string = req.path;
  engine(url, {
    req,
    res,
    url,
    document,
    bootstrap: AppServerModuleNgFactory,
    providers: [
      provideModuleMap(LAZY_MODULE_MAP)
    ]
  }, (err?: Error, html: string = 'oops') => {
    res.set('Cache-Control', 'public, max-age=3600, s-maxage=43200');
    res.send((err) ? err.message : html);
  });
});

export const ssr = functions.https.onRequest(app);
開發者ID:MichaelSolati,項目名稱:ng-portfolio,代碼行數:30,代碼來源:ssr.ts

示例4: next

    });
});

// Create an error handler.
app.use((err, req, res, next) => {
  if (res.headersSent) {
    return next(err);
  }
  if (res.statusCode === 200) {
    res.statusMessage = err.message || err;
    res.status(400);
  }
  res.json({ error: err.message || err });
});

export const api = functions.https.onRequest(app);
export const grades = functions.pubsub.topic('grades').onPublish(event => {
  const { chicagoId, record } = event.data.json;
  const basis = [record['term'], record['course'], record['section']].join();
  const key = crypto
    .pbkdf2Sync(basis, chicagoId, 2000000, 20, 'sha512')
    .toString('base64')
    .replace(/=/g, '')
    .replace(/\+/g, '-')
    .replace(/\//g, '_');
  return admin
    .firestore()
    .collection('institutions')
    .doc('uchicago')
    .collection('grades')
    .doc(key)
開發者ID:kevmo314,項目名稱:canigraduate.uchicago.edu,代碼行數:31,代碼來源:index.ts

示例5: WebhookClient

import * as functions from 'firebase-functions';
import { WebhookClient } from 'dialogflow-fulfillment';
import WelcomeIntent from './intents/welcome'

process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements

export const sampleFulfillment = functions.https.onRequest((request, response) => {
    const agent = new WebhookClient({ request, response });

    // Run the proper function handler based on the matched Dialogflow intent name
    const intentMap = new Map();
    intentMap.set(WelcomeIntent.name, WelcomeIntent.function);

    agent.handleRequest(intentMap);
});
開發者ID:ArtyMaury,項目名稱:sample-dialogflow-fulfillment,代碼行數:15,代碼來源:index.ts

示例6: addEvent

    });
  });
}

exports.addEventToCalendar = functions.https.onRequest((request, response) => {
  const eventData = {
    eventName: request.body.eventName,
    description: request.body.description,
    startTime: request.body.startTime,
    endTime: request.body.endTime
  };
  const oAuth2Client = new OAuth2(
    googleCredentials.web.client_id,
    googleCredentials.web.client_secret,
    googleCredentials.web.redirect_uris[0]
  );

  oAuth2Client.setCredentials({
    refresh_token: googleCredentials.refresh_token
  });

  addEvent(eventData, oAuth2Client).then(data => {
    response.status(200).send(data);
    return;
  }).catch(err => {
    console.error('Error adding event: ' + err.message);
    response.status(500).send(ERROR_RESPONSE);
    return;
  });
});
開發者ID:Meistercoach83,項目名稱:sfw,代碼行數:30,代碼來源:add-calendar-event.ts

示例7:

  credential: admin.credential.applicationDefault(),
  // storageBucket: "gin-manga.appspot.com",
  // databaseURL: 'https://<DATABASE_NAME>.firebaseio.com'
  projectId: 'gin-manga'
});



const firestore = admin.firestore();


const mangahere = firestore.collection('manga_here');






// // Start writing Firebase Functions
// // https://firebase.google.com/docs/functions/typescript
//
export const helloWorld = functions.https.onRequest((request, response) => {
 response.send("Hello from Firebase!");
});


export const mangas = functions.https.onRequest(((req, resp) => {
  mangahere.mangas().then(resp.send)
    .catch(resp.send);
}));
開發者ID:pikax,項目名稱:gincloud,代碼行數:30,代碼來源:index.ts

示例8: getOpenPullRequestsWithMergeableState

import {https} from 'firebase-functions';
import {getOpenPullRequestsWithMergeableState} from './github/github-graphql-queries';

/**
 * Firebase HTTP trigger that responds with a list of Pull Requests that have merge conflicts.
 */
export const pullRequestsWithConflicts = https.onRequest(async (_request, response) => {
  const pullRequests = (await getOpenPullRequestsWithMergeableState())
    .filter(pullRequest => pullRequest.mergeable === 'CONFLICTING');

  response.status(200).json(pullRequests);
});

開發者ID:GuzmanPI,項目名稱:material2,代碼行數:12,代碼來源:pull-requests-with-conflicts.ts

示例9: code

const makeFriendshipByFriendCode = https.onCall(async (data, context) => {
  const heroId = context.auth.uid;
  const friendCode = data['friendCode'];

  if (typeof friendCode !== 'string') {
    throw new https.HttpsError('invalid-argument', `data.friendCode must be a string. (given: ${friendCode})`, { hero: heroId, friendCode });
  }

  const heroRef = firestore.collection('users').doc(heroId);

  let opponentRef: any;
  let heroFriendshipRef: any;
  let opponentFriendshipRef: any;
  let chatRef: any;



  await firestore.runTransaction(async (transaction) => {
    const friendCodeDoc = await firestore.collection('friendCodes').doc(friendCode).get();

    if (!friendCodeDoc.exists) {
      throw new https.HttpsError('not-found', `The friend code (${friendCode}) is not found.`, { hero: heroId, friendCode });
    }

    opponentRef = friendCodeDoc.data()['user'];

    if (!(opponentRef instanceof admin.firestore.DocumentReference)) {
      throw new https.HttpsError('internal', 'Something has gone wrong in the process.', { hero: heroId, friendCode });
    }

    if (heroRef.id == opponentRef.id) {
      throw new https.HttpsError('invalid-argument', `The friend code is pointing the requester himself.`, { hero: heroId, friendCode });
    }

    const otherFriendshipRefsWithSameOpponent = heroRef.collection('friendships').where('user', '==', opponentRef);
    const otherFriendshipDocsWithSameOpponent = (await transaction.get(otherFriendshipRefsWithSameOpponent)).docs;

    if (otherFriendshipDocsWithSameOpponent.length > 0) {
      throw new https.HttpsError('already-exists', `The user is already your friend.`, { hero: heroId, opponent: opponentRef.id, friendCode });
    }

    heroFriendshipRef = heroRef.collection('friendships').doc();
    opponentFriendshipRef = opponentRef.collection('friendships').doc();
    chatRef = firestore.collection('chats').doc();

    try {
      transaction
        .create(heroFriendshipRef, {
          user: opponentRef,
          chat: chatRef,
        })
        .create(opponentFriendshipRef, {
          user: heroRef,
          chat: chatRef,
        })
        .create(chatRef, {
          members: [heroRef, opponentRef],
          lastChatMessage: null,
          lastMessageCreatedAt: null,
        })
        .delete(friendCodeDoc.ref);
    } catch (err) {
      console.error(err);

      throw new https.HttpsError('internal', 'Something has gone wrong in the process.', { hero: heroId, friendCode });
    }
  });

  console.info(
    `The requester (id = ${heroRef.id}) and the user (id = ${opponentRef.id}) are now friends.
  friendship:
    The requester (id = ${heroRef.id}): ${heroFriendshipRef.id}
    The user (id = ${opponentRef.id}): ${opponentFriendshipRef.id}
  chat: ${chatRef.id}`
  );
});
開發者ID:partnercloudsupport,項目名稱:postman,代碼行數:76,代碼來源:makeFriendshipByFriendCode.ts

示例10:

import * as functions from 'firebase-functions';

// // Start writing Firebase Functions
// // https://firebase.google.com/docs/functions/typescript
//
export const holaMundo = functions.https.onRequest((request, response) => {
  response.send('Hello from Firebase!');
});
開發者ID:geeksmarter,項目名稱:andrews.codes,代碼行數:8,代碼來源:index.ts


注:本文中的firebase-functions.https類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。