@@ -50,10 +50,7 @@ function getDebouncedCallback(key) {
5050 return debounceRegistry . get ( key ) ;
5151}
5252
53- // FIXME hard-coded path.
54- const blobDir = "/tmp/example-repo" ;
55-
56- async function handleSaveBlob ( { repoId, yDocBlob } ) {
53+ async function handleSaveBlob ( { repoId, yDocBlob, blobDir } ) {
5754 console . log ( "save blob" , repoId , yDocBlob . length ) ;
5855 // create the yjs-blob folder if not exists
5956 if ( ! fs . existsSync ( blobDir ) ) {
@@ -67,7 +64,7 @@ async function handleSaveBlob({ repoId, yDocBlob }) {
6764 * This function is called when setting up the WS connection, after the loadFromCodePod step.
6865 * TODO need to make sure this is only called once per repo, regardless of how many users are connected later.
6966 */
70- function setupObserversToDB ( ydoc : Y . Doc , repoId : string ) {
67+ function setupObserversToDB ( ydoc : Y . Doc , repoId : string , blobDir : string ) {
7168 console . log ( "setupObserversToDB for repo" , repoId ) ;
7269 // just observe and save the entire doc
7370 function observer ( _ , transaction ) {
@@ -82,7 +79,7 @@ function setupObserversToDB(ydoc: Y.Doc, repoId: string) {
8279 // FIXME it may be too expensive to update the entire doc.
8380 // FIXME history is discarded
8481 const update = Y . encodeStateAsUpdate ( ydoc ) ;
85- handleSaveBlob ( { repoId, yDocBlob : Buffer . from ( update ) } ) ;
82+ handleSaveBlob ( { repoId, yDocBlob : Buffer . from ( update ) , blobDir } ) ;
8683 } ) ;
8784 }
8885 const rootMap = ydoc . getMap ( "rootMap" ) ;
@@ -101,7 +98,7 @@ function setupObserversToDB(ydoc: Y.Doc, repoId: string) {
10198/**
10299 * This function is called when setting up the WS connection, as a first step.
103100 */
104- async function loadFromFS ( ydoc : Y . Doc , repoId : string ) {
101+ async function loadFromFS ( ydoc : Y . Doc , repoId : string , blobDir : string ) {
105102 // load from the database and write to the ydoc
106103 console . log ( "=== loadFromFS" ) ;
107104 // read the blob from file system
@@ -124,11 +121,11 @@ async function loadFromFS(ydoc: Y.Doc, repoId: string) {
124121 }
125122}
126123
127- export async function bindState ( doc : Y . Doc , repoId : string ) {
124+ export async function bindState ( doc : Y . Doc , repoId : string , blobDir : string ) {
128125 // Load persisted document state from the database.
129- await loadFromFS ( doc , repoId ) ;
126+ await loadFromFS ( doc , repoId , blobDir ) ;
130127 // Observe changes and write to the database.
131- setupObserversToDB ( doc , repoId ) ;
128+ setupObserversToDB ( doc , repoId , blobDir ) ;
132129 // setupObserversToRuntime(doc, repoId);
133130 // reset runtime status
134131 // clear runtimeMap status/commands but keep the ID
0 commit comments