Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save xErik/7f2d5090b28dbe0a2528f0ac4875227a to your computer and use it in GitHub Desktop.
Save xErik/7f2d5090b28dbe0a2528f0ac4875227a to your computer and use it in GitHub Desktop.
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