@@ -109,23 +109,160 @@ export class SectionService implements ISectionService {
109109 column . position . zoneIndex = newSectionIndex ;
110110 column . position . zoneId = newZoneId ;
111111 }
112-
112+
113113 canvasContent = canvasContent . concat ( newSection ) ;
114114
115- await this . spHttpClient . post (
116- `${ currentWeb } /_api/sitepages/pages(${ currentPageId } )/savepage` ,
117- SPHttpClient . configurations . v1 ,
118- {
119- headers : {
120- 'accept' : 'application/json;odata=nometadata' ,
121- 'content-type' : 'application/json;odata=nometadata' ,
122- 'If-Match' : '*'
123- } ,
124- body : JSON . stringify ( {
125- CanvasContent1 : JSON . stringify ( canvasContent )
126- } )
127- }
128- ) ;
115+ if ( true ) {
116+
117+
118+ /*if (!pageContentJson.IsPageCheckedOutToCurrentUser) {
119+
120+ await this.spHttpClient.post(
121+ `${currentWeb}/_api/web/GetFileByServerRelativePath(DecodedUrl=@a1)/CheckOut?@a1=%27%2Fsites%2FMediaPark%2FSitePages%2Ftest%281%29%2Easpx%27`,
122+ SPHttpClient.configurations.v1,
123+ {
124+
125+
126+ }
127+ );
128+
129+ }*/
130+
131+
132+ /*await this.spHttpClient.post(
133+ `https://mknetpl.sharepoint.com/_api/v2.1/drives/b!Z-jDRnmYHkOW-wMtAMqXjf801B2I88lLjnyxyQ7wiQc6VZAxUHixRo-E_ABgbWlu/items/4566ae2c-c701-4aab-9565-decf2e01853a/opStream/joinSession?ump=1`,
134+ SPHttpClient.configurations.v1,
135+ {
136+ headers: {
137+ 'If-Match': '*'
138+ },
139+ body: JSON.stringify({
140+ "authoringMetadata":
141+ {
142+ "SessionId": pageContentJson.AuthoringMetadata.SessionId,
143+ "SequenceId": pageContentJson.AuthoringMetadata.SequenceId,
144+ "FluidContainerCustomId": pageContentJson.AuthoringMetadata.FluidContainerCustomId,
145+ "IsSingleUserSession": true,
146+ "ClientOperation": 2
147+ },
148+ "connectivityUpdateReason": 1
149+ })
150+
151+ }
152+ );*/
153+
154+
155+ /*await this.spHttpClient.post(
156+ `${currentWeb}/_api/sitepages/pages(${currentPageId})/ExtendSessionCoAuth`,
157+ SPHttpClient.configurations.v1,
158+ {
159+ headers: {
160+ 'If-Match': '*'
161+ },
162+ body: JSON.stringify({
163+ "authoringMetadata":
164+ {
165+ "SessionId": pageContentJson.AuthoringMetadata.SessionId,
166+ "SequenceId": pageContentJson.AuthoringMetadata.SequenceId,
167+ "FluidContainerCustomId": pageContentJson.AuthoringMetadata.FluidContainerCustomId,
168+ "IsSingleUserSession": true,
169+ "ClientOperation": 2
170+ },
171+ "connectivityUpdateReason": 1
172+ })
173+
174+ }
175+ );*/
176+
177+ const pageSeqData = await this . spHttpClient . get (
178+ `https://mknetpl.sharepoint.com/_api/v2.1/drives/b!Z-jDRnmYHkOW-wMtAMqXjf801B2I88lLjnyxyQ7wiQc6VZAxUHixRo-E_ABgbWlu/items/4566ae2c-c701-4aab-9565-decf2e01853a/opStream?ump=1&filter=sequenceNumber%20ge%20${ pageContentJson . AuthoringMetadata . SequenceId } %20and%20sequenceNumber%20le%205106` ,
179+ SPHttpClient . configurations . v1
180+ ) ;
181+ const pageSeqDataJson = await pageSeqData . json ( ) ;
182+
183+
184+ const getLatestSequenceId = pageSeqDataJson . value [ pageSeqDataJson . value . length - 1 ] . sequenceNumber ;
185+
186+ const pageCoSaveResult = await this . spHttpClient . post (
187+ `${ currentWeb } /_api/sitepages/pages(${ currentPageId } )/SavePageCoAuth` ,
188+ SPHttpClient . configurations . v1 ,
189+ {
190+ headers : {
191+ 'If-Match' : '*'
192+ } ,
193+ body : JSON . stringify ( {
194+ //AuthorByline:[],
195+ //BannerImageUrl: pageContentJson.BannerImageUrl,
196+ CanvasContent1 : JSON . stringify ( canvasContent ) ,
197+ //LayoutWebpartsContent: pageContentJson.LayoutWebpartsContent,
198+ //Title: pageContentJson.Title,
199+ //TopicHeader: pageContentJson.TopicHeader,
200+ // WebTranspileContent: pageContentJson.WebTranspileContent,
201+ AuthoringMetadata : {
202+ ClientOperation : 3 ,
203+ //ClientOperation: 2,
204+ FluidContainerCustomId : pageContentJson . AuthoringMetadata . FluidContainerCustomId ,
205+ IsSingleUserSession : true ,
206+ SequenceId : getLatestSequenceId ,
207+ SessionId : pageContentJson . AuthoringMetadata . SessionId
208+ } ,
209+ CoAuthState : {
210+ Action : 1 ,
211+ //LockAction: 1,
212+ LockAction : 2 ,
213+ SharedLockId : pageContentJson . CoAuthState ?. SharedLockId
214+ } ,
215+ Collaborators : [
216+ //{ LoginName: "mkornet@mknetpl.onmicrosoft.com" }
217+ ]
218+ } )
219+ }
220+ ) ;
221+
222+
223+ const pageCoSaveResultJson = await pageCoSaveResult . json ( ) ;
224+ console . log ( 'Page co-save result:' , pageCoSaveResultJson ) ;
225+
226+
227+
228+ /*await this.spHttpClient.post(
229+ `${currentWeb}/_api/sitepages/pages(${currentPageId})/ExtendSessionCoAuth`,
230+ SPHttpClient.configurations.v1,
231+ {
232+ headers: {
233+ 'If-Match': '*'
234+ },
235+ body: JSON.stringify({
236+ "authoringMetadata":
237+ {
238+ "SessionId": pageContentJson.AuthoringMetadata.SessionId,
239+ "SequenceId": pageContentJson.AuthoringMetadata.SequenceId,
240+ "FluidContainerCustomId": pageContentJson.AuthoringMetadata.FluidContainerCustomId,
241+ "IsSingleUserSession": true,
242+ "ClientOperation": 2
243+ },
244+ "connectivityUpdateReason": 1
245+ })
246+
247+ }
248+ );*/
249+ }
250+ else {
251+ await this . spHttpClient . post (
252+ `${ currentWeb } /_api/sitepages/pages(${ currentPageId } )/savepage` ,
253+ SPHttpClient . configurations . v1 ,
254+ {
255+ headers : {
256+ 'accept' : 'application/json;odata=nometadata' ,
257+ 'content-type' : 'application/json;odata=nometadata' ,
258+ 'If-Match' : '*'
259+ } ,
260+ body : JSON . stringify ( {
261+ CanvasContent1 : JSON . stringify ( canvasContent )
262+ } )
263+ }
264+ ) ;
265+ }
129266 } catch ( error ) {
130267 console . error ( 'Error adding section to page:' , error ) ;
131268 throw error ;
0 commit comments