Last active
September 21, 2019 11:03
-
-
Save xErik/7f2d5090b28dbe0a2528f0ac4875227a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functions = require('firebase-functions'); | |
import fs = require('fs'); | |
import os = require('os'); | |
import path = require('path'); | |
const admin = require('firebase-admin'); | |
admin.initializeApp(); | |
const bucket = admin.storage().bucket(); | |
export const textToSpeechRequest = functions.https.onCall((data: any, context: any) => { | |
const destName = 'test.txt'; | |
const tempFile = path.join(os.tmpdir(), destName); | |
return new Promise((resolve, reject) => { | |
fs.writeFile(tempFile, "Hey there!", function(err) { | |
if (err) { | |
console.log(err); | |
reject(`error_write_tmp: ${tempFile}`); | |
} | |
console.log(tempFile, destName); | |
return bucket.upload(tempFile, { destination: destName }) | |
.then(() => { | |
resolve({ | |
query:data, | |
answer:destName | |
}); | |
}).catch((err1: any) => { | |
reject('Failed to upload: ' + JSON.stringify(err1)); | |
}); | |
}); | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment