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


TypeScript firebase-admin.database函數代碼示例

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


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

示例1: copyTestImagesToGoldens

export function copyTestImagesToGoldens(prNumber: string) {
  return firebaseAdmin.database().ref(`screenshot/reports/${prNumber}/results`).once('value')
    .then((snapshot: firebaseAdmin.database.DataSnapshot) => {
      const failedFilenames: string[] = [];
      let counter = 0;

      snapshot.forEach(childSnapshot => {
        if (childSnapshot.key && childSnapshot.val() === false) {
          failedFilenames.push(childSnapshot.key);
        }

        counter++;
        return counter === snapshot.numChildren();
      });

      return failedFilenames;
    }).then((failedFilenames: string[]) => {
      return bucket.getFiles({prefix: `screenshots/${prNumber}/test`}).then((data: any) => {
        return Promise.all(data[0]
          .filter((file: any) => failedFilenames.includes(
            path.basename(file.name, '.screenshot.png')))
          .map((file: any) => file.copy(`goldens/${path.basename(file.name)}`)));
      });
    });
}
開發者ID:GuzmanPI,項目名稱:material2,代碼行數:25,代碼來源:test-goldens.ts

示例2: selectFcmTokens

export const statusMessager = functions.database.ref('/status').onWrite(async event => {
  const tokens = await selectFcmTokens(admin.database())
  const newStatus = event.data.val()
  const title = 'Mailbox status changed'
  const body = logMessageMap(newStatus)
  await sendCloudMessage(title, body, tokens, admin.messaging())
})
開發者ID:jsse-2017-ph23,項目名稱:firebase-functions,代碼行數:7,代碼來源:index.ts

示例3: if

 await gameRef.once('value').then(async (tables: admin.database.DataSnapshot) => {
     console.log("searching for matches")
     for (let i = 0; i < tables.numChildren(); i++) {
         console.log(`searching table ${i}`)
         const result = await admin.database().ref(`games/table${i}/`).transaction((players) => {
             if (players === null) {
                 return 0;
             }
             if (players.player1 === "") {
                 console.log("adding as player1");
                 players.player1 = uid;
                 matched = true;
                 return players
             } else if (players.player2 === "") {
                 console.log("adding as player2");
                 players.player2 = uid;
                 matched = true;
                 return players
             }
         }).catch((reason) => {
             console.warn("transaction failed!");
             return {
                 committed: false,
                 snapshot: undefined
             }
         })
         if (result.committed === true) {
             if (matched) {
                 break;
             }
         }
     }
 }).catch(() => {
開發者ID:TylerLeite,項目名稱:supa-kyapucha-gemu,代碼行數:33,代碼來源:index.ts

示例4: copyGoldImagesToDatabase

export function copyGoldImagesToDatabase(name: string, resourceState: string, fileBucket: any) {
  // The name should always look like "goldens/xxx.png"
  let parsedPath = path.parse(name);
  // Get the file name.
  if (parsedPath.root != '' ||
    parsedPath.dir != 'goldens' ||
    parsedPath.ext.toLowerCase() != '.png') {
    return;
  }

  let filenameKey = path.basename(parsedPath.name, '.screenshot');
  let databaseRef = firebaseAdmin.database().ref(FIREBASE_DATA_GOLDENS).child(filenameKey);

  // When a gold image is deleted, also delete the corresponding record in the firebase database.
  if (resourceState === 'not_exists') {
    return databaseRef.set(null);
  }

  let tempFilePath = `/tmp/${parsedPath.base}`;
  let bucket = gcs.bucket(fileBucket);
  // Download file from bucket.
  return bucket.file(name).download({destination: tempFilePath})
    .then(() => {
      let data = readFileSync(tempFilePath);
      return databaseRef.set(data);
    }).catch((error: any) => console.error(`${filenameKey} ${error}`));
}
開發者ID:Chintuz,項目名稱:material2,代碼行數:27,代碼來源:image-data.ts

示例5: Date

 }, (error: any, response: any, body: string) => {
   if (error) {
     return res.status(error.code).send(error.message);
   }
   try {
     let parsed = JSON.parse(body);
     if (parsed.error) {
       return res.status(parsed.error.code).send(parsed.error.message);
     }
     parsed = parsed.map((rep: any) => {
       return {
         title: rep.name,
         description: rep.description,
         url: rep.html_url,
         createdOn: new Date(rep.pushed_at).getTime()
       };
     })
       .sort((a, b) => b.createdOn - a.createdOn)
       .slice(0, 12)
     const result = {
       results: parsed,
       expires: tomorrow
     };
     admin.database().ref('github').set(result).then(() => res.send(JSON.stringify(result.results)));
   } catch (error) {
     return res.status(error.code).send(error.message);
   }
 });
