mirror of
https://github.com/outline/outline.git
synced 2026-11-22 05:51:43 +03:00
47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
import { flatten } from "es-toolkit/compat";
|
|
import {
|
|
MultiplayerEntityType,
|
|
toMultiplayerName,
|
|
} from "@shared/collaboration/EntityName";
|
|
import stores from "~/stores";
|
|
import { flattenTree } from "@shared/utils/tree";
|
|
|
|
/**
|
|
* Delete all databases in the browser.
|
|
*
|
|
* @returns A promise that resolves when all databases have been deleted.
|
|
*/
|
|
export async function deleteAllDatabases() {
|
|
if (!window.indexedDB) {
|
|
return;
|
|
}
|
|
|
|
if ("databases" in window.indexedDB) {
|
|
const databases = await window.indexedDB.databases();
|
|
|
|
for (const database of databases) {
|
|
if (database.name) {
|
|
window.indexedDB.deleteDatabase(database.name);
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
|
|
// If the browser does not support listing databases, we need to manually delete as best we can
|
|
// by iterating over all known collections and documents.
|
|
await Promise.all(
|
|
stores.collections.orderedData.map(async (collection) => {
|
|
window.indexedDB.deleteDatabase(
|
|
toMultiplayerName(MultiplayerEntityType.Collection, collection.id)
|
|
);
|
|
const nodes = flatten(collection.documents?.map(flattenTree));
|
|
|
|
return nodes.map(async (node) => {
|
|
window.indexedDB.deleteDatabase(
|
|
toMultiplayerName(MultiplayerEntityType.Document, node.id)
|
|
);
|
|
});
|
|
})
|
|
);
|
|
}
|