7export const deriveMfsParams = (appPrefix: string) => { 10 return {mfsRoot: `/${appPrefix}-${dbQsName}-ipfsmfs`, kvKey: `ipfs_mfsroot_${dbQsName}`} 13export const deriveMfsParamsFromQs = (qsName: string) => { 14 const appPrefix = qsName.includes('donate') ? 'donateapp' : 'gamesapp' 15 return {mfsRoot: `/${appPrefix}-${qsName}-ipfsmfs`, kvKey: `ipfs_mfsroot_${qsName}`} 25export const addToIpfsMfsRoot = async ({cid, ext, mfsRoot, kvKey}: MfsRootParams): Promise<string> => { 28 await primaryClient.files.mkdir(mfsRoot, {parents: true}).catch(() => {}) 30 const mfsPath = `${mfsRoot}/${cid}.${ext}` 31 await primaryClient.files.cp(`/ipfs/${cid}`, mfsPath).catch(() => {}) 33 const stat = await primaryClient.files.stat(mfsRoot) 34 const newRootCid = stat.cid.toString() 37 for (const {host, client} of targets) { 38 if (client === primaryClient) continue 40 await client.files.mkdir(mfsRoot, {parents: true}).catch(() => {}) 41 await client.files.cp(`/ipfs/${cid}`, mfsPath).catch(() => {}) 42 const secondaryStat = await client.files.stat(mfsRoot) 43 const secondaryRootCid = secondaryStat.cid.toString() 44 if (secondaryRootCid !== newRootCid) { 45 betLog('mfsReplicateCidMismatch', {host, mfsRoot, primaryCid: newRootCid, secondaryCid: secondaryRootCid}) 48 betLog('mfsReplicateFail', {host, mfsRoot, errMsg: (err as Error).message}) 53 const oldRoot = await db('generic_kvs').where({key: kvKey}).first() 56 if (oldRoot?.value && oldRoot.value !== newRootCid) { 60 await db('generic_kvs') 61 .insert({key: kvKey, value: newRootCid}) 63 .merge({value: newRootCid, updated_at: db.fn.now()})