@@ -163,10 +163,13 @@ export const getSpaceNameFromId = async (
163163 return data . name ;
164164} ;
165165
166- export const getSpaceNameIdFromUri = async (
166+ export const getSpaceNameIdFromRid = async (
167167 client : DGSupabaseClient ,
168- spaceUri : string ,
168+ rid : string ,
169169) : Promise < { spaceName : string ; spaceId : number } > => {
170+ const parts = rid . split ( "/" ) ;
171+ parts . pop ( ) ;
172+ const spaceUri = parts . join ( "/" ) ;
170173 const { data, error } = await client
171174 . from ( "Space" )
172175 . select ( "name, id" )
@@ -296,9 +299,7 @@ export const fetchNodeContentWithMetadata = async ({
296299
297300 return {
298301 content : data . text ,
299- createdAt : data . created
300- ? new Date ( data . created + "Z" ) . valueOf ( )
301- : 0 ,
302+ createdAt : data . created ? new Date ( data . created + "Z" ) . valueOf ( ) : 0 ,
302303 modifiedAt : data . last_modified
303304 ? new Date ( data . last_modified + "Z" ) . valueOf ( )
304305 : 0 ,
@@ -382,15 +383,15 @@ const fetchNodeContentForImport = async ({
382383export const getSourceContentDates = async ( {
383384 plugin,
384385 nodeInstanceId,
385- spaceUri ,
386+ importedFromRid ,
386387} : {
387388 plugin : DiscourseGraphPlugin ;
388389 nodeInstanceId : string ;
389- spaceUri : string ;
390+ importedFromRid : string ;
390391} ) : Promise < { createdAt : string ; modifiedAt : string } | null > => {
391392 const client = await getLoggedInClient ( plugin ) ;
392393 if ( ! client ) return null ;
393- const { spaceId } = await getSpaceNameIdFromUri ( client , spaceUri ) ;
394+ const { spaceId } = await getSpaceNameIdFromRid ( client , importedFromRid ) ;
394395 if ( spaceId < 0 ) return null ;
395396 const { data, error } = await client
396397 . from ( "my_contents" )
@@ -1074,6 +1075,7 @@ const processFileContent = async ({
10741075 // often empty immediately after create/modify), then map nodeTypeId and update frontmatter.
10751076 const { frontmatter } = parseFrontmatter ( rawContent ) ;
10761077 const sourceNodeTypeId = frontmatter . nodeTypeId ;
1078+ const sourceNodeId = frontmatter . nodeInstanceId ;
10771079
10781080 let mappedNodeTypeId : string | undefined ;
10791081 if ( sourceNodeTypeId && typeof sourceNodeTypeId === "string" ) {
@@ -1092,7 +1094,7 @@ const processFileContent = async ({
10921094 if ( mappedNodeTypeId !== undefined ) {
10931095 record . nodeTypeId = mappedNodeTypeId ;
10941096 }
1095- record . importedFromSpaceUri = sourceSpaceUri ;
1097+ record . importedFromRid = ` ${ sourceSpaceUri } / ${ sourceNodeId } ` ;
10961098 record . lastModified = importedModifiedAt ;
10971099 } ,
10981100 stat ,
@@ -1321,24 +1323,24 @@ export const refreshImportedFile = async ({
13211323 }
13221324 const cache = plugin . app . metadataCache . getFileCache ( file ) ;
13231325 const frontmatter = cache ?. frontmatter as Record < string , unknown > | undefined ;
1324- if ( ! frontmatter ?. importedFromSpaceUri || ! frontmatter ?. nodeInstanceId ) {
1326+ if ( ! frontmatter ?. importedFromRid || ! frontmatter ?. nodeInstanceId ) {
13251327 return {
13261328 success : false ,
1327- error : "Missing frontmatter: importedFromSpaceUri or nodeInstanceId" ,
1329+ error : "Missing frontmatter: importedFromRid or nodeInstanceId" ,
13281330 } ;
13291331 }
13301332 if (
1331- typeof frontmatter . importedFromSpaceUri !== "string" ||
1333+ typeof frontmatter . importedFromRid !== "string" ||
13321334 typeof frontmatter . nodeInstanceId !== "string"
13331335 ) {
13341336 return {
13351337 success : false ,
1336- error : "Non-string frontmatter: importedFromSpaceUri or nodeInstanceId" ,
1338+ error : "Non-string frontmatter: importedFromRid or nodeInstanceId" ,
13371339 } ;
13381340 }
1339- const { spaceName, spaceId } = await getSpaceNameIdFromUri (
1341+ const { spaceName, spaceId } = await getSpaceNameIdFromRid (
13401342 supabaseClient ,
1341- frontmatter . importedFromSpaceUri ,
1343+ frontmatter . importedFromRid ,
13421344 ) ;
13431345 if ( spaceId === - 1 ) {
13441346 return { success : false , error : "Could not get the space Id" } ;
@@ -1397,7 +1399,7 @@ export const refreshAllImportedFiles = async (
13971399 for ( const file of allFiles ) {
13981400 const cache = plugin . app . metadataCache . getFileCache ( file ) ;
13991401 const frontmatter = cache ?. frontmatter ;
1400- if ( frontmatter ?. importedFromSpaceUri && frontmatter ?. nodeInstanceId ) {
1402+ if ( frontmatter ?. importedFromRid && frontmatter ?. nodeInstanceId ) {
14011403 importedFiles . push ( file ) ;
14021404 }
14031405 }
0 commit comments