Path: blob/master/src/packages/sync/editor/generic/export.ts
1450 views
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { SortedPatchList } from "./sorted-patch-list";6import { Patch } from "./types";78export interface HistoryEntry {9time_utc: Date;10account_id: string;11patch?: any[];12patch_length?: number;13}1415export interface HistoryExportOptions {16patches?: boolean;17patch_lengths?: boolean; // length of each patch (some measure of amount changed)18}1920export function export_history(21account_ids: string[],22patch_list: SortedPatchList,23options: HistoryExportOptions,24): HistoryEntry[] {25const patches: Patch[] = patch_list.export();26const entries: HistoryEntry[] = [];27for (const x of patches) {28const time_utc = new Date(x.time);29let account_id = account_ids[x.user_id];30if (account_id == null) {31account_id = "unknown"; // should never happen...32}33const entry: HistoryEntry = { time_utc, account_id };34if (options.patches) {35entry.patch = x.patch;36}37if (options.patch_lengths) {38entry.patch_length = JSON.stringify(x.patch).length;39}40entries.push(entry);41}42return entries;43}444546