Last active
November 22, 2018 19:39
-
-
Save alvarowolfx/a58774867f39570ca8bd27cbcb631a11 to your computer and use it in GitHub Desktop.
Google Cloud OTA Update Post - InsertBQ
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
const path = require( 'path' ) | |
/** | |
* Generic background Cloud Function to be triggered by Cloud Storage. | |
* | |
* @param {object} data The event payload. | |
* @param {object} context The event metadata. | |
*/ | |
exports.insertFirmwaresOnBigquery = ( data, context ) => { | |
const file = data; | |
const filename = path.basename( file.name ) | |
const ext = path.extname( filename ) | |
if ( ext !== '.bin' ) { | |
console.log( 'Not a firmware file.' ) | |
return 'ok' | |
} | |
const filenameWithoutExt = path.basename( file.name, ext ) | |
const dir = path.dirname( file.name ) | |
const version = dir.split( '/' ).pop() | |
const variant = filenameWithoutExt.split( '_' ).pop() | |
const row = { | |
id : context.eventId, | |
bucket : file.bucket, | |
version, | |
fullname : file.name, | |
filename, | |
variant, | |
createdAt : file.timeCreated, | |
eventType : context.eventType, | |
} | |
console.log( 'Row to insert', row ) | |
return insertIntoBigquery( row ) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment