No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

57 líneas
1.1 KiB

  1. define([
  2. 'google-spreadsheet',
  3. './creds'
  4. ], function (
  5. googleSheets,
  6. creds
  7. ) {
  8. return {
  9. doc: null,
  10. sheet: null,
  11. records: null,
  12. init: function () {
  13. this.doc = new googleSheets('1PhNFF8IbNX7uecFeWkFsoTZgDfLF-zWVibOTuutNy8c');
  14. this.doc.useServiceAccountAuth(creds, this.onAuth.bind(this));
  15. },
  16. onAuth: function () {
  17. this.doc.getInfo(this.onGetInfo.bind(this));
  18. },
  19. onGetInfo: function () {
  20. this.sheet = this.doc.worksheets[0];
  21. this.update();
  22. },
  23. getRecord: function (name) {
  24. return (this.records || []).find(r => (r.username == name));
  25. },
  26. onGetRows: function (err, rows) {
  27. this.records = rows.map(function (r) {
  28. var o = {};
  29. Object.keys(r).forEach(function (p) {
  30. if (['id', 'app:edited', '_links', '_xml', 'save', 'del'].indexOf(p) > -1)
  31. return;
  32. o[p] = r[p];
  33. });
  34. o.items = JSON.parse(o.items);
  35. o.skins = JSON.parse(o.skins);
  36. return o;
  37. });
  38. setTimeout(this.update.bind(this), 10000)
  39. },
  40. update: function () {
  41. this.sheet.getRows({}, this.onGetRows.bind(this));
  42. }
  43. };
  44. });