DearDesi / deardesi

The DIY blog platform for normal people
http://dear.desi
Apache License 2.0
6 stars 1 forks source link

Browser Firebase Adapter #26

Open coolaj86 opened 9 years ago

coolaj86 commented 9 years ago

Looking through the API this seems very possible.

dependencies: firebase, gzip-js, tar-js, deflate-js, crc32

the tar / gzip stuff may need some arraybuffer updates, but I don't think it'll be too bad actually.

coolaj86 commented 9 years ago

Porting the node lib...

var email = 'coolaj86@gmail.com';
var password = 'supersecretsauce';

$.ajax({
  type: 'GET'
, url: 'https://admin.firebase.com/account/login'
, data: {
    email: email
  , password: password
  , rememberMe: true
  , cli: "1.1.6"
  }
}).then(function (body) {
  console.log('body', body); // only adminToken

  var firebasename = 'desi';
  return $.ajax({
    type: 'GET'
  , url: 'https://admin.firebase.com/firebase/' + firebasename + '/token'
  , data: { token: body.adminToken }
  }).then(function (tokens) {
    console.log(tokens.firebaseToken);
    console.log(tokens.personalToken);
  });
});

Once the Tar is working it should be pretty easy to implement this:

671         var firebaseRef = new Firebase(api.realtimeUrl.replace(/\/\//, '//firebase.'));
672         firebaseRef.authWithCustomToken(tokens.firebaseToken, function(error, result) {
673           if (error) {
674             console.log('Firebase authentication failed!');
675             process.exit(1);
676           }
677         });
678         var directoryRef = firebaseRef
679                 .child('hosting/versions')
680                 .child(settings.firebase) // firebasename
681                 .push();

  var directoryRef = firebaseRef
679                 .child('hosting/versions')
680                 .child(settings.firebase)
681                 .push();

292     upload.send(settings.firebase, settings.public, settings.ignore, directoryRef.key(), message, handleFailedDeploy('Couldn    \'t upload site'));

 83       var params = ['id=' + encodeURIComponent(pushId), 'fileCount=' + fileCount, 'token=' + auth.token];
 84       if (message) {
 85         params.push('message=' + encodeURIComponent(message));
 86       }
 87       var url = api.uploadUrl + '/upload/' + firebase + '?' + params.join('&');

 90       var r = request.put({
 91         url: url,
 92         json: true
 93       }, function(err, response, body) {
 94         var failed = (err || !body || body.error);
 95         setTimeout(callback, 0, failed, body && body.directory);
 96       });
 97       var form = r.form();
 98       form.append('site', bufferStream, {
 99         filename: 'site.tar.gz',
100         contentType: 'application/x-gzip',
101         knownLength: tarballSize
102       });
103     });

  5 var api = {
  6   realtimeUrl: 'https://firebaseio.com',
  7   adminUrl: 'https://admin.firebase.com',
  8   uploadUrl: 'https://hosting.firebase.com',
  9   hostingUrl: 'https://firebaseapp.com',

https://www.firebase.com/docs/hosting/guide/custom-domain.html