Created
August 7, 2020 13:43
-
-
Save ForceTower/4e84982b4c71487741780b92cf3067f8 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 * as functions from "firebase-functions" | |
import * as moment from "moment" | |
const messages = [ | |
{ | |
message: "Bom dia", | |
attachments: [ | |
{ | |
name: "bom dia", | |
source: | |
"https://www.mensagensdebomdia.com.br/wp-content/uploads/2020/01/77B38E74-EE06-4EB2-8A63-9031E494337C.jpeg", | |
type: "image" | |
} | |
] | |
}, | |
{ | |
message: "Olá família", | |
attachments: [] | |
}, | |
{ | |
message: "Nossa! O mundo acabou de virar quadrado!", | |
attachments: [] | |
}, | |
{ | |
message: "Qual seu nome?", | |
attachments: [] | |
}, | |
{ | |
message: "Eu sou o Geralt, Geralt de Rívia!", | |
attachments: [ | |
{ | |
name: "minha foto", | |
source: | |
"https://meups.com.br/wp-content/uploads/2018/03/the-witcher-3-900x503.jpg", | |
type: "image" | |
} | |
] | |
}, | |
{ | |
message: "Olha só que incrivel esse artigo sobre o android", | |
attachments: [ | |
{ | |
name: "um bom PDF", | |
source: | |
"https://d1wqtxts1xzle7.cloudfront.net/30551848/andoid--tech.pdf?1360332915=&response-content-disposition=inline%3B+filename%3DWhat_is_Android.pdf&Expires=1596807421&Signature=M38O4FHscXLe~~pJ7idOuCy~IcasfmxN2AkFC5AUhvVG2XS3YlTtBw2azUtqvi31KKAW745vLRrTvDJkWmEGltl152B0sTmEYzy3vbY-2X6ooX50CeaHfOpPcGj~LrOQSxtCDKq5~8yY0S0UAKU8rw2F0cDju~m7e07YmuYsQ3LVmLthkZzJfqHmrcWIq5exHRjWf-SqERVF04ziVPZ0pJr0wz5iMmkTXakgzDOIplmVEEI1WI1Ugb3CxQgDcySgPDox~CgjsLp1z5EmQZTWxmf~5L49zo~0UAJb3ZG9XKscsP4LAXQuSVIltDkeqbKEfSAvyR4wbXGl3IMm3jTnew__&Key-Pair-Id=APKAJLOHF5GGSLRBV4ZA", | |
type: "pdf" | |
} | |
] | |
}, | |
{ | |
message: "as fotos da viagem estão otimas!", | |
attachments: [ | |
{ | |
name: "", | |
source: | |
"https://images.unsplash.com/photo-1572137675491-20aee8014ce4?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=634&q=80", | |
type: "image" | |
}, | |
{ | |
name: "", | |
source: | |
"https://images.unsplash.com/photo-1596787071179-fbbcd89cc2d2?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1267&q=80", | |
type: "image" | |
}, | |
{ | |
name: "", | |
source: | |
"https://images.unsplash.com/photo-1596785236414-3b235f4ff58a?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=634&q=80", | |
type: "image" | |
} | |
] | |
}, | |
{ | |
message: "Esse café ta lindo!", | |
attachments: [ | |
{ | |
name: "", | |
source: | |
"https://images.unsplash.com/photo-1594306410309-c4d6f85405ba?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=675&q=80", | |
type: "image" | |
} | |
] | |
}, | |
{ | |
message: | |
"Finalmente saiu o bugfix do paging! https://developer.android.com/jetpack/androidx/releases/paging?hl=en", | |
attachments: [] | |
}, | |
{ | |
message: "pyke é roubado!", | |
attachments: [] | |
}, | |
{ | |
message: | |
"uhhh duhhhh wiiiind waalll. wind walllll wind waaaallll. oohhh duuuuuuh", | |
attachments: [] | |
}, | |
{ | |
message: "three guns means never having to say i'm sorry", | |
attachments: [] | |
}, | |
{ | |
message: "lulu w, lulu double youuuuuu, uhhh duuuhhh", | |
attachments: [] | |
}, | |
{ | |
message: "nice skill dude! nice flash R", | |
attachments: [] | |
}, | |
{ | |
message: "stay mad", | |
attachments: [] | |
}, | |
{ | |
message: "Seu pagamento de R$ 64,80 foi confirmado.", | |
attachments: [] | |
}, | |
{ | |
message: "boleto chega para qualquer um!", | |
attachments: [] | |
}, | |
{ | |
message: "você é um NPC!", | |
attachments: [] | |
}, | |
{ | |
message: "Nossa, que ofensivo...", | |
attachments: [] | |
}, | |
{ | |
message: "conte-me mais...", | |
attachments: [] | |
}, | |
{ | |
message: | |
"Não deixe de se registrar para o AWSome Day Brasil - Conferência Online!", | |
attachments: [] | |
}, | |
{ | |
message: | |
"Vá nas casas bahia e compre uma Tv maior que a envergadura das suas costas!", | |
attachments: [] | |
}, | |
{ | |
message: "nada mais a dizer", | |
attachments: [] | |
} | |
] | |
const users = [ | |
{ | |
id: 1, | |
name: "Super Bot", | |
avatar: | |
"https://image.freepik.com/vetores-gratis/icone-do-robo-design-de-sinal-de-bot-conceito-de-simbolo-de-chatbot-servico-de-suporte-por-voz-bot-bot-de-suporte-on-line-estoque-ilustracao-vetorial_100456-34.jpg" | |
}, | |
{ | |
id: 2, | |
name: "Mario Bros", | |
avatar: | |
"https://veja.abril.com.br/wp-content/uploads/2016/06/alx_entretenimento-video-game-nintendo-mario-20141212-63-2_original.jpeg" | |
}, | |
{ | |
id: 3, | |
name: "Playstation", | |
avatar: | |
"https://s2.glbimg.com/T1gLl5Vy-Ve9A4S9Nq6ZZKomyP4=/0x0:1000x560/984x0/smart/filters:strip_icc()/i.s3.glbimg.com/v1/AUTH_59edd422c0c84a879bd37670ae4f538a/internal_photos/bs/2019/b/F/HxBxYlRIiIdsNcyhcUMQ/playsatation.jpg" | |
} | |
] | |
const shuffle = (elements: Array<any>) => { | |
const array = [...elements] | |
let currentIndex = array.length, | |
temporaryValue, | |
randomIndex | |
while (0 !== currentIndex) { | |
randomIndex = Math.floor(Math.random() * currentIndex) | |
currentIndex -= 1 | |
temporaryValue = array[currentIndex] | |
array[currentIndex] = array[randomIndex] | |
array[randomIndex] = temporaryValue | |
} | |
return array | |
} | |
export const fetchMessages = functions.https.onRequest((request, response) => { | |
const page = parseInt(request.query.page?.toString() ?? "1", 10) - 1 | |
const limit = 10 | |
const values = shuffle(messages) | |
.slice(0, limit) | |
.map((it, index) => { | |
const next = moment() | |
.add(page * -1, "days") | |
.add(index * -1, "hour") | |
return { | |
id: page * 10 + (index + 1), | |
...it, | |
user: shuffle(users)[0], | |
createdAt: next | |
} | |
}) | |
response.json({ | |
message: "ok", | |
data: values | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment