Added docs idb proxy.
Some checks are pending
Check SPDX-License-Identifier / check-spdx-license-id (push) Waiting to run
Check copyright year / check_copyright_year (push) Waiting to run
Publish Docker image (develop) / Build (linux/amd64) (push) Waiting to run
Publish Docker image (develop) / Build (linux/arm64) (push) Waiting to run
Publish Docker image (develop) / merge (push) Blocked by required conditions
Dockle / dockle (push) Waiting to run
Lint / pnpm_install (push) Waiting to run
Lint / lint (backend) (push) Blocked by required conditions
Lint / lint (frontend) (push) Blocked by required conditions
Lint / lint (frontend-embed) (push) Blocked by required conditions
Lint / lint (frontend-shared) (push) Blocked by required conditions
Lint / lint (misskey-bubble-game) (push) Blocked by required conditions
Lint / lint (misskey-js) (push) Blocked by required conditions
Lint / lint (misskey-reversi) (push) Blocked by required conditions
Lint / lint (sw) (push) Blocked by required conditions
Lint / typecheck (backend) (push) Blocked by required conditions
Lint / typecheck (misskey-js) (push) Blocked by required conditions
Lint / typecheck (sw) (push) Blocked by required conditions
Storybook / build (push) Waiting to run
Test (frontend) / vitest (20.16.0) (push) Waiting to run
Test (frontend) / e2e (chrome, 20.16.0) (push) Waiting to run
Test (production install and build) / production (20.16.0) (push) Waiting to run
Some checks are pending
Check SPDX-License-Identifier / check-spdx-license-id (push) Waiting to run
Check copyright year / check_copyright_year (push) Waiting to run
Publish Docker image (develop) / Build (linux/amd64) (push) Waiting to run
Publish Docker image (develop) / Build (linux/arm64) (push) Waiting to run
Publish Docker image (develop) / merge (push) Blocked by required conditions
Dockle / dockle (push) Waiting to run
Lint / pnpm_install (push) Waiting to run
Lint / lint (backend) (push) Blocked by required conditions
Lint / lint (frontend) (push) Blocked by required conditions
Lint / lint (frontend-embed) (push) Blocked by required conditions
Lint / lint (frontend-shared) (push) Blocked by required conditions
Lint / lint (misskey-bubble-game) (push) Blocked by required conditions
Lint / lint (misskey-js) (push) Blocked by required conditions
Lint / lint (misskey-reversi) (push) Blocked by required conditions
Lint / lint (sw) (push) Blocked by required conditions
Lint / typecheck (backend) (push) Blocked by required conditions
Lint / typecheck (misskey-js) (push) Blocked by required conditions
Lint / typecheck (sw) (push) Blocked by required conditions
Storybook / build (push) Waiting to run
Test (frontend) / vitest (20.16.0) (push) Waiting to run
Test (frontend) / e2e (chrome, 20.16.0) (push) Waiting to run
Test (production install and build) / production (20.16.0) (push) Waiting to run
This commit is contained in:
parent
9fa011c6e0
commit
38576a80b4
|
@ -26,6 +26,7 @@ if (window.Cypress) {
|
||||||
console.log('Cypress detected. It will use localStorage.');
|
console.log('Cypress detected. It will use localStorage.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check for the availability of indexedDB.
|
||||||
if (idbAvailable) {
|
if (idbAvailable) {
|
||||||
await iset('idb-test', 'test')
|
await iset('idb-test', 'test')
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
|
@ -37,16 +38,36 @@ if (idbAvailable) {
|
||||||
console.error('indexedDB is unavailable. It will use localStorage.');
|
console.error('indexedDB is unavailable. It will use localStorage.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a value from indexedDB (or localStorage as a fallback).
|
||||||
|
*
|
||||||
|
* @param key The key of the item to retrieve.
|
||||||
|
*
|
||||||
|
* @returns The value of the item.
|
||||||
|
*/
|
||||||
export async function get(key: string) {
|
export async function get(key: string) {
|
||||||
if (idbAvailable) return iget(key);
|
if (idbAvailable) return iget(key);
|
||||||
return miLocalStorage.getItemAsJson(`${PREFIX}${key}`);
|
return miLocalStorage.getItemAsJson(`${PREFIX}${key}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a value in indexedDB (or localStorage as a fallback).
|
||||||
|
*
|
||||||
|
* @param {string} key - The key of the item to set.
|
||||||
|
* @param {any} val - The value of the item to set.
|
||||||
|
* @returns {Promise<void>} - A promise that resolves when the value has been set.`
|
||||||
|
*/
|
||||||
export async function set(key: string, val: any) {
|
export async function set(key: string, val: any) {
|
||||||
if (idbAvailable) return iset(key, val);
|
if (idbAvailable) return iset(key, val);
|
||||||
return miLocalStorage.setItemAsJson(`${PREFIX}${key}`, val);
|
return miLocalStorage.setItemAsJson(`${PREFIX}${key}`, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a value from indexedDB (or localStorage as a fallback).
|
||||||
|
*
|
||||||
|
* @param {string} key - The key of the item to delete.
|
||||||
|
* @returns {Promise<void>} - A promise that resolves when the value has been deleted.
|
||||||
|
*/
|
||||||
export async function del(key: string) {
|
export async function del(key: string) {
|
||||||
if (idbAvailable) return idel(key);
|
if (idbAvailable) return idel(key);
|
||||||
return miLocalStorage.removeItem(`${PREFIX}${key}`);
|
return miLocalStorage.removeItem(`${PREFIX}${key}`);
|
||||||
|
|
Loading…
Reference in a new issue