1
1
import { conat } from "@cocalc/backend/conat" ;
2
2
import isCollaborator from "@cocalc/server/projects/is-collaborator" ;
3
3
import { patchesStreamName } from "@cocalc/conat/sync/synctable-stream" ;
4
- import { type Patch } from "@cocalc/conat/hub/api/sync" ;
4
+ import { type Patch , type HistoryInfo } from "@cocalc/conat/hub/api/sync" ;
5
+ import { client_db } from "@cocalc/util/db-schema/client-db" ;
5
6
6
7
export async function history ( {
7
8
account_id,
@@ -15,7 +16,7 @@ export async function history({
15
16
path : string ;
16
17
start_seq ?: number ;
17
18
end_seq ?: number ;
18
- } ) : Promise < { patches : Patch [ ] } > {
19
+ } ) : Promise < { patches : Patch [ ] ; info : HistoryInfo } > {
19
20
if ( ! account_id || ! ( await isCollaborator ( { account_id, project_id } ) ) ) {
20
21
throw Error ( "user must be collaborator on source project" ) ;
21
22
}
@@ -34,5 +35,18 @@ export async function history({
34
35
} ) ) {
35
36
patches . push ( patch as any ) ;
36
37
}
37
- return { patches } ;
38
+
39
+ const akv = client . sync . akv ( {
40
+ name : `__dko__syncstrings:${ client_db . sha1 ( project_id , path ) } ` ,
41
+ project_id,
42
+ noInventory : true ,
43
+ } ) ;
44
+ const keys = await akv . keys ( ) ;
45
+ const info : Partial < HistoryInfo > = { } ;
46
+ for ( const key of keys ) {
47
+ if ( key [ 0 ] != "[" ) continue ;
48
+ info [ JSON . parse ( key ) [ 1 ] ] = await akv . get ( key ) ;
49
+ }
50
+
51
+ return { patches, info : info as HistoryInfo } ;
38
52
}
0 commit comments