開發者ID:MichaelSolati,項目名稱:ng-portfolio,代碼行數:28,代碼來源:github.ts

示例6: cors

 cors(req, res, () => {
   admin.database().ref('linkedin').once('value', (snapshot: admin.database.DataSnapshot) => {
     if (snapshot.exists() && snapshot.val().expires > new Date().getTime()) {
       return res.status(400).send('Functions only update data that\'s older than 24 hours.');
     } else {
       const tomorrow: number = new Date().getTime() + 86400000;
       admin.storage().bucket().file('linkedin.html', {})
         .getSignedUrl({ action: 'read', expires: tomorrow })
         .then((url: string[]) => {
           if (url.length !== 1) return res.status(400).send('No profile found');
           httpRequest({ method: 'GET', url: url[0] }, (error: any, response: any, body: string) => {
             if (error) { return res.status(error.code).send(error.message); }
             inScrape.getProfile(body)
               .then((profile) => {
                 const regex: RegExp = RegExp('<img.*?alt="' + profile.name + '".*?src=".\/linkedin_files\/(.*?)"', 'g');
                 const images: string[] = regex.exec(body);
                 if (Array.isArray(images) && images.length > 0) { profile.photo = 'https://media.licdn.com/mpr/mpr/' + images[1]; }
                 if (profile.experience && Array.isArray(profile.experience)) { profile.experience = orderExperience(profile.experience); }
                 const result = {
                   results: profile,
                   expires: tomorrow
                 };
                 admin.database().ref('linkedin').set(result).then(() => res.send(JSON.stringify(result.results)));
               }).catch(err => res.status(400).send(err));
           });
         })
         .catch(error => res.status(400).send(error));
     }
   });
 });
開發者ID:MichaelSolati,項目名稱:ng-portfolio,代碼行數:30,代碼來源:linkedin.ts

示例7: Date

 .onCreate(async (snap: any, ctx: any) => {
   admin
     .database()
     .ref("write-test")
     .set({
       date: new Date(),
     });
 }),
開發者ID:firebase,項目名稱:firebase-tools,代碼行數:8,代碼來源:functionsEmulatorRuntime.spec.ts

示例8:

  .ref('/conversations/{conversationId}/messages/{messageId}').onCreate(event => {
    const value = event.data.val();
    const timestamp = Date.now() * -1;
    console.log(`server timestamp ${timestamp}`);
    value['.priority'] = timestamp;

    return admin.database()
      .ref(`/conversations/${event.params.conversationId}/messages/${event.data.key}`)
      .update(value);
});
開發者ID:aguacongas,項目名稱:chatle,代碼行數:10,代碼來源:index.ts

示例9: RegExp

 .then((profile) => {
   const regex: RegExp = RegExp('<img.*?alt="' + profile.name + '".*?src=".\/linkedin_files\/(.*?)"', 'g');
   const images: string[] = regex.exec(body);
   if (Array.isArray(images) && images.length > 0) { profile.photo = 'https://media.licdn.com/mpr/mpr/' + images[1]; }
   if (profile.experience && Array.isArray(profile.experience)) { profile.experience = orderExperience(profile.experience); }
   const result = {
     results: profile,
     expires: tomorrow
   };
   admin.database().ref('linkedin').set(result).then(() => res.send(JSON.stringify(result.results)));
 }).catch(err => res.status(400).send(err));
開發者ID:MichaelSolati,項目名稱:ng-portfolio,代碼行數:11,代碼來源:linkedin.ts


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