about summary refs log tree commit diff
path: root/app/javascript/mastodon/storage/db.js
blob: 377a792a7decaf3f375a1df763f361633300c5b5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
export default () => new Promise((resolve, reject) => {
  // ServiceWorker is required to synchronize the login state.
  // Microsoft Edge 17 does not support getAll according to:
  // Catalog of standard and vendor APIs across browsers - Microsoft Edge Development
  // https://developer.microsoft.com/en-us/microsoft-edge/platform/catalog/?q=specName%3Aindexeddb
  if (!('caches' in self && 'getAll' in IDBObjectStore.prototype)) {
    reject();
    return;
  }

  const request = indexedDB.open('mastodon');

  request.onerror = reject;
  request.onsuccess = ({ target }) => resolve(target.result);

  request.onupgradeneeded = ({ target }) => {
    const accounts = target.result.createObjectStore('accounts', { autoIncrement: true });
    const statuses = target.result.createObjectStore('statuses', { autoIncrement: true });

    accounts.createIndex('id', 'id', { unique: true });
    accounts.createIndex('moved', 'moved');

    statuses.createIndex('id', 'id', { unique: true });
    statuses.createIndex('account', 'account');
    statuses.createIndex('reblog', 'reblog');
  };
});