OverviewFilesCommitsIssuesDocsReleasesPeers

keet-cli / keet-core-4.14.4-pretty / lib / core / migrations / 8 / index.js

15 lines · javascript ref:
const o = require("hypercore-id-encoding")
module.exports = async function (e) {
  const t = new Map()
  for await (const { roomKey: n, file: c, cleared: i } of e.find("@local/blob-files")) {
    if (i) continue
    const e = c.pointer.externalBlob?.blob.byteLength
    if (!e) continue
    const l = o.encode(n)
    t.set(l, (t.get(l) ?? 0) + e)
  }
  const n = []
  for (const [c, i] of t) n.push(e.insert("@local/file-stats", { roomKey: o.decode(c), total: i }))
  await Promise.all(n)
}