闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
1.1 KiB

  1. export default () => new Promise((resolve, reject) => {
  2. // ServiceWorker is required to synchronize the login state.
  3. // Microsoft Edge 17 does not support getAll according to:
  4. // Catalog of standard and vendor APIs across browsers - Microsoft Edge Development
  5. // https://developer.microsoft.com/en-us/microsoft-edge/platform/catalog/?q=specName%3Aindexeddb
  6. if (!('caches' in self && 'getAll' in IDBObjectStore.prototype)) {
  7. reject();
  8. return;
  9. }
  10. const request = indexedDB.open('mastodon');
  11. request.onerror = reject;
  12. request.onsuccess = ({ target }) => resolve(target.result);
  13. request.onupgradeneeded = ({ target }) => {
  14. const accounts = target.result.createObjectStore('accounts', { autoIncrement: true });
  15. const statuses = target.result.createObjectStore('statuses', { autoIncrement: true });
  16. accounts.createIndex('id', 'id', { unique: true });
  17. accounts.createIndex('moved', 'moved');
  18. statuses.createIndex('id', 'id', { unique: true });
  19. statuses.createIndex('account', 'account');
  20. statuses.createIndex('reblog', 'reblog');
  21. };
  22. });