Skip to content

Instantly share code, notes, and snippets.

View jefBinomed's full-sized avatar

Jean-François Garreau - Binomed jefBinomed

View GitHub Profile
@jefBinomed
jefBinomed / firestore.rules.js
Created November 30, 2018 16:13
2018-countdown-security-firestore
service cloud.firestore {
match /databases/{database}/documents {
// Generic method that checks if the email of the currently authenticated user is contained in the admin collection
function isAdmin() {
return request.auth != null
&& get(/databases/$(database)/documents/admins/adminList).data[request.auth.token.email] == true
&& request.auth.token.email_verified == true;
}
// The admin collection is in read only for the admins
@jefBinomed
jefBinomed / model-tree.js
Created November 30, 2018 16:12
2018-countdown-model-tree
// Collection 'admins'
{
adminList: {
[email protected]: true,
[email protected]: true
}
}
// Collection 'planets'
{
@jefBinomed
jefBinomed / admin-check.js
Created November 30, 2018 16:11
2018-countdown-admincheck
// Mount method of my CountDown component
mounted() {
firestore.collection("admins").get('adminList')
.then(()=>{
// console.debug('Admin Loggued :)');
})
.catch((error) =>{
// eslint-disable-next-line no-console
console.error(error);
this.$router.push('/')
@jefBinomed
jefBinomed / router.js
Created November 30, 2018 16:10
2018-countdown-router
const secureRoute = (to, from, next) => {
const currentRoute = to.path;
if (from.path === '/wait') {
next();
}else {
next('/wait');
firebase.auth().onAuthStateChanged((user) => {
if(user) {
next(currentRoute);
} else {
@jefBinomed
jefBinomed / package.json.js
Created November 30, 2018 16:09
2018-countdown-packagevue
{
"name": "countdowndevfest2018",
"version": "1.0.0",
"description": "CountDown game for DevFest Nantes 2018",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"vue": "vue",
"serve": "vue-cli-service serve",
"clean": "del-cli dist/*",
"build": "npm run clean && vue-cli-service build && npm run cp-assets",
@jefBinomed
jefBinomed / update-tree.js
Created November 30, 2018 15:59
2018-countdown-update-tree
function updateTree(userId, drawId, result) {
return new Promise((resolve, reject) => {
admin.database().ref(`/drawUpload/${drawId}`).once('value', (snapshot) => {
try {
// prepare to update the tree
if (snapshot && snapshot.val()) {
let snapshotFb = snapshot.val();
// Update the drawing with the classifications
snapshotFb.tags = extractTags(result);
// Add the drawing in a new part of tree
@jefBinomed
jefBinomed / cloud-function.js
Created November 30, 2018 15:58
2018-countdown-cloudfunction
/**
* Method trigger when an image is upload
*/
exports.detectImage = functions.storage.object().onChange(event => {
const object = event.data; // The Storage object.
const fileBucket = object.bucket; // The Storage bucket that contains the file.
const filePath = object.name; // File path in the bucket.
const contentType = object.contentType; // File content type.
const resourceState = object.resourceState; // The resourceState is 'exists' or 'not_exists' (for file/folder deletions).
@jefBinomed
jefBinomed / package.json.js
Created November 30, 2018 15:56
2018-countdown-package-draw
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"dependencies": {
// Use for the cloud storage
"@google-cloud/storage": "^1.4.0",
// A wrapper to use child_process in promise
"child-process-promise": "^2.2.1",
// Use for manipulating the realtime database
"firebase-admin": "~5.2.1",
@jefBinomed
jefBinomed / video-player.js
Created November 30, 2018 15:54
2018-countdown-videoplayer
'use strict'
/**
* Class for playing video
*
*/
export class VideoPlayer {
constructor(parentElt, callBackEnd) {
this.videoElt = document.createElement('video');
parentElt.appendChild(this.videoElt);
@jefBinomed
jefBinomed / audio-player.js
Created November 30, 2018 15:52
2018-countdown-player-audio-es6-0
'use strict'
import {
PLAYLIST
} from './playlist.js';
/**
* Class for playing music
*
* We create an invisible audio element and we play music on it
*/