@@ -8,7 +8,7 @@ async function snapshotsLogic(linkToKG, linkToGKsnapshotContainer, KGname, thres
88 await loadOrCreateContainer ( store , linkToGKsnapshotContainer )
99 const snapshots = await getContainerMembers ( store , UI . rdf . sym ( linkToGKsnapshotContainer ) )
1010 const sortedSnapshotFileNames = snapshots . map ( snapshot => snapshot . value ) . sort ( ) // the first element contains the oldest content
11-
11+
1212 const currentKG = await store . fetcher . load ( linkToKG )
1313
1414 if ( sortedSnapshotFileNames && sortedSnapshotFileNames . length === 0 ) {
@@ -17,25 +17,21 @@ async function snapshotsLogic(linkToKG, linkToGKsnapshotContainer, KGname, thres
1717 const latestSnapshotLink = sortedSnapshotFileNames [ sortedSnapshotFileNames . length - 1 ] // last element contains the newest content
1818 let latestSnapshotKG
1919 try {
20- latestSnapshotKG = await store . fetcher ?. load ( latestSnapshotLink )
20+ latestSnapshotKG = await getSnapshotWithoutAdditionalTriples ( store , latestSnapshotLink )
2121 } catch ( err ) {
2222 console . log ( err )
2323 latestSnapshotKG = { }
2424 latestSnapshotKG . responseText = ''
2525 }
2626
2727 if ( latestSnapshotKG . responseText !== currentKG . responseText ) {
28- //console.log(latestSnapshotKG.responseText !== currentKG.responseText)
29- //console.log(latestSnapshotKG.responseText)
30- //console.log(currentKG.responseText)
3128 sortedSnapshotFileNames . push ( await createSnapshot ( store , currentKG , KGname ) )
3229 }
3330 }
3431
3532 if ( sortedSnapshotFileNames && sortedSnapshotFileNames . length > threshold ) {
3633 deleteOlderSnapshots ( store , sortedSnapshotFileNames , threshold )
3734 }
38-
3935}
4036
4137async function createSnapshot ( store , currentKG , nameOfSnapshot ) {
@@ -79,7 +75,7 @@ async function createSnapshotNow(store, linkToCurrentKG, snapName, sortedSnapsho
7975 console . info ( 'creating snapshot' )
8076 element . textContent = 'Working...'
8177 try {
82- const currentKG = await store . fetcher ? .load ( linkToCurrentKG )
78+ const currentKG = await store . fetcher . load ( linkToCurrentKG )
8379 sortedSnapshotFileNames . push ( await createSnapshot ( store , currentKG , snapName ) )
8480 } catch ( err ) {
8581 const msg = 'Something went wrong'
@@ -93,14 +89,24 @@ async function switchSnapshot(store, url, element, linkToKG) {
9389 console . info ( "switching snapshot" )
9490 element . textContent = 'Working...'
9591 try {
96- const snapshotKG = await store . fetcher ?. load ( url )
97- await store . fetcher ? .webOperation ( 'DELETE' , UI . rdf . sym ( linkToKG ) )
98- await store . fetcher ? .webOperation ( 'PUT' , linkToKG , { data : snapshotKG . responseText , contentType : 'text/turtle' , Link : '<http://www.w3.org/ns/ldp#BasicContainer>; rel="type"' } )
99- const currentKG = await store . fetcher ? .load ( linkToKG )
92+ const snapshotKG = await getSnapshotWithoutAdditionalTriples ( store , url )
93+ await store . fetcher . webOperation ( 'DELETE' , UI . rdf . sym ( linkToKG ) )
94+ await store . fetcher . webOperation ( 'PUT' , linkToKG , { data : snapshotKG . responseText , contentType : 'text/turtle' , Link : '<http://www.w3.org/ns/ldp#BasicContainer>; rel="type"' } )
95+ const currentKG = await store . fetcher . load ( linkToKG )
10096 } catch ( err ) {
10197 const msg = 'could not switch snapshot '
10298 element . textContent = msg
10399 throw new Error ( msg ) ;
104100 }
105101 element . textContent = "Successful"
102+ }
103+
104+ async function getSnapshotWithoutAdditionalTriples ( store , linkToResource ) {
105+ let loadedResource = await store . fetcher . load ( linkToResource )
106+ const creator = store . statementsMatching ( null , UI . rdf . sym ( "http://purl.org/dc/terms/creator" ) , null , UI . rdf . sym ( linkToResource ) )
107+ const modified = store . statementsMatching ( null , UI . rdf . sym ( "http://purl.org/dc/terms/modified" ) , null , UI . rdf . sym ( linkToResource ) )
108+ await store . updater . update ( creator . concat ( modified ) , [ ] )
109+ loadedResource = await store . fetcher . load ( linkToResource )
110+ await store . updater . update ( [ ] , creator . concat ( modified ) )
111+ return loadedResource
106112}
0 commit comments