Skip to content

Instantly share code, notes, and snippets.

@zephraph
Last active August 11, 2021 04:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zephraph/73d72277c9a43a5baecb6f43925b8494 to your computer and use it in GitHub Desktop.
Save zephraph/73d72277c9a43a5baecb6f43925b8494 to your computer and use it in GitHub Desktop.
Exporting indexdb files from riverside.fm
// This script is adapted from david fahlander's post: https://dfahlander.medium.com/export-indexeddb-from-a-web-app-using-devtools-62c55a8996a1
// You should be able to drop this in the console on a riverside.fm page once you're logged in.
// Find the indexdb table name that you want to import by 2. Include dexie-export-import into the page.
const dbName = 'export-db'
const loadScript = src =>
new Promise(resolve => {
let script = document.createElement('script')
script.src = src;
script.onload = resolve;
document.body.appendChild(script);
})
await loadScript('https://unpkg.com/dexie');
await loadScript('https://unpkg.com/dexie-export-import');
let db = new Dexie(dbName);
const { verno, tables } await db.open();
db.close();
db = new Dexie(dbName);
db.version(verno).stores(tables.reduce((p,c) => {
p[c.name] = c.schema.primKey.keyPath || "";
return p;
}, {}));
const blob = await db.export({
numRowsPerChunk: 2 // This is important because riverside's rows can be 4mb and dexie's default is 2k rows which will absolutely crash the browser
});
document.body.innerHTML = `
<a href=’${URL.createObjectURL(blob)}’>Right-click to download database export</a>
`
// paste into console on any riverside.fm page
// drag file into box to upload
const dbName = 'import-db'
const loadScript = src =>
new Promise(resolve => {
let script = document.createElement('script')
script.src = src;
script.onload = resolve;
document.body.appendChild(script);
})
await loadScript('https://unpkg.com/dexie');
await loadScript('https://unpkg.com/dexie-export-import');
let db = new Dexie('dbName');
const dropZone = document.createElement('div');
dropZone.setAttribute('style', `
width: 600px;
height: 20px;
border: 2px dotted #bbb;
border-radius: 10px;
padding: 35px;
color: #bbb;
text-align: center;
`)
dropZone.textContent = "Drop your dexie recording here"
dropZone.ondragover = event => {
event.stopPropagation();
event.preventDefault();
event.dataTransfer.dropEffect = 'copy';
};
dropZone.ondrop = async event => {
event.stopPropagation();
event.preventDefault();
const recording = event.dataTransfer.files[0];
if (!recording) throw new Error('Must drop recording');
await db.delete();
db = await Dexie.import(recording, {
progressCallback({ totalRows, completedRows }) {
console.log(`${Math.floor(completedRows/totalRows * 100)}%`)
}
});
console.log("Import finished");
}
document.body.replaceWith(dropZone)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment