android.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* global window, navigator */
  2. window.LIMITS = {
  3. ANON: {
  4. MAX_FILE_SIZE: 1024 * 1024 * 1024 * 2,
  5. MAX_DOWNLOADS: 20,
  6. MAX_EXPIRE_SECONDS: 86400
  7. },
  8. MAX_FILE_SIZE: 1024 * 1024 * 1024 * 2,
  9. MAX_DOWNLOADS: 200,
  10. MAX_EXPIRE_SECONDS: 604800,
  11. MAX_FILES_PER_ARCHIVE: 64,
  12. MAX_ARCHIVES_PER_USER: 16
  13. };
  14. window.DEFAULTS = {
  15. DOWNLOAD_COUNTS: [1, 2, 3, 4, 5, 20, 50, 100, 200],
  16. EXPIRE_TIMES_SECONDS: [300, 3600, 86400, 604800],
  17. EXPIRE_SECONDS: 3600
  18. };
  19. import choo from 'choo';
  20. import html from 'choo/html';
  21. import Raven from 'raven-js';
  22. import { setApiUrlPrefix } from '../app/api';
  23. import metrics from '../app/metrics';
  24. //import assets from '../common/assets';
  25. import Archive from '../app/archive';
  26. import Header from '../app/ui/header';
  27. import storage from '../app/storage';
  28. import controller from '../app/controller';
  29. import User from './user';
  30. import intents from './stores/intents';
  31. import home from './pages/home';
  32. import upload from './pages/upload';
  33. import share from './pages/share';
  34. import preferences from './pages/preferences';
  35. import error from './pages/error';
  36. import { getTranslator } from '../app/locale';
  37. if (navigator.userAgent === 'Send Android') {
  38. setApiUrlPrefix('https://send2.dev.lcip.org');
  39. }
  40. const app = choo();
  41. //app.use(state);
  42. app.use(controller);
  43. app.use(intents);
  44. function body(main) {
  45. return function(state, emit) {
  46. /*
  47. Disable the preferences menu for now since it is ugly and isn't
  48. relevant to the beta
  49. function clickPreferences(event) {
  50. event.preventDefault();
  51. emit('pushState', '/preferences');
  52. }
  53. const menu = html`<a
  54. id="hamburger"
  55. class="absolute pin-t pin-r z-50"
  56. href="#"
  57. onclick="${clickPreferences}"
  58. >
  59. <img src="${assets.get('preferences.png')}" />
  60. </a>`;
  61. */
  62. return html`
  63. <body
  64. class="flex flex-col items-center font-sans bg-grey-lightest h-screen"
  65. >
  66. ${state.cache(Header, 'header').render()} ${main(state, emit)}
  67. </body>
  68. `;
  69. };
  70. }
  71. (async function start() {
  72. const translate = await getTranslator('en-US');
  73. app.use((state, emitter) => {
  74. state.translate = translate;
  75. state.capabilities = {
  76. account: true
  77. }; //TODO
  78. state.archive = new Archive();
  79. state.storage = storage;
  80. state.user = new User(storage);
  81. state.raven = Raven;
  82. window.finishLogin = async function(accountInfo) {
  83. await state.user.finishLogin(accountInfo);
  84. await state.user.syncFileList();
  85. emitter.emit('replaceState', '/');
  86. };
  87. // for debugging
  88. window.appState = state;
  89. window.appEmit = emitter.emit.bind(emitter);
  90. });
  91. app.use(metrics);
  92. app.route('/', body(home));
  93. app.route('/upload', upload);
  94. app.route('/share/:id', share);
  95. app.route('/preferences', preferences);
  96. app.route('/error', error);
  97. //app.route('/debugging', require('./pages/debugging').default);
  98. // add /api/filelist
  99. app.mount('body');
  100. })();