diff --git a/src/common/store.js b/src/common/store.js index 94fd523ae..63740cf4b 100644 --- a/src/common/store.js +++ b/src/common/store.js @@ -72,6 +72,16 @@ const migrations = { flags = flags.filter(f => f !== dhtClientFlag) store.set('ipfsConfig.flags', flags) } + }, + '>=0.39.1': store => { + fileLogger.info('Running migration: >=0.39.1') + logger.info('[store]: Migrating to use CID version 1 for files') + const useCIDv1 = store.get('ipfsConfig.useCIDv1', null) + if (useCIDv1 === null) { + // if it's null, it's not set to true or false, so we set it to the new default + store.safeSet('ipfsConfig.useCIDv1', true) + } + // otherwise, it's already set to true or false, so we don't need to do anything } } diff --git a/src/enable-cid-v1.js b/src/enable-cid-v1.js new file mode 100644 index 000000000..09fbb09ff --- /dev/null +++ b/src/enable-cid-v1.js @@ -0,0 +1,27 @@ +const store = require('./common/store') +const getCtx = require('./context') +const logger = require('./common/logger') + +module.exports = async function () { + const shouldUseCIDv1 = store.get('ipfsConfig.useCIDv1', true) + + if (shouldUseCIDv1) { + logger.info('[enable-cid-v1]: Attempting to enable CID version 1 for files') + const ctx = getCtx() + const getIpfsd = await ctx.getProp('getIpfsd') + /** @type {import('ipfsd-ctl').Controller|null} */ + const ipfsd = await getIpfsd() + if (!ipfsd) { + logger.error('[enable-cid-v1]: Could not get IPFS daemon controller') + return + } + logger.info('[enable-cid-v1]: Enabling CID version 1 for files') + try { + // @ts-expect-error - ipfsd.api is not typed properly + await ipfsd.api.files.chcid('/', { cidVersion: 1 }) + logger.info('[enable-cid-v1]: CID version 1 enabled for files') + } catch (e) { + logger.error('[enable-cid-v1]: Failed to enable CID version 1 for files', e) + } + } +} diff --git a/src/index.js b/src/index.js index 461fe7d71..5afc08df7 100644 --- a/src/index.js +++ b/src/index.js @@ -34,6 +34,7 @@ const setupSecondInstance = require('./second-instance') const { analyticsKeys } = require('./analytics/keys') const handleError = require('./handleError') const createSplashScreen = require('./splash/create-splash-screen') +const enableCIDv1 = require('./enable-cid-v1') // Hide Dock if (app.dock) app.dock.hide() @@ -82,7 +83,8 @@ async function run () { setupNamesysPubsub(), setupSecondInstance(), // Setup global shortcuts - setupTakeScreenshot() + setupTakeScreenshot(), + enableCIDv1() ]) const submitAppReady = () => { logger.addAnalyticsEvent({ withAnalytics: analyticsKeys.APP_READY, dur: getSecondsSinceAppStart() })