11import type { ContributionClient } from './client.js'
22import { diffGameRecord } from './diff.js'
3+ import { contentHashRkey } from './hash.js'
4+
5+ const CONTRIBUTION_COLLECTION = 'games.gamesgamesgamesgames.contribution'
36
47export interface ContributionSyncResult {
58 action : 'created' | 'skipped'
@@ -22,9 +25,16 @@ export async function syncGameViaContribution(
2225 const existing = await contributionClient . getGameByIgdbId ( igdbId )
2326
2427 if ( ! existing ) {
28+ const rkey = contentHashRkey ( mappedRecord )
29+ const existingRecord = await contributionClient . getRecord ( CONTRIBUTION_COLLECTION , rkey )
30+ if ( existingRecord ) {
31+ return { action : 'skipped' }
32+ }
33+
2534 const result = await contributionClient . createContribution ( {
2635 contributionType : 'newGame' ,
2736 changes : mappedRecord ,
37+ rkey,
2838 } )
2939 return { action : 'created' , contributionType : 'newGame' , uri : result . uri }
3040 }
@@ -35,11 +45,18 @@ export async function syncGameViaContribution(
3545 return { action : 'skipped' }
3646 }
3747
48+ const rkey = contentHashRkey ( changes )
49+ const existingRecord = await contributionClient . getRecord ( CONTRIBUTION_COLLECTION , rkey )
50+ if ( existingRecord ) {
51+ return { action : 'skipped' }
52+ }
53+
3854 const subjectUri = existing . uri
3955 const result = await contributionClient . createContribution ( {
4056 contributionType : 'correction' ,
4157 changes,
4258 subject : subjectUri ,
59+ rkey,
4360 } )
4461
4562 if ( existing . redirectedFrom ) {
0 commit comments