@strapi/data-transfer 5.41.1 → 5.42.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/directory/index.d.ts +2 -0
- package/dist/directory/index.d.ts.map +1 -0
- package/dist/directory/index.js +8 -0
- package/dist/directory/index.js.map +1 -0
- package/dist/directory/index.mjs +3 -0
- package/dist/directory/index.mjs.map +1 -0
- package/dist/directory/providers/destination/index.d.ts +40 -0
- package/dist/directory/providers/destination/index.d.ts.map +1 -0
- package/dist/directory/providers/destination/index.js +179 -0
- package/dist/directory/providers/destination/index.js.map +1 -0
- package/dist/directory/providers/destination/index.mjs +177 -0
- package/dist/directory/providers/destination/index.mjs.map +1 -0
- package/dist/directory/providers/destination/utils.d.ts +9 -0
- package/dist/directory/providers/destination/utils.d.ts.map +1 -0
- package/dist/directory/providers/destination/utils.js +58 -0
- package/dist/directory/providers/destination/utils.js.map +1 -0
- package/dist/directory/providers/destination/utils.mjs +56 -0
- package/dist/directory/providers/destination/utils.mjs.map +1 -0
- package/dist/directory/providers/index.d.ts +3 -0
- package/dist/directory/providers/index.d.ts.map +1 -0
- package/dist/directory/providers/index.js +10 -0
- package/dist/directory/providers/index.js.map +1 -0
- package/dist/directory/providers/index.mjs +3 -0
- package/dist/directory/providers/index.mjs.map +1 -0
- package/dist/directory/providers/source/index.d.ts +28 -0
- package/dist/directory/providers/source/index.d.ts.map +1 -0
- package/dist/directory/providers/source/index.js +260 -0
- package/dist/directory/providers/source/index.js.map +1 -0
- package/dist/directory/providers/source/index.mjs +258 -0
- package/dist/directory/providers/source/index.mjs.map +1 -0
- package/dist/file/providers/destination/index.js +3 -3
- package/dist/file/providers/destination/index.js.map +1 -1
- package/dist/file/providers/source/index.js +2 -2
- package/dist/file/providers/source/index.js.map +1 -1
- package/dist/file/providers/source/index.mjs +2 -2
- package/dist/file/providers/source/index.mjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -8
- package/dist/index.mjs.map +1 -1
- package/dist/strapi/providers/local-destination/index.js +9 -9
- package/dist/strapi/providers/local-destination/index.js.map +1 -1
- package/dist/strapi/providers/local-destination/index.mjs +8 -8
- package/dist/strapi/providers/local-destination/index.mjs.map +1 -1
- package/dist/strapi/providers/local-source/assets.js +3 -3
- package/dist/strapi/providers/local-source/assets.js.map +1 -1
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/strapi/providers/local-destination/index.ts"],"sourcesContent":["import { Writable, Readable } from 'stream';\nimport path from 'path';\nimport * as fse from 'fs-extra';\nimport type { Knex } from 'knex';\nimport type { Core, Struct } from '@strapi/types';\nimport type {\n IAsset,\n IDestinationProvider,\n IFile,\n IMetadata,\n ProviderType,\n Transaction,\n} from '../../../../types';\nimport type { IDiagnosticReporter } from '../../../utils/diagnostic';\n\nimport { restore } from './strategies';\nimport * as utils from '../../../utils';\nimport {\n ProviderInitializationError,\n ProviderTransferError,\n ProviderValidationError,\n} from '../../../errors/providers';\nimport { assertValidStrapi } from '../../../utils/providers';\n\nexport const VALID_CONFLICT_STRATEGIES = ['restore'];\nexport const DEFAULT_CONFLICT_STRATEGY = 'restore';\n\nexport interface ILocalStrapiDestinationProviderOptions {\n getStrapi(): Core.Strapi | Promise<Core.Strapi>; // return an initialized instance of Strapi\n\n autoDestroy?: boolean; // shut down the instance returned by getStrapi() at the end of the transfer\n restore?: restore.IRestoreOptions; // erase data in strapi database before transfer; required if strategy is 'restore'\n strategy: 'restore'; // conflict management strategy; only the restore strategy is available at this time\n}\n\nclass LocalStrapiDestinationProvider implements IDestinationProvider {\n name = 'destination::local-strapi';\n\n type: ProviderType = 'destination';\n\n options: ILocalStrapiDestinationProviderOptions;\n\n strapi?: Core.Strapi;\n\n transaction?: Transaction;\n\n uploadsBackupDirectoryName: string;\n\n onWarning?: ((message: string) => void) | undefined;\n\n #diagnostics?: IDiagnosticReporter;\n\n /**\n * The entities mapper is used to map old entities to their new IDs\n */\n #entitiesMapper: { [type: string]: { [id: number]: number } };\n\n constructor(options: ILocalStrapiDestinationProviderOptions) {\n this.options = options;\n this.#entitiesMapper = {};\n this.uploadsBackupDirectoryName = `uploads_backup_${Date.now()}`;\n }\n\n async bootstrap(diagnostics?: IDiagnosticReporter): Promise<void> {\n this.#diagnostics = diagnostics;\n this.#validateOptions();\n this.strapi = await this.options.getStrapi();\n if (!this.strapi) {\n throw new ProviderInitializationError('Could not access local strapi');\n }\n this.strapi.db.lifecycles.disable();\n this.transaction = utils.transaction.createTransaction(this.strapi);\n }\n\n // TODO: either move this to restore strategy, or restore strategy should given access to these instead of repeating the logic possibly in a different way\n #areAssetsIncluded = () => {\n return this.options.restore?.assets;\n };\n\n #isContentTypeIncluded = (type: string) => {\n const notIncluded =\n this.options.restore?.entities?.include &&\n !this.options.restore?.entities?.include?.includes(type);\n const excluded =\n this.options.restore?.entities?.exclude &&\n this.options.restore?.entities.exclude.includes(type);\n\n return !excluded && !notIncluded;\n };\n\n #reportInfo(message: string) {\n this.#diagnostics?.report({\n details: {\n createdAt: new Date(),\n message,\n origin: 'local-destination-provider',\n },\n kind: 'info',\n });\n }\n\n async close(): Promise<void> {\n const { autoDestroy } = this.options;\n assertValidStrapi(this.strapi);\n this.transaction?.end();\n this.strapi.db.lifecycles.enable();\n // Basically `!== false` but more deterministic\n if (autoDestroy === undefined || autoDestroy === true) {\n await this.strapi?.destroy();\n }\n }\n\n #validateOptions() {\n this.#reportInfo('validating options');\n if (!VALID_CONFLICT_STRATEGIES.includes(this.options.strategy)) {\n throw new ProviderValidationError(`Invalid strategy ${this.options.strategy}`, {\n check: 'strategy',\n strategy: this.options.strategy,\n validStrategies: VALID_CONFLICT_STRATEGIES,\n });\n }\n\n // require restore options when using restore\n if (this.options.strategy === 'restore' && !this.options.restore) {\n throw new ProviderValidationError('Missing restore options');\n }\n }\n\n async #deleteFromRestoreOptions() {\n assertValidStrapi(this.strapi);\n if (!this.options.restore) {\n throw new ProviderValidationError('Missing restore options');\n }\n this.#reportInfo('deleting record ');\n return restore.deleteRecords(this.strapi, this.options.restore);\n }\n\n async #deleteAllAssets(trx?: Knex.Transaction) {\n assertValidStrapi(this.strapi);\n this.#reportInfo('deleting all assets');\n // if we're not restoring files, don't touch the files\n if (!this.#areAssetsIncluded()) {\n return;\n }\n\n const stream: Readable = this.strapi.db\n // Create a query builder instance (default type is 'select')\n .queryBuilder('plugin::upload.file')\n // Fetch all columns\n .select('*')\n // Attach the transaction\n .transacting(trx)\n // Get a readable stream\n .stream();\n\n // TODO use bulk delete when exists in providers\n for await (const file of stream) {\n await this.strapi.plugin('upload').provider.delete(file);\n if (file.formats) {\n for (const fileFormat of Object.values(file.formats)) {\n await this.strapi.plugin('upload').provider.delete(fileFormat);\n }\n }\n }\n\n this.#reportInfo('deleted all assets');\n }\n\n async rollback() {\n this.#reportInfo('Rolling back transaction');\n await this.transaction?.rollback();\n this.#reportInfo('Rolled back transaction');\n }\n\n async beforeTransfer() {\n if (!this.strapi) {\n throw new Error('Strapi instance not found');\n }\n\n await this.transaction?.attach(async (trx) => {\n try {\n if (this.options.strategy === 'restore') {\n await this.#handleAssetsBackup();\n await this.#deleteAllAssets(trx);\n await this.#deleteFromRestoreOptions();\n }\n } catch (error) {\n throw new Error(`restore failed ${error}`);\n }\n });\n }\n\n getMetadata(): IMetadata {\n this.#reportInfo('getting metadata');\n assertValidStrapi(this.strapi, 'Not able to get Schemas');\n const strapiVersion = this.strapi.config.get<string>('info.strapi');\n const createdAt = new Date().toISOString();\n\n return {\n createdAt,\n strapi: {\n version: strapiVersion,\n },\n };\n }\n\n getSchemas(): Record<string, Struct.Schema> {\n this.#reportInfo('getting schema');\n assertValidStrapi(this.strapi, 'Not able to get Schemas');\n\n const schemas = utils.schema.schemasToValidJSON({\n ...this.strapi.contentTypes,\n ...this.strapi.components,\n });\n\n return utils.schema.mapSchemasValues(schemas);\n }\n\n createEntitiesWriteStream(): Writable {\n assertValidStrapi(this.strapi, 'Not able to import entities');\n this.#reportInfo('creating entities stream');\n const { strategy } = this.options;\n\n const updateMappingTable = (type: string, oldID: number, newID: number) => {\n if (!this.#entitiesMapper[type]) {\n this.#entitiesMapper[type] = {};\n }\n\n Object.assign(this.#entitiesMapper[type], { [oldID]: newID });\n };\n\n if (strategy === 'restore') {\n return restore.createEntitiesWriteStream({\n strapi: this.strapi,\n updateMappingTable,\n transaction: this.transaction,\n });\n }\n\n throw new ProviderValidationError(`Invalid strategy ${this.options.strategy}`, {\n check: 'strategy',\n strategy: this.options.strategy,\n validStrategies: VALID_CONFLICT_STRATEGIES,\n });\n }\n\n async #handleAssetsBackup() {\n assertValidStrapi(this.strapi, 'Not able to create the assets backup');\n\n // if we're not restoring assets, don't back them up because they won't be touched\n if (!this.#areAssetsIncluded()) {\n return;\n }\n\n if (this.strapi.config.get<{ provider: string }>('plugin::upload').provider === 'local') {\n this.#reportInfo('creating assets backup directory');\n const assetsDirectory = path.join(this.strapi.dirs.static.public, 'uploads');\n const backupDirectory = path.join(\n this.strapi.dirs.static.public,\n this.uploadsBackupDirectoryName\n );\n\n try {\n // Check access before attempting to do anything\n await fse.access(\n assetsDirectory,\n // eslint-disable-next-line no-bitwise\n fse.constants.W_OK | fse.constants.R_OK | fse.constants.F_OK\n );\n // eslint-disable-next-line no-bitwise\n await fse.access(path.join(assetsDirectory, '..'), fse.constants.W_OK | fse.constants.R_OK);\n\n await fse.move(assetsDirectory, backupDirectory);\n await fse.mkdir(assetsDirectory);\n // Create a .gitkeep file to ensure the directory is not empty\n await fse.outputFile(path.join(assetsDirectory, '.gitkeep'), '');\n this.#reportInfo(`created assets backup directory ${backupDirectory}`);\n } catch (err) {\n throw new ProviderTransferError(\n 'The backup folder for the assets could not be created inside the public folder. Please ensure Strapi has write permissions on the public directory',\n {\n code: 'ASSETS_DIRECTORY_ERR',\n }\n );\n }\n return backupDirectory;\n }\n }\n\n async #removeAssetsBackup() {\n assertValidStrapi(this.strapi, 'Not able to remove Assets');\n // if we're not restoring assets, don't back them up because they won't be touched\n if (!this.#areAssetsIncluded()) {\n return;\n }\n // TODO: this should catch all thrown errors and bubble it up to engine so it can be reported as a non-fatal diagnostic message telling the user they may need to manually delete assets\n if (this.strapi.config.get<{ provider: string }>('plugin::upload').provider === 'local') {\n this.#reportInfo('removing assets backup');\n assertValidStrapi(this.strapi);\n const backupDirectory = path.join(\n this.strapi.dirs.static.public,\n this.uploadsBackupDirectoryName\n );\n await fse.rm(backupDirectory, { recursive: true, force: true });\n this.#reportInfo('successfully removed assets backup');\n }\n }\n\n // TODO: Move this logic to the restore strategy\n async createAssetsWriteStream(): Promise<Writable> {\n assertValidStrapi(this.strapi, 'Not able to stream Assets');\n this.#reportInfo('creating assets write stream');\n if (!this.#areAssetsIncluded()) {\n throw new ProviderTransferError(\n 'Attempting to transfer assets when `assets` is not set in restore options'\n );\n }\n\n const removeAssetsBackup = this.#removeAssetsBackup.bind(this);\n const strapi = this.strapi;\n const transaction = this.transaction;\n const fileEntitiesMapper = this.#entitiesMapper['plugin::upload.file'];\n\n const restoreMediaEntitiesContent = this.#isContentTypeIncluded('plugin::upload.file');\n\n return new Writable({\n objectMode: true,\n async final(next) {\n // Delete the backup folder\n await removeAssetsBackup();\n next();\n },\n async write(chunk: IAsset, _encoding, callback) {\n await transaction?.attach(async () => {\n const uploadData = {\n ...chunk.metadata,\n stream: Readable.from(chunk.stream),\n buffer: chunk?.buffer,\n };\n\n const provider = strapi.config.get<{ provider: string }>('plugin::upload').provider;\n\n const fileId = fileEntitiesMapper?.[uploadData.id];\n if (!fileId) {\n return callback(new Error(`File ID not found for ID: ${uploadData.id}`));\n }\n\n try {\n await strapi.plugin('upload').provider.uploadStream(uploadData);\n\n // if we're not supposed to transfer the associated entities, stop here\n if (!restoreMediaEntitiesContent) {\n return callback();\n }\n\n // Files formats are stored within the parent file entity\n if (uploadData?.type) {\n const entry: IFile = await strapi.db.query('plugin::upload.file').findOne({\n where: { id: fileId },\n });\n if (!entry) {\n throw new Error('file not found');\n }\n const specificFormat = entry?.formats?.[uploadData.type];\n if (specificFormat) {\n specificFormat.url = uploadData.url;\n }\n await strapi.db.query('plugin::upload.file').update({\n where: { id: entry.id },\n data: {\n formats: entry.formats,\n provider,\n },\n });\n return callback();\n }\n\n const entry: IFile = await strapi.db.query('plugin::upload.file').findOne({\n where: { id: fileId },\n });\n if (!entry) {\n throw new Error('file not found');\n }\n entry.url = uploadData.url;\n await strapi.db.query('plugin::upload.file').update({\n where: { id: entry.id },\n data: {\n url: entry.url,\n provider,\n },\n });\n return callback();\n } catch (error) {\n return callback(new Error(`Error while uploading asset ${chunk.filename} ${error}`));\n }\n });\n },\n });\n }\n\n async createConfigurationWriteStream(): Promise<Writable> {\n assertValidStrapi(this.strapi, 'Not able to stream Configurations');\n this.#reportInfo('creating configuration write stream');\n const { strategy } = this.options;\n\n if (strategy === 'restore') {\n return restore.createConfigurationWriteStream(this.strapi, this.transaction);\n }\n\n throw new ProviderValidationError(`Invalid strategy ${strategy}`, {\n check: 'strategy',\n strategy,\n validStrategies: VALID_CONFLICT_STRATEGIES,\n });\n }\n\n async createLinksWriteStream(): Promise<Writable> {\n this.#reportInfo('creating links write stream');\n if (!this.strapi) {\n throw new Error('Not able to stream links. Strapi instance not found');\n }\n\n const { strategy } = this.options;\n const mapID = (uid: string, id: number): number | undefined => this.#entitiesMapper[uid]?.[id];\n\n if (strategy === 'restore') {\n return restore.createLinksWriteStream(mapID, this.strapi, this.transaction, this.onWarning);\n }\n\n throw new ProviderValidationError(`Invalid strategy ${strategy}`, {\n check: 'strategy',\n strategy,\n validStrategies: VALID_CONFLICT_STRATEGIES,\n });\n }\n}\n\nexport const createLocalStrapiDestinationProvider = (\n options: ILocalStrapiDestinationProviderOptions\n) => {\n return new LocalStrapiDestinationProvider(options);\n};\n"],"names":["VALID_CONFLICT_STRATEGIES","DEFAULT_CONFLICT_STRATEGY","LocalStrapiDestinationProvider","bootstrap","diagnostics","strapi","options","getStrapi","ProviderInitializationError","db","lifecycles","disable","transaction","utils","close","autoDestroy","assertValidStrapi","end","enable","undefined","destroy","rollback","beforeTransfer","Error","attach","trx","strategy","error","getMetadata","strapiVersion","config","get","createdAt","Date","toISOString","version","getSchemas","schemas","contentTypes","components","createEntitiesWriteStream","updateMappingTable","type","oldID","newID","Object","assign","restore","ProviderValidationError","check","validStrategies","createAssetsWriteStream","ProviderTransferError","removeAssetsBackup","bind","fileEntitiesMapper","restoreMediaEntitiesContent","Writable","objectMode","final","next","write","chunk","_encoding","callback","uploadData","metadata","stream","Readable","from","buffer","provider","fileId","id","plugin","uploadStream","entry","query","findOne","where","specificFormat","formats","url","update","data","filename","createConfigurationWriteStream","createLinksWriteStream","mapID","uid","onWarning","name","assets","notIncluded","entities","include","includes","excluded","exclude","uploadsBackupDirectoryName","now","message","report","details","origin","kind","queryBuilder","select","transacting","file","delete","fileFormat","values","assetsDirectory","path","join","dirs","static","public","backupDirectory","fse","access","constants","W_OK","R_OK","F_OK","move","mkdir","outputFile","err","code","rm","recursive","force","createLocalStrapiDestinationProvider"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAwBaA,yBAAAA,GAA4B;AAAC,IAAA;;AACnC,MAAMC,4BAA4B;IAyBvC,YAAA,iBAAA,8BAAA,CAAA,cAAA,CAAA;;AAIC,MACD;AAoBA,kBAAA,iBAAA,8BAAA,CAAA,oBAAA,CAAA,EAIA,sBAAA,iBAAA,8BAAA,CAAA,wBAAA,CAAA,EAWA,WAAA,iBAAA,8BAAA,CAAA,aAAA,CAAA,EAsBA,gBAAA,iBAAA,8BAAA,CAAA,kBAAA,CAAA,EAgBM,yBAAA,iBAAA,8BAAA,CAAA,2BAAA,CAAA,EASA,qFA6GA,mBAAA,iBAAA,8BAAA,CAAA,qBAAA,CAAA,EA2CA,mBAAA,iBAAA,8BAAA,CAAA,qBAAA,CAAA;AA9PR,MAAMC,8B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AAA,CAAkB,IAAI,CAACX,MAAM,CAAA;AAC7B,QAAA,MAAMkH,kBAAkBL,IAAAA,CAAKC,IAAI,CAC/B,IAAI,CAAC9G,MAAM,CAAC+G,IAAI,CAACC,MAAM,CAACC,MAAM,EAC9B,IAAI,CAACnB,0BAA0B,CAAA;QAEjC,MAAMqB,cAAAA,CAAIW,EAAE,CAACZ,eAAAA,EAAiB;YAAEa,SAAAA,EAAW,IAAA;YAAMC,KAAAA,EAAO;AAAK,SAAA,CAAA;QAC7D,+BAAA,CAAA,IAAI,EAAC,WAAA,CAAA,CAAA,WAAA,CAAA,CAAY,oCAAA,CAAA;AACnB,IAAA;AACF;AAmIK,MAAMC,uCAAuC,CAClDhI,OAAAA,GAAAA;AAEA,IAAA,OAAO,IAAIJ,8BAAAA,CAA+BI,OAAAA,CAAAA;AAC5C;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/strapi/providers/local-destination/index.ts"],"sourcesContent":["import { Writable, Readable } from 'stream';\nimport path from 'path';\nimport * as fse from 'fs-extra';\nimport type { Knex } from 'knex';\nimport type { Core, Struct } from '@strapi/types';\nimport type {\n IAsset,\n IDestinationProvider,\n IFile,\n IMetadata,\n ProviderType,\n Transaction,\n} from '../../../../types';\nimport type { IDiagnosticReporter } from '../../../utils/diagnostic';\n\nimport { restore } from './strategies';\nimport * as utils from '../../../utils';\nimport {\n ProviderInitializationError,\n ProviderTransferError,\n ProviderValidationError,\n} from '../../../errors/providers';\nimport { assertValidStrapi } from '../../../utils/providers';\n\nexport const VALID_CONFLICT_STRATEGIES = ['restore'];\nexport const DEFAULT_CONFLICT_STRATEGY = 'restore';\n\nexport interface ILocalStrapiDestinationProviderOptions {\n getStrapi(): Core.Strapi | Promise<Core.Strapi>; // return an initialized instance of Strapi\n\n autoDestroy?: boolean; // shut down the instance returned by getStrapi() at the end of the transfer\n restore?: restore.IRestoreOptions; // erase data in strapi database before transfer; required if strategy is 'restore'\n strategy: 'restore'; // conflict management strategy; only the restore strategy is available at this time\n}\n\nclass LocalStrapiDestinationProvider implements IDestinationProvider {\n name = 'destination::local-strapi';\n\n type: ProviderType = 'destination';\n\n options: ILocalStrapiDestinationProviderOptions;\n\n strapi?: Core.Strapi;\n\n transaction?: Transaction;\n\n uploadsBackupDirectoryName: string;\n\n onWarning?: ((message: string) => void) | undefined;\n\n #diagnostics?: IDiagnosticReporter;\n\n /**\n * The entities mapper is used to map old entities to their new IDs\n */\n #entitiesMapper: { [type: string]: { [id: number]: number } };\n\n constructor(options: ILocalStrapiDestinationProviderOptions) {\n this.options = options;\n this.#entitiesMapper = {};\n this.uploadsBackupDirectoryName = `uploads_backup_${Date.now()}`;\n }\n\n async bootstrap(diagnostics?: IDiagnosticReporter): Promise<void> {\n this.#diagnostics = diagnostics;\n this.#validateOptions();\n this.strapi = await this.options.getStrapi();\n if (!this.strapi) {\n throw new ProviderInitializationError('Could not access local strapi');\n }\n this.strapi.db.lifecycles.disable();\n this.transaction = utils.transaction.createTransaction(this.strapi);\n }\n\n // TODO: either move this to restore strategy, or restore strategy should given access to these instead of repeating the logic possibly in a different way\n #areAssetsIncluded = () => {\n return this.options.restore?.assets;\n };\n\n #isContentTypeIncluded = (type: string) => {\n const notIncluded =\n this.options.restore?.entities?.include &&\n !this.options.restore?.entities?.include?.includes(type);\n const excluded =\n this.options.restore?.entities?.exclude &&\n this.options.restore?.entities.exclude.includes(type);\n\n return !excluded && !notIncluded;\n };\n\n #reportInfo(message: string) {\n this.#diagnostics?.report({\n details: {\n createdAt: new Date(),\n message,\n origin: 'local-destination-provider',\n },\n kind: 'info',\n });\n }\n\n async close(): Promise<void> {\n const { autoDestroy } = this.options;\n assertValidStrapi(this.strapi);\n this.transaction?.end();\n this.strapi.db.lifecycles.enable();\n // Basically `!== false` but more deterministic\n if (autoDestroy === undefined || autoDestroy === true) {\n await this.strapi?.destroy();\n }\n }\n\n #validateOptions() {\n this.#reportInfo('validating options');\n if (!VALID_CONFLICT_STRATEGIES.includes(this.options.strategy)) {\n throw new ProviderValidationError(`Invalid strategy ${this.options.strategy}`, {\n check: 'strategy',\n strategy: this.options.strategy,\n validStrategies: VALID_CONFLICT_STRATEGIES,\n });\n }\n\n // require restore options when using restore\n if (this.options.strategy === 'restore' && !this.options.restore) {\n throw new ProviderValidationError('Missing restore options');\n }\n }\n\n async #deleteFromRestoreOptions() {\n assertValidStrapi(this.strapi);\n if (!this.options.restore) {\n throw new ProviderValidationError('Missing restore options');\n }\n this.#reportInfo('deleting record ');\n return restore.deleteRecords(this.strapi, this.options.restore);\n }\n\n async #deleteAllAssets(trx?: Knex.Transaction) {\n assertValidStrapi(this.strapi);\n this.#reportInfo('deleting all assets');\n // if we're not restoring files, don't touch the files\n if (!this.#areAssetsIncluded()) {\n return;\n }\n\n const stream: Readable = this.strapi.db\n // Create a query builder instance (default type is 'select')\n .queryBuilder('plugin::upload.file')\n // Fetch all columns\n .select('*')\n // Attach the transaction\n .transacting(trx)\n // Get a readable stream\n .stream();\n\n // TODO use bulk delete when exists in providers\n for await (const file of stream) {\n await this.strapi.plugin('upload').provider.delete(file);\n if (file.formats) {\n for (const fileFormat of Object.values(file.formats)) {\n await this.strapi.plugin('upload').provider.delete(fileFormat);\n }\n }\n }\n\n this.#reportInfo('deleted all assets');\n }\n\n async rollback() {\n this.#reportInfo('Rolling back transaction');\n await this.transaction?.rollback();\n this.#reportInfo('Rolled back transaction');\n }\n\n async beforeTransfer() {\n if (!this.strapi) {\n throw new Error('Strapi instance not found');\n }\n\n await this.transaction?.attach(async (trx) => {\n try {\n if (this.options.strategy === 'restore') {\n await this.#handleAssetsBackup();\n await this.#deleteAllAssets(trx);\n await this.#deleteFromRestoreOptions();\n }\n } catch (error) {\n throw new Error(`restore failed ${error}`);\n }\n });\n }\n\n getMetadata(): IMetadata {\n this.#reportInfo('getting metadata');\n assertValidStrapi(this.strapi, 'Not able to get Schemas');\n const strapiVersion = this.strapi.config.get<string>('info.strapi');\n const createdAt = new Date().toISOString();\n\n return {\n createdAt,\n strapi: {\n version: strapiVersion,\n },\n };\n }\n\n getSchemas(): Record<string, Struct.Schema> {\n this.#reportInfo('getting schema');\n assertValidStrapi(this.strapi, 'Not able to get Schemas');\n\n const schemas = utils.schema.schemasToValidJSON({\n ...this.strapi.contentTypes,\n ...this.strapi.components,\n });\n\n return utils.schema.mapSchemasValues(schemas);\n }\n\n createEntitiesWriteStream(): Writable {\n assertValidStrapi(this.strapi, 'Not able to import entities');\n this.#reportInfo('creating entities stream');\n const { strategy } = this.options;\n\n const updateMappingTable = (type: string, oldID: number, newID: number) => {\n if (!this.#entitiesMapper[type]) {\n this.#entitiesMapper[type] = {};\n }\n\n Object.assign(this.#entitiesMapper[type], { [oldID]: newID });\n };\n\n if (strategy === 'restore') {\n return restore.createEntitiesWriteStream({\n strapi: this.strapi,\n updateMappingTable,\n transaction: this.transaction,\n });\n }\n\n throw new ProviderValidationError(`Invalid strategy ${this.options.strategy}`, {\n check: 'strategy',\n strategy: this.options.strategy,\n validStrategies: VALID_CONFLICT_STRATEGIES,\n });\n }\n\n async #handleAssetsBackup() {\n assertValidStrapi(this.strapi, 'Not able to create the assets backup');\n\n // if we're not restoring assets, don't back them up because they won't be touched\n if (!this.#areAssetsIncluded()) {\n return;\n }\n\n if (this.strapi.config.get<{ provider: string }>('plugin::upload').provider === 'local') {\n this.#reportInfo('creating assets backup directory');\n const assetsDirectory = path.join(this.strapi.dirs.static.public, 'uploads');\n const backupDirectory = path.join(\n this.strapi.dirs.static.public,\n this.uploadsBackupDirectoryName\n );\n\n try {\n // Check access before attempting to do anything\n await fse.access(\n assetsDirectory,\n // eslint-disable-next-line no-bitwise\n fse.constants.W_OK | fse.constants.R_OK | fse.constants.F_OK\n );\n // eslint-disable-next-line no-bitwise\n await fse.access(path.join(assetsDirectory, '..'), fse.constants.W_OK | fse.constants.R_OK);\n\n await fse.move(assetsDirectory, backupDirectory);\n await fse.mkdir(assetsDirectory);\n // Create a .gitkeep file to ensure the directory is not empty\n await fse.outputFile(path.join(assetsDirectory, '.gitkeep'), '');\n this.#reportInfo(`created assets backup directory ${backupDirectory}`);\n } catch (err) {\n throw new ProviderTransferError(\n 'The backup folder for the assets could not be created inside the public folder. Please ensure Strapi has write permissions on the public directory',\n {\n code: 'ASSETS_DIRECTORY_ERR',\n }\n );\n }\n return backupDirectory;\n }\n }\n\n async #removeAssetsBackup() {\n assertValidStrapi(this.strapi, 'Not able to remove Assets');\n // if we're not restoring assets, don't back them up because they won't be touched\n if (!this.#areAssetsIncluded()) {\n return;\n }\n // TODO: this should catch all thrown errors and bubble it up to engine so it can be reported as a non-fatal diagnostic message telling the user they may need to manually delete assets\n if (this.strapi.config.get<{ provider: string }>('plugin::upload').provider === 'local') {\n this.#reportInfo('removing assets backup');\n assertValidStrapi(this.strapi);\n const backupDirectory = path.join(\n this.strapi.dirs.static.public,\n this.uploadsBackupDirectoryName\n );\n await fse.rm(backupDirectory, { recursive: true, force: true });\n this.#reportInfo('successfully removed assets backup');\n }\n }\n\n // TODO: Move this logic to the restore strategy\n async createAssetsWriteStream(): Promise<Writable> {\n assertValidStrapi(this.strapi, 'Not able to stream Assets');\n this.#reportInfo('creating assets write stream');\n if (!this.#areAssetsIncluded()) {\n throw new ProviderTransferError(\n 'Attempting to transfer assets when `assets` is not set in restore options'\n );\n }\n\n const removeAssetsBackup = this.#removeAssetsBackup.bind(this);\n const strapi = this.strapi;\n const transaction = this.transaction;\n const fileEntitiesMapper = this.#entitiesMapper['plugin::upload.file'];\n\n const restoreMediaEntitiesContent = this.#isContentTypeIncluded('plugin::upload.file');\n\n return new Writable({\n objectMode: true,\n async final(next) {\n // Delete the backup folder\n await removeAssetsBackup();\n next();\n },\n async write(chunk: IAsset, _encoding, callback) {\n await transaction?.attach(async () => {\n const uploadData = {\n ...chunk.metadata,\n stream: Readable.from(chunk.stream),\n buffer: chunk?.buffer,\n };\n\n const provider = strapi.config.get<{ provider: string }>('plugin::upload').provider;\n\n const fileId = fileEntitiesMapper?.[uploadData.id];\n if (!fileId) {\n return callback(new Error(`File ID not found for ID: ${uploadData.id}`));\n }\n\n try {\n await strapi.plugin('upload').provider.uploadStream(uploadData);\n\n // if we're not supposed to transfer the associated entities, stop here\n if (!restoreMediaEntitiesContent) {\n return callback();\n }\n\n // Files formats are stored within the parent file entity\n if (uploadData?.type) {\n const entry: IFile = await strapi.db.query('plugin::upload.file').findOne({\n where: { id: fileId },\n });\n if (!entry) {\n throw new Error('file not found');\n }\n const specificFormat = entry?.formats?.[uploadData.type];\n if (specificFormat) {\n specificFormat.url = uploadData.url;\n }\n await strapi.db.query('plugin::upload.file').update({\n where: { id: entry.id },\n data: {\n formats: entry.formats,\n provider,\n },\n });\n return callback();\n }\n\n const entry: IFile = await strapi.db.query('plugin::upload.file').findOne({\n where: { id: fileId },\n });\n if (!entry) {\n throw new Error('file not found');\n }\n entry.url = uploadData.url;\n await strapi.db.query('plugin::upload.file').update({\n where: { id: entry.id },\n data: {\n url: entry.url,\n provider,\n },\n });\n return callback();\n } catch (error) {\n return callback(new Error(`Error while uploading asset ${chunk.filename} ${error}`));\n }\n });\n },\n });\n }\n\n async createConfigurationWriteStream(): Promise<Writable> {\n assertValidStrapi(this.strapi, 'Not able to stream Configurations');\n this.#reportInfo('creating configuration write stream');\n const { strategy } = this.options;\n\n if (strategy === 'restore') {\n return restore.createConfigurationWriteStream(this.strapi, this.transaction);\n }\n\n throw new ProviderValidationError(`Invalid strategy ${strategy}`, {\n check: 'strategy',\n strategy,\n validStrategies: VALID_CONFLICT_STRATEGIES,\n });\n }\n\n async createLinksWriteStream(): Promise<Writable> {\n this.#reportInfo('creating links write stream');\n if (!this.strapi) {\n throw new Error('Not able to stream links. Strapi instance not found');\n }\n\n const { strategy } = this.options;\n const mapID = (uid: string, id: number): number | undefined => this.#entitiesMapper[uid]?.[id];\n\n if (strategy === 'restore') {\n return restore.createLinksWriteStream(mapID, this.strapi, this.transaction, this.onWarning);\n }\n\n throw new ProviderValidationError(`Invalid strategy ${strategy}`, {\n check: 'strategy',\n strategy,\n validStrategies: VALID_CONFLICT_STRATEGIES,\n });\n }\n}\n\nexport const createLocalStrapiDestinationProvider = (\n options: ILocalStrapiDestinationProviderOptions\n) => {\n return new LocalStrapiDestinationProvider(options);\n};\n"],"names":["VALID_CONFLICT_STRATEGIES","DEFAULT_CONFLICT_STRATEGY","LocalStrapiDestinationProvider","bootstrap","diagnostics","strapi","options","getStrapi","ProviderInitializationError","db","lifecycles","disable","transaction","utils","close","autoDestroy","assertValidStrapi","end","enable","undefined","destroy","rollback","beforeTransfer","Error","attach","trx","strategy","error","getMetadata","strapiVersion","config","get","createdAt","Date","toISOString","version","getSchemas","schemas","contentTypes","components","createEntitiesWriteStream","updateMappingTable","type","oldID","newID","Object","assign","restore","ProviderValidationError","check","validStrategies","createAssetsWriteStream","ProviderTransferError","removeAssetsBackup","bind","fileEntitiesMapper","restoreMediaEntitiesContent","Writable","objectMode","final","next","write","chunk","_encoding","callback","uploadData","metadata","stream","Readable","from","buffer","provider","fileId","id","plugin","uploadStream","entry","query","findOne","where","specificFormat","formats","url","update","data","filename","createConfigurationWriteStream","createLinksWriteStream","mapID","uid","onWarning","name","assets","notIncluded","entities","include","includes","excluded","exclude","uploadsBackupDirectoryName","now","message","report","details","origin","kind","queryBuilder","select","transacting","file","delete","fileFormat","values","assetsDirectory","path","join","dirs","static","public","backupDirectory","fse","access","constants","W_OK","R_OK","F_OK","move","mkdir","outputFile","err","code","rm","recursive","force","createLocalStrapiDestinationProvider"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAwBaA,yBAAAA,GAA4B;AAAC,IAAA;;AACnC,MAAMC,4BAA4B;IAyBvC,YAAA,iBAAA,8BAAA,CAAA,cAAA,CAAA;;AAIC,MACD;AAoBA,kBAAA,iBAAA,8BAAA,CAAA,oBAAA,CAAA,EAIA,sBAAA,iBAAA,8BAAA,CAAA,wBAAA,CAAA,EAWA,WAAA,iBAAA,8BAAA,CAAA,aAAA,CAAA,EAsB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IAAA;;IAEA,IAAI,IAAI,CAACA,MAAM,CAACyB,MAAM,CAACC,GAAG,CAAuB,gBAAA,CAAA,CAAkBwC,QAAQ,KAAK,OAAA,EAAS;QACvF,+BAAA,CAAA,IAAI,EAAC,WAAA,CAAA,CAAA,WAAA,CAAA,CAAY,wBAAA,CAAA;QACjBvD,6BAAAA,CAAkB,IAAI,CAACX,MAAM,CAAA;AAC7B,QAAA,MAAMkH,kBAAkBL,IAAAA,CAAKC,IAAI,CAC/B,IAAI,CAAC9G,MAAM,CAAC+G,IAAI,CAACC,MAAM,CAACC,MAAM,EAC9B,IAAI,CAACnB,0BAA0B,CAAA;QAEjC,MAAMqB,aAAAA,CAAIW,EAAE,CAACZ,eAAAA,EAAiB;YAAEa,SAAAA,EAAW,IAAA;YAAMC,KAAAA,EAAO;AAAK,SAAA,CAAA;QAC7D,+BAAA,CAAA,IAAI,EAAC,WAAA,CAAA,CAAA,WAAA,CAAA,CAAY,oCAAA,CAAA;AACnB,IAAA;AACF;AAmIK,MAAMC,uCAAuC,CAClDhI,OAAAA,GAAAA;AAEA,IAAA,OAAO,IAAIJ,8BAAAA,CAA+BI,OAAAA,CAAAA;AAC5C;;;;;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Writable, Readable } from 'stream';
|
|
2
2
|
import path from 'path';
|
|
3
|
-
import * as
|
|
3
|
+
import * as fs from 'fs-extra';
|
|
4
4
|
import { deleteRecords } from './strategies/restore/index.mjs';
|
|
5
5
|
import 'crypto';
|
|
6
6
|
import 'lodash/fp';
|
|
@@ -353,14 +353,14 @@ async function handleAssetsBackup() {
|
|
|
353
353
|
const backupDirectory = path.join(this.strapi.dirs.static.public, this.uploadsBackupDirectoryName);
|
|
354
354
|
try {
|
|
355
355
|
// Check access before attempting to do anything
|
|
356
|
-
await
|
|
357
|
-
|
|
356
|
+
await fs.access(assetsDirectory, // eslint-disable-next-line no-bitwise
|
|
357
|
+
fs.constants.W_OK | fs.constants.R_OK | fs.constants.F_OK);
|
|
358
358
|
// eslint-disable-next-line no-bitwise
|
|
359
|
-
await
|
|
360
|
-
await
|
|
361
|
-
await
|
|
359
|
+
await fs.access(path.join(assetsDirectory, '..'), fs.constants.W_OK | fs.constants.R_OK);
|
|
360
|
+
await fs.move(assetsDirectory, backupDirectory);
|
|
361
|
+
await fs.mkdir(assetsDirectory);
|
|
362
362
|
// Create a .gitkeep file to ensure the directory is not empty
|
|
363
|
-
await
|
|
363
|
+
await fs.outputFile(path.join(assetsDirectory, '.gitkeep'), '');
|
|
364
364
|
_class_private_field_loose_base(this, _reportInfo)[_reportInfo](`created assets backup directory ${backupDirectory}`);
|
|
365
365
|
} catch (err) {
|
|
366
366
|
throw new ProviderTransferError('The backup folder for the assets could not be created inside the public folder. Please ensure Strapi has write permissions on the public directory', {
|
|
@@ -381,7 +381,7 @@ async function removeAssetsBackup() {
|
|
|
381
381
|
_class_private_field_loose_base(this, _reportInfo)[_reportInfo]('removing assets backup');
|
|
382
382
|
assertValidStrapi(this.strapi);
|
|
383
383
|
const backupDirectory = path.join(this.strapi.dirs.static.public, this.uploadsBackupDirectoryName);
|
|
384
|
-
await
|
|
384
|
+
await fs.rm(backupDirectory, {
|
|
385
385
|
recursive: true,
|
|
386
386
|
force: true
|
|
387
387
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../../src/strapi/providers/local-destination/index.ts"],"sourcesContent":["import { Writable, Readable } from 'stream';\nimport path from 'path';\nimport * as fse from 'fs-extra';\nimport type { Knex } from 'knex';\nimport type { Core, Struct } from '@strapi/types';\nimport type {\n IAsset,\n IDestinationProvider,\n IFile,\n IMetadata,\n ProviderType,\n Transaction,\n} from '../../../../types';\nimport type { IDiagnosticReporter } from '../../../utils/diagnostic';\n\nimport { restore } from './strategies';\nimport * as utils from '../../../utils';\nimport {\n ProviderInitializationError,\n ProviderTransferError,\n ProviderValidationError,\n} from '../../../errors/providers';\nimport { assertValidStrapi } from '../../../utils/providers';\n\nexport const VALID_CONFLICT_STRATEGIES = ['restore'];\nexport const DEFAULT_CONFLICT_STRATEGY = 'restore';\n\nexport interface ILocalStrapiDestinationProviderOptions {\n getStrapi(): Core.Strapi | Promise<Core.Strapi>; // return an initialized instance of Strapi\n\n autoDestroy?: boolean; // shut down the instance returned by getStrapi() at the end of the transfer\n restore?: restore.IRestoreOptions; // erase data in strapi database before transfer; required if strategy is 'restore'\n strategy: 'restore'; // conflict management strategy; only the restore strategy is available at this time\n}\n\nclass LocalStrapiDestinationProvider implements IDestinationProvider {\n name = 'destination::local-strapi';\n\n type: ProviderType = 'destination';\n\n options: ILocalStrapiDestinationProviderOptions;\n\n strapi?: Core.Strapi;\n\n transaction?: Transaction;\n\n uploadsBackupDirectoryName: string;\n\n onWarning?: ((message: string) => void) | undefined;\n\n #diagnostics?: IDiagnosticReporter;\n\n /**\n * The entities mapper is used to map old entities to their new IDs\n */\n #entitiesMapper: { [type: string]: { [id: number]: number } };\n\n constructor(options: ILocalStrapiDestinationProviderOptions) {\n this.options = options;\n this.#entitiesMapper = {};\n this.uploadsBackupDirectoryName = `uploads_backup_${Date.now()}`;\n }\n\n async bootstrap(diagnostics?: IDiagnosticReporter): Promise<void> {\n this.#diagnostics = diagnostics;\n this.#validateOptions();\n this.strapi = await this.options.getStrapi();\n if (!this.strapi) {\n throw new ProviderInitializationError('Could not access local strapi');\n }\n this.strapi.db.lifecycles.disable();\n this.transaction = utils.transaction.createTransaction(this.strapi);\n }\n\n // TODO: either move this to restore strategy, or restore strategy should given access to these instead of repeating the logic possibly in a different way\n #areAssetsIncluded = () => {\n return this.options.restore?.assets;\n };\n\n #isContentTypeIncluded = (type: string) => {\n const notIncluded =\n this.options.restore?.entities?.include &&\n !this.options.restore?.entities?.include?.includes(type);\n const excluded =\n this.options.restore?.entities?.exclude &&\n this.options.restore?.entities.exclude.includes(type);\n\n return !excluded && !notIncluded;\n };\n\n #reportInfo(message: string) {\n this.#diagnostics?.report({\n details: {\n createdAt: new Date(),\n message,\n origin: 'local-destination-provider',\n },\n kind: 'info',\n });\n }\n\n async close(): Promise<void> {\n const { autoDestroy } = this.options;\n assertValidStrapi(this.strapi);\n this.transaction?.end();\n this.strapi.db.lifecycles.enable();\n // Basically `!== false` but more deterministic\n if (autoDestroy === undefined || autoDestroy === true) {\n await this.strapi?.destroy();\n }\n }\n\n #validateOptions() {\n this.#reportInfo('validating options');\n if (!VALID_CONFLICT_STRATEGIES.includes(this.options.strategy)) {\n throw new ProviderValidationError(`Invalid strategy ${this.options.strategy}`, {\n check: 'strategy',\n strategy: this.options.strategy,\n validStrategies: VALID_CONFLICT_STRATEGIES,\n });\n }\n\n // require restore options when using restore\n if (this.options.strategy === 'restore' && !this.options.restore) {\n throw new ProviderValidationError('Missing restore options');\n }\n }\n\n async #deleteFromRestoreOptions() {\n assertValidStrapi(this.strapi);\n if (!this.options.restore) {\n throw new ProviderValidationError('Missing restore options');\n }\n this.#reportInfo('deleting record ');\n return restore.deleteRecords(this.strapi, this.options.restore);\n }\n\n async #deleteAllAssets(trx?: Knex.Transaction) {\n assertValidStrapi(this.strapi);\n this.#reportInfo('deleting all assets');\n // if we're not restoring files, don't touch the files\n if (!this.#areAssetsIncluded()) {\n return;\n }\n\n const stream: Readable = this.strapi.db\n // Create a query builder instance (default type is 'select')\n .queryBuilder('plugin::upload.file')\n // Fetch all columns\n .select('*')\n // Attach the transaction\n .transacting(trx)\n // Get a readable stream\n .stream();\n\n // TODO use bulk delete when exists in providers\n for await (const file of stream) {\n await this.strapi.plugin('upload').provider.delete(file);\n if (file.formats) {\n for (const fileFormat of Object.values(file.formats)) {\n await this.strapi.plugin('upload').provider.delete(fileFormat);\n }\n }\n }\n\n this.#reportInfo('deleted all assets');\n }\n\n async rollback() {\n this.#reportInfo('Rolling back transaction');\n await this.transaction?.rollback();\n this.#reportInfo('Rolled back transaction');\n }\n\n async beforeTransfer() {\n if (!this.strapi) {\n throw new Error('Strapi instance not found');\n }\n\n await this.transaction?.attach(async (trx) => {\n try {\n if (this.options.strategy === 'restore') {\n await this.#handleAssetsBackup();\n await this.#deleteAllAssets(trx);\n await this.#deleteFromRestoreOptions();\n }\n } catch (error) {\n throw new Error(`restore failed ${error}`);\n }\n });\n }\n\n getMetadata(): IMetadata {\n this.#reportInfo('getting metadata');\n assertValidStrapi(this.strapi, 'Not able to get Schemas');\n const strapiVersion = this.strapi.config.get<string>('info.strapi');\n const createdAt = new Date().toISOString();\n\n return {\n createdAt,\n strapi: {\n version: strapiVersion,\n },\n };\n }\n\n getSchemas(): Record<string, Struct.Schema> {\n this.#reportInfo('getting schema');\n assertValidStrapi(this.strapi, 'Not able to get Schemas');\n\n const schemas = utils.schema.schemasToValidJSON({\n ...this.strapi.contentTypes,\n ...this.strapi.components,\n });\n\n return utils.schema.mapSchemasValues(schemas);\n }\n\n createEntitiesWriteStream(): Writable {\n assertValidStrapi(this.strapi, 'Not able to import entities');\n this.#reportInfo('creating entities stream');\n const { strategy } = this.options;\n\n const updateMappingTable = (type: string, oldID: number, newID: number) => {\n if (!this.#entitiesMapper[type]) {\n this.#entitiesMapper[type] = {};\n }\n\n Object.assign(this.#entitiesMapper[type], { [oldID]: newID });\n };\n\n if (strategy === 'restore') {\n return restore.createEntitiesWriteStream({\n strapi: this.strapi,\n updateMappingTable,\n transaction: this.transaction,\n });\n }\n\n throw new ProviderValidationError(`Invalid strategy ${this.options.strategy}`, {\n check: 'strategy',\n strategy: this.options.strategy,\n validStrategies: VALID_CONFLICT_STRATEGIES,\n });\n }\n\n async #handleAssetsBackup() {\n assertValidStrapi(this.strapi, 'Not able to create the assets backup');\n\n // if we're not restoring assets, don't back them up because they won't be touched\n if (!this.#areAssetsIncluded()) {\n return;\n }\n\n if (this.strapi.config.get<{ provider: string }>('plugin::upload').provider === 'local') {\n this.#reportInfo('creating assets backup directory');\n const assetsDirectory = path.join(this.strapi.dirs.static.public, 'uploads');\n const backupDirectory = path.join(\n this.strapi.dirs.static.public,\n this.uploadsBackupDirectoryName\n );\n\n try {\n // Check access before attempting to do anything\n await fse.access(\n assetsDirectory,\n // eslint-disable-next-line no-bitwise\n fse.constants.W_OK | fse.constants.R_OK | fse.constants.F_OK\n );\n // eslint-disable-next-line no-bitwise\n await fse.access(path.join(assetsDirectory, '..'), fse.constants.W_OK | fse.constants.R_OK);\n\n await fse.move(assetsDirectory, backupDirectory);\n await fse.mkdir(assetsDirectory);\n // Create a .gitkeep file to ensure the directory is not empty\n await fse.outputFile(path.join(assetsDirectory, '.gitkeep'), '');\n this.#reportInfo(`created assets backup directory ${backupDirectory}`);\n } catch (err) {\n throw new ProviderTransferError(\n 'The backup folder for the assets could not be created inside the public folder. Please ensure Strapi has write permissions on the public directory',\n {\n code: 'ASSETS_DIRECTORY_ERR',\n }\n );\n }\n return backupDirectory;\n }\n }\n\n async #removeAssetsBackup() {\n assertValidStrapi(this.strapi, 'Not able to remove Assets');\n // if we're not restoring assets, don't back them up because they won't be touched\n if (!this.#areAssetsIncluded()) {\n return;\n }\n // TODO: this should catch all thrown errors and bubble it up to engine so it can be reported as a non-fatal diagnostic message telling the user they may need to manually delete assets\n if (this.strapi.config.get<{ provider: string }>('plugin::upload').provider === 'local') {\n this.#reportInfo('removing assets backup');\n assertValidStrapi(this.strapi);\n const backupDirectory = path.join(\n this.strapi.dirs.static.public,\n this.uploadsBackupDirectoryName\n );\n await fse.rm(backupDirectory, { recursive: true, force: true });\n this.#reportInfo('successfully removed assets backup');\n }\n }\n\n // TODO: Move this logic to the restore strategy\n async createAssetsWriteStream(): Promise<Writable> {\n assertValidStrapi(this.strapi, 'Not able to stream Assets');\n this.#reportInfo('creating assets write stream');\n if (!this.#areAssetsIncluded()) {\n throw new ProviderTransferError(\n 'Attempting to transfer assets when `assets` is not set in restore options'\n );\n }\n\n const removeAssetsBackup = this.#removeAssetsBackup.bind(this);\n const strapi = this.strapi;\n const transaction = this.transaction;\n const fileEntitiesMapper = this.#entitiesMapper['plugin::upload.file'];\n\n const restoreMediaEntitiesContent = this.#isContentTypeIncluded('plugin::upload.file');\n\n return new Writable({\n objectMode: true,\n async final(next) {\n // Delete the backup folder\n await removeAssetsBackup();\n next();\n },\n async write(chunk: IAsset, _encoding, callback) {\n await transaction?.attach(async () => {\n const uploadData = {\n ...chunk.metadata,\n stream: Readable.from(chunk.stream),\n buffer: chunk?.buffer,\n };\n\n const provider = strapi.config.get<{ provider: string }>('plugin::upload').provider;\n\n const fileId = fileEntitiesMapper?.[uploadData.id];\n if (!fileId) {\n return callback(new Error(`File ID not found for ID: ${uploadData.id}`));\n }\n\n try {\n await strapi.plugin('upload').provider.uploadStream(uploadData);\n\n // if we're not supposed to transfer the associated entities, stop here\n if (!restoreMediaEntitiesContent) {\n return callback();\n }\n\n // Files formats are stored within the parent file entity\n if (uploadData?.type) {\n const entry: IFile = await strapi.db.query('plugin::upload.file').findOne({\n where: { id: fileId },\n });\n if (!entry) {\n throw new Error('file not found');\n }\n const specificFormat = entry?.formats?.[uploadData.type];\n if (specificFormat) {\n specificFormat.url = uploadData.url;\n }\n await strapi.db.query('plugin::upload.file').update({\n where: { id: entry.id },\n data: {\n formats: entry.formats,\n provider,\n },\n });\n return callback();\n }\n\n const entry: IFile = await strapi.db.query('plugin::upload.file').findOne({\n where: { id: fileId },\n });\n if (!entry) {\n throw new Error('file not found');\n }\n entry.url = uploadData.url;\n await strapi.db.query('plugin::upload.file').update({\n where: { id: entry.id },\n data: {\n url: entry.url,\n provider,\n },\n });\n return callback();\n } catch (error) {\n return callback(new Error(`Error while uploading asset ${chunk.filename} ${error}`));\n }\n });\n },\n });\n }\n\n async createConfigurationWriteStream(): Promise<Writable> {\n assertValidStrapi(this.strapi, 'Not able to stream Configurations');\n this.#reportInfo('creating configuration write stream');\n const { strategy } = this.options;\n\n if (strategy === 'restore') {\n return restore.createConfigurationWriteStream(this.strapi, this.transaction);\n }\n\n throw new ProviderValidationError(`Invalid strategy ${strategy}`, {\n check: 'strategy',\n strategy,\n validStrategies: VALID_CONFLICT_STRATEGIES,\n });\n }\n\n async createLinksWriteStream(): Promise<Writable> {\n this.#reportInfo('creating links write stream');\n if (!this.strapi) {\n throw new Error('Not able to stream links. Strapi instance not found');\n }\n\n const { strategy } = this.options;\n const mapID = (uid: string, id: number): number | undefined => this.#entitiesMapper[uid]?.[id];\n\n if (strategy === 'restore') {\n return restore.createLinksWriteStream(mapID, this.strapi, this.transaction, this.onWarning);\n }\n\n throw new ProviderValidationError(`Invalid strategy ${strategy}`, {\n check: 'strategy',\n strategy,\n validStrategies: VALID_CONFLICT_STRATEGIES,\n });\n }\n}\n\nexport const createLocalStrapiDestinationProvider = (\n options: ILocalStrapiDestinationProviderOptions\n) => {\n return new LocalStrapiDestinationProvider(options);\n};\n"],"names":["VALID_CONFLICT_STRATEGIES","DEFAULT_CONFLICT_STRATEGY","LocalStrapiDestinationProvider","bootstrap","diagnostics","strapi","options","getStrapi","ProviderInitializationError","db","lifecycles","disable","transaction","utils","close","autoDestroy","assertValidStrapi","end","enable","undefined","destroy","rollback","beforeTransfer","Error","attach","trx","strategy","error","getMetadata","strapiVersion","config","get","createdAt","Date","toISOString","version","getSchemas","schemas","contentTypes","components","createEntitiesWriteStream","updateMappingTable","type","oldID","newID","Object","assign","restore","ProviderValidationError","check","validStrategies","createAssetsWriteStream","ProviderTransferError","removeAssetsBackup","bind","fileEntitiesMapper","restoreMediaEntitiesContent","Writable","objectMode","final","next","write","chunk","_encoding","callback","uploadData","metadata","stream","Readable","from","buffer","provider","fileId","id","plugin","uploadStream","entry","query","findOne","where","specificFormat","formats","url","update","data","filename","createConfigurationWriteStream","createLinksWriteStream","mapID","uid","onWarning","name","assets","notIncluded","entities","include","includes","excluded","exclude","uploadsBackupDirectoryName","now","message","report","details","origin","kind","queryBuilder","select","transacting","file","delete","fileFormat","values","assetsDirectory","path","join","dirs","static","public","backupDirectory","fse","access","constants","W_OK","R_OK","F_OK","move","mkdir","outputFile","err","code","rm","recursive","force","createLocalStrapiDestinationProvider"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;MAw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AM;AACR,aAAA,CAAA;AAEJ,QAAA;QACA,OAAOX,eAAAA;AACT,IAAA;AACF;AAEA,eAAA,kBAAA,GAAA;IACEvG,iBAAAA,CAAkB,IAAI,CAACX,MAAM,EAAE,2BAAA,CAAA;;AAE/B,IAAA,IAAI,CAAC,+BAAA,CAAA,IAAI,EAAC,oBAAA,kBAAA,CAAA,EAAA,EAAsB;AAC9B,QAAA;AACF,IAAA;;IAEA,IAAI,IAAI,CAACA,MAAM,CAACyB,MAAM,CAACC,GAAG,CAAuB,gBAAA,CAAA,CAAkBwC,QAAQ,KAAK,OAAA,EAAS;QACvF,+BAAA,CAAA,IAAI,EAAC,WAAA,CAAA,CAAA,WAAA,CAAA,CAAY,wBAAA,CAAA;QACjBvD,iBAAAA,CAAkB,IAAI,CAACX,MAAM,CAAA;AAC7B,QAAA,MAAMkH,kBAAkBL,IAAAA,CAAKC,IAAI,CAC/B,IAAI,CAAC9G,MAAM,CAAC+G,IAAI,CAACC,MAAM,CAACC,MAAM,EAC9B,IAAI,CAACnB,0BAA0B,CAAA;QAEjC,MAAMqB,GAAAA,CAAIW,EAAE,CAACZ,eAAAA,EAAiB;YAAEa,SAAAA,EAAW,IAAA;YAAMC,KAAAA,EAAO;AAAK,SAAA,CAAA;QAC7D,+BAAA,CAAA,IAAI,EAAC,WAAA,CAAA,CAAA,WAAA,CAAA,CAAY,oCAAA,CAAA;AACnB,IAAA;AACF;AAmIK,MAAMC,uCAAuC,CAClDhI,OAAAA,GAAAA;AAEA,IAAA,OAAO,IAAIJ,8BAAAA,CAA+BI,OAAAA,CAAAA;AAC5C;;;;"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../../src/strapi/providers/local-destination/index.ts"],"sourcesContent":["import { Writable, Readable } from 'stream';\nimport path from 'path';\nimport * as fse from 'fs-extra';\nimport type { Knex } from 'knex';\nimport type { Core, Struct } from '@strapi/types';\nimport type {\n IAsset,\n IDestinationProvider,\n IFile,\n IMetadata,\n ProviderType,\n Transaction,\n} from '../../../../types';\nimport type { IDiagnosticReporter } from '../../../utils/diagnostic';\n\nimport { restore } from './strategies';\nimport * as utils from '../../../utils';\nimport {\n ProviderInitializationError,\n ProviderTransferError,\n ProviderValidationError,\n} from '../../../errors/providers';\nimport { assertValidStrapi } from '../../../utils/providers';\n\nexport const VALID_CONFLICT_STRATEGIES = ['restore'];\nexport const DEFAULT_CONFLICT_STRATEGY = 'restore';\n\nexport interface ILocalStrapiDestinationProviderOptions {\n getStrapi(): Core.Strapi | Promise<Core.Strapi>; // return an initialized instance of Strapi\n\n autoDestroy?: boolean; // shut down the instance returned by getStrapi() at the end of the transfer\n restore?: restore.IRestoreOptions; // erase data in strapi database before transfer; required if strategy is 'restore'\n strategy: 'restore'; // conflict management strategy; only the restore strategy is available at this time\n}\n\nclass LocalStrapiDestinationProvider implements IDestinationProvider {\n name = 'destination::local-strapi';\n\n type: ProviderType = 'destination';\n\n options: ILocalStrapiDestinationProviderOptions;\n\n strapi?: Core.Strapi;\n\n transaction?: Transaction;\n\n uploadsBackupDirectoryName: string;\n\n onWarning?: ((message: string) => void) | undefined;\n\n #diagnostics?: IDiagnosticReporter;\n\n /**\n * The entities mapper is used to map old entities to their new IDs\n */\n #entitiesMapper: { [type: string]: { [id: number]: number } };\n\n constructor(options: ILocalStrapiDestinationProviderOptions) {\n this.options = options;\n this.#entitiesMapper = {};\n this.uploadsBackupDirectoryName = `uploads_backup_${Date.now()}`;\n }\n\n async bootstrap(diagnostics?: IDiagnosticReporter): Promise<void> {\n this.#diagnostics = diagnostics;\n this.#validateOptions();\n this.strapi = await this.options.getStrapi();\n if (!this.strapi) {\n throw new ProviderInitializationError('Could not access local strapi');\n }\n this.strapi.db.lifecycles.disable();\n this.transaction = utils.transaction.createTransaction(this.strapi);\n }\n\n // TODO: either move this to restore strategy, or restore strategy should given access to these instead of repeating the logic possibly in a different way\n #areAssetsIncluded = () => {\n return this.options.restore?.assets;\n };\n\n #isContentTypeIncluded = (type: string) => {\n const notIncluded =\n this.options.restore?.entities?.include &&\n !this.options.restore?.entities?.include?.includes(type);\n const excluded =\n this.options.restore?.entities?.exclude &&\n this.options.restore?.entities.exclude.includes(type);\n\n return !excluded && !notIncluded;\n };\n\n #reportInfo(message: string) {\n this.#diagnostics?.report({\n details: {\n createdAt: new Date(),\n message,\n origin: 'local-destination-provider',\n },\n kind: 'info',\n });\n }\n\n async close(): Promise<void> {\n const { autoDestroy } = this.options;\n assertValidStrapi(this.strapi);\n this.transaction?.end();\n this.strapi.db.lifecycles.enable();\n // Basically `!== false` but more deterministic\n if (autoDestroy === undefined || autoDestroy === true) {\n await this.strapi?.destroy();\n }\n }\n\n #validateOptions() {\n this.#reportInfo('validating options');\n if (!VALID_CONFLICT_STRATEGIES.includes(this.options.strategy)) {\n throw new ProviderValidationError(`Invalid strategy ${this.options.strategy}`, {\n check: 'strategy',\n strategy: this.options.strategy,\n validStrategies: VALID_CONFLICT_STRATEGIES,\n });\n }\n\n // require restore options when using restore\n if (this.options.strategy === 'restore' && !this.options.restore) {\n throw new ProviderValidationError('Missing restore options');\n }\n }\n\n async #deleteFromRestoreOptions() {\n assertValidStrapi(this.strapi);\n if (!this.options.restore) {\n throw new ProviderValidationError('Missing restore options');\n }\n this.#reportInfo('deleting record ');\n return restore.deleteRecords(this.strapi, this.options.restore);\n }\n\n async #deleteAllAssets(trx?: Knex.Transaction) {\n assertValidStrapi(this.strapi);\n this.#reportInfo('deleting all assets');\n // if we're not restoring files, don't touch the files\n if (!this.#areAssetsIncluded()) {\n return;\n }\n\n const stream: Readable = this.strapi.db\n // Create a query builder instance (default type is 'select')\n .queryBuilder('plugin::upload.file')\n // Fetch all columns\n .select('*')\n // Attach the transaction\n .transacting(trx)\n // Get a readable stream\n .stream();\n\n // TODO use bulk delete when exists in providers\n for await (const file of stream) {\n await this.strapi.plugin('upload').provider.delete(file);\n if (file.formats) {\n for (const fileFormat of Object.values(file.formats)) {\n await this.strapi.plugin('upload').provider.delete(fileFormat);\n }\n }\n }\n\n this.#reportInfo('deleted all assets');\n }\n\n async rollback() {\n this.#reportInfo('Rolling back transaction');\n await this.transaction?.rollback();\n this.#reportInfo('Rolled back transaction');\n }\n\n async beforeTransfer() {\n if (!this.strapi) {\n throw new Error('Strapi instance not found');\n }\n\n await this.transaction?.attach(async (trx) => {\n try {\n if (this.options.strategy === 'restore') {\n await this.#handleAssetsBackup();\n await this.#deleteAllAssets(trx);\n await this.#deleteFromRestoreOptions();\n }\n } catch (error) {\n throw new Error(`restore failed ${error}`);\n }\n });\n }\n\n getMetadata(): IMetadata {\n this.#reportInfo('getting metadata');\n assertValidStrapi(this.strapi, 'Not able to get Schemas');\n const strapiVersion = this.strapi.config.get<string>('info.strapi');\n const createdAt = new Date().toISOString();\n\n return {\n createdAt,\n strapi: {\n version: strapiVersion,\n },\n };\n }\n\n getSchemas(): Record<string, Struct.Schema> {\n this.#reportInfo('getting schema');\n assertValidStrapi(this.strapi, 'Not able to get Schemas');\n\n const schemas = utils.schema.schemasToValidJSON({\n ...this.strapi.contentTypes,\n ...this.strapi.components,\n });\n\n return utils.schema.mapSchemasValues(schemas);\n }\n\n createEntitiesWriteStream(): Writable {\n assertValidStrapi(this.strapi, 'Not able to import entities');\n this.#reportInfo('creating entities stream');\n const { strategy } = this.options;\n\n const updateMappingTable = (type: string, oldID: number, newID: number) => {\n if (!this.#entitiesMapper[type]) {\n this.#entitiesMapper[type] = {};\n }\n\n Object.assign(this.#entitiesMapper[type], { [oldID]: newID });\n };\n\n if (strategy === 'restore') {\n return restore.createEntitiesWriteStream({\n strapi: this.strapi,\n updateMappingTable,\n transaction: this.transaction,\n });\n }\n\n throw new ProviderValidationError(`Invalid strategy ${this.options.strategy}`, {\n check: 'strategy',\n strategy: this.options.strategy,\n validStrategies: VALID_CONFLICT_STRATEGIES,\n });\n }\n\n async #handleAssetsBackup() {\n assertValidStrapi(this.strapi, 'Not able to create the assets backup');\n\n // if we're not restoring assets, don't back them up because they won't be touched\n if (!this.#areAssetsIncluded()) {\n return;\n }\n\n if (this.strapi.config.get<{ provider: string }>('plugin::upload').provider === 'local') {\n this.#reportInfo('creating assets backup directory');\n const assetsDirectory = path.join(this.strapi.dirs.static.public, 'uploads');\n const backupDirectory = path.join(\n this.strapi.dirs.static.public,\n this.uploadsBackupDirectoryName\n );\n\n try {\n // Check access before attempting to do anything\n await fse.access(\n assetsDirectory,\n // eslint-disable-next-line no-bitwise\n fse.constants.W_OK | fse.constants.R_OK | fse.constants.F_OK\n );\n // eslint-disable-next-line no-bitwise\n await fse.access(path.join(assetsDirectory, '..'), fse.constants.W_OK | fse.constants.R_OK);\n\n await fse.move(assetsDirectory, backupDirectory);\n await fse.mkdir(assetsDirectory);\n // Create a .gitkeep file to ensure the directory is not empty\n await fse.outputFile(path.join(assetsDirectory, '.gitkeep'), '');\n this.#reportInfo(`created assets backup directory ${backupDirectory}`);\n } catch (err) {\n throw new ProviderTransferError(\n 'The backup folder for the assets could not be created inside the public folder. Please ensure Strapi has write permissions on the public directory',\n {\n code: 'ASSETS_DIRECTORY_ERR',\n }\n );\n }\n return backupDirectory;\n }\n }\n\n async #removeAssetsBackup() {\n assertValidStrapi(this.strapi, 'Not able to remove Assets');\n // if we're not restoring assets, don't back them up because they won't be touched\n if (!this.#areAssetsIncluded()) {\n return;\n }\n // TODO: this should catch all thrown errors and bubble it up to engine so it can be reported as a non-fatal diagnostic message telling the user they may need to manually delete assets\n if (this.strapi.config.get<{ provider: string }>('plugin::upload').provider === 'local') {\n this.#reportInfo('removing assets backup');\n assertValidStrapi(this.strapi);\n const backupDirectory = path.join(\n this.strapi.dirs.static.public,\n this.uploadsBackupDirectoryName\n );\n await fse.rm(backupDirectory, { recursive: true, force: true });\n this.#reportInfo('successfully removed assets backup');\n }\n }\n\n // TODO: Move this logic to the restore strategy\n async createAssetsWriteStream(): Promise<Writable> {\n assertValidStrapi(this.strapi, 'Not able to stream Assets');\n this.#reportInfo('creating assets write stream');\n if (!this.#areAssetsIncluded()) {\n throw new ProviderTransferError(\n 'Attempting to transfer assets when `assets` is not set in restore options'\n );\n }\n\n const removeAssetsBackup = this.#removeAssetsBackup.bind(this);\n const strapi = this.strapi;\n const transaction = this.transaction;\n const fileEntitiesMapper = this.#entitiesMapper['plugin::upload.file'];\n\n const restoreMediaEntitiesContent = this.#isContentTypeIncluded('plugin::upload.file');\n\n return new Writable({\n objectMode: true,\n async final(next) {\n // Delete the backup folder\n await removeAssetsBackup();\n next();\n },\n async write(chunk: IAsset, _encoding, callback) {\n await transaction?.attach(async () => {\n const uploadData = {\n ...chunk.metadata,\n stream: Readable.from(chunk.stream),\n buffer: chunk?.buffer,\n };\n\n const provider = strapi.config.get<{ provider: string }>('plugin::upload').provider;\n\n const fileId = fileEntitiesMapper?.[uploadData.id];\n if (!fileId) {\n return callback(new Error(`File ID not found for ID: ${uploadData.id}`));\n }\n\n try {\n await strapi.plugin('upload').provider.uploadStream(uploadData);\n\n // if we're not supposed to transfer the associated entities, stop here\n if (!restoreMediaEntitiesContent) {\n return callback();\n }\n\n // Files formats are stored within the parent file entity\n if (uploadData?.type) {\n const entry: IFile = await strapi.db.query('plugin::upload.file').findOne({\n where: { id: fileId },\n });\n if (!entry) {\n throw new Error('file not found');\n }\n const specificFormat = entry?.formats?.[uploadData.type];\n if (specificFormat) {\n specificFormat.url = uploadData.url;\n }\n await strapi.db.query('plugin::upload.file').update({\n where: { id: entry.id },\n data: {\n formats: entry.formats,\n provider,\n },\n });\n return callback();\n }\n\n const entry: IFile = await strapi.db.query('plugin::upload.file').findOne({\n where: { id: fileId },\n });\n if (!entry) {\n throw new Error('file not found');\n }\n entry.url = uploadData.url;\n await strapi.db.query('plugin::upload.file').update({\n where: { id: entry.id },\n data: {\n url: entry.url,\n provider,\n },\n });\n return callback();\n } catch (error) {\n return callback(new Error(`Error while uploading asset ${chunk.filename} ${error}`));\n }\n });\n },\n });\n }\n\n async createConfigurationWriteStream(): Promise<Writable> {\n assertValidStrapi(this.strapi, 'Not able to stream Configurations');\n this.#reportInfo('creating configuration write stream');\n const { strategy } = this.options;\n\n if (strategy === 'restore') {\n return restore.createConfigurationWriteStream(this.strapi, this.transaction);\n }\n\n throw new ProviderValidationError(`Invalid strategy ${strategy}`, {\n check: 'strategy',\n strategy,\n validStrategies: VALID_CONFLICT_STRATEGIES,\n });\n }\n\n async createLinksWriteStream(): Promise<Writable> {\n this.#reportInfo('creating links write stream');\n if (!this.strapi) {\n throw new Error('Not able to stream links. Strapi instance not found');\n }\n\n const { strategy } = this.options;\n const mapID = (uid: string, id: number): number | undefined => this.#entitiesMapper[uid]?.[id];\n\n if (strategy === 'restore') {\n return restore.createLinksWriteStream(mapID, this.strapi, this.transaction, this.onWarning);\n }\n\n throw new ProviderValidationError(`Invalid strategy ${strategy}`, {\n check: 'strategy',\n strategy,\n validStrategies: VALID_CONFLICT_STRATEGIES,\n });\n }\n}\n\nexport const createLocalStrapiDestinationProvider = (\n options: ILocalStrapiDestinationProviderOptions\n) => {\n return new LocalStrapiDestinationProvider(options);\n};\n"],"names":["VALID_CONFLICT_STRATEGIES","DEFAULT_CONFLICT_STRATEGY","LocalStrapiDestinationProvider","bootstrap","diagnostics","strapi","options","getStrapi","ProviderInitializationError","db","lifecycles","disable","transaction","utils","close","autoDestroy","assertValidStrapi","end","enable","undefined","destroy","rollback","beforeTransfer","Error","attach","trx","strategy","error","getMetadata","strapiVersion","config","get","createdAt","Date","toISOString","version","getSchemas","schemas","contentTypes","components","createEntitiesWriteStream","updateMappingTable","type","oldID","newID","Object","assign","restore","ProviderValidationError","check","validStrategies","createAssetsWriteStream","ProviderTransferError","removeAssetsBackup","bind","fileEntitiesMapper","restoreMediaEntitiesContent","Writable","objectMode","final","next","write","chunk","_encoding","callback","uploadData","metadata","stream","Readable","from","buffer","provider","fileId","id","plugin","uploadStream","entry","query","findOne","where","specificFormat","formats","url","update","data","filename","createConfigurationWriteStream","createLinksWriteStream","mapID","uid","onWarning","name","assets","notIncluded","entities","include","includes","excluded","exclude","uploadsBackupDirectoryName","now","message","report","details","origin","kind","queryBuilder","select","transacting","file","delete","fileFormat","values","assetsDirectory","path","join","dirs","static","public","backupDirectory","fse","access","constants","W_OK","R_OK","F_OK","move","mkdir","outputFile","err","code","rm","recursive","force","createLocalStrapiDestinationProvider"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;MAwBaA,yBAAAA,GAA4B;AAAC,IAAA;;AACnC,MAAMC,4BAA4B;IAyBvC,YAAA,iBAAA,8BAAA,CAAA,cAAA,CAAA;;AAIC,MACD;AAoBA,kBAAA,iBAAA,8BAAA,CAAA,oBAAA,CAAA,EAIA,sBAAA,iBAAA,8BAAA,CAAA,wBAAA,CAAA,EAWA,WAAA,iBAAA,8BAAA,CAAA,aAAA,CAAA,EAsBA,gBAAA,iBAAA,8BAAA,CAAA,kBAAA,CAAA,EAgBM,yBAAA,iBAAA,8BAAA,CAAA,2BAAA,CAAA,EASA,qFA6GA,mBAAA,iBAAA,8BAAA,CAAA,qBAAA,CAAA,EA2CA,mBAAA,iBAAA,8BAAA,CAAA,qBAAA,CAAA;AA9PR,MAAMC,8BAAAA,CAAAA;IA4BJ,MAAMC,SAAAA,CAAUC,WAAiC,EAAiB;QAChE,+BAAA,CAAA,IAAI,EAAC,YAAA,CAAA,CAAA,YAAA,CAAA,GAAeA,WAAAA;QACpB,+BAAA,CAAA,IAAI,EAAC,gBAAA,CAAA,CAAA,gBAAA,CAAA,EAAA;QACL,IAAI,CAACC,MAAM,GAAG,MAAM,IAAI,CAACC,OAAO,CAACC,SAAS,EAAA;AAC1C,QAAA,IAAI,CAAC,IAAI,CAACF,MAAM,EAAE;AAChB,YAAA,MAAM,IAAIG,2BAAAA,CAA4B,+BAAA,CAAA;AACxC,QAAA;AACA,QAAA,IAAI,CAACH,MAAM,CAACI,EAAE,CAACC,UAAU,CAACC,OAAO,EAAA;QACjC,IAAI,CAACC,WAAW,GAAGC,iBAAmC,CAAC,IAAI,CAACR,MAAM,CAAA;AACpE,IAAA;AA6BA,IAAA,MAAMS,KAAAA,GAAuB;A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path = require('path');
|
|
4
4
|
var stream = require('stream');
|
|
5
|
-
var
|
|
5
|
+
var fs = require('fs-extra');
|
|
6
6
|
|
|
7
7
|
function getFileStream(filepath, strapi1, isLocal = false) {
|
|
8
8
|
if (isLocal) {
|
|
9
9
|
// Todo: handle errors
|
|
10
|
-
return
|
|
10
|
+
return fs.createReadStream(filepath);
|
|
11
11
|
}
|
|
12
12
|
const readableStream = new stream.PassThrough();
|
|
13
13
|
// fetch the image from remote url and stream it
|
|
@@ -29,7 +29,7 @@ function getFileStream(filepath, strapi1, isLocal = false) {
|
|
|
29
29
|
}
|
|
30
30
|
function getFileStats(filepath, strapi1, isLocal = false) {
|
|
31
31
|
if (isLocal) {
|
|
32
|
-
return
|
|
32
|
+
return fs.stat(filepath);
|
|
33
33
|
}
|
|
34
34
|
return new Promise((resolve, reject)=>{
|
|
35
35
|
strapi1.fetch(filepath).then((res)=>{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assets.js","sources":["../../../../src/strapi/providers/local-source/assets.ts"],"sourcesContent":["import { join } from 'path';\nimport { Duplex, PassThrough, Readable } from 'stream';\nimport { stat, createReadStream, ReadStream } from 'fs-extra';\nimport * as webStream from 'stream/web';\nimport type { Core } from '@strapi/types';\n\nimport type { IAsset, IFile } from '../../../../types';\n\nfunction getFileStream(\n filepath: string,\n strapi: Core.Strapi,\n isLocal = false\n): PassThrough | ReadStream {\n if (isLocal) {\n // Todo: handle errors\n return createReadStream(filepath);\n }\n\n const readableStream = new PassThrough();\n\n // fetch the image from remote url and stream it\n strapi\n .fetch(filepath)\n .then((res: Response) => {\n if (res.status !== 200) {\n readableStream.emit('error', new Error(`Request failed with status code ${res.status}`));\n return;\n }\n\n if (res.body) {\n // pipe the image data\n Readable.fromWeb(res.body as webStream.ReadableStream<Uint8Array>).pipe(readableStream);\n } else {\n readableStream.emit('error', new Error('Empty data found for file'));\n }\n })\n .catch((error: unknown) => {\n readableStream.emit('error', error);\n });\n\n return readableStream;\n}\n\nfunction getFileStats(\n filepath: string,\n strapi: Core.Strapi,\n isLocal = false\n): Promise<{ size: number }> {\n if (isLocal) {\n return stat(filepath);\n }\n return new Promise((resolve, reject) => {\n strapi\n .fetch(filepath)\n .then((res: Response) => {\n if (res.status !== 200) {\n reject(new Error(`Request failed with status code ${res.status}`));\n return;\n }\n\n const contentLength = res.headers.get('content-length');\n const stats = {\n size: contentLength ? parseInt(contentLength, 10) : 0,\n };\n\n resolve(stats);\n })\n .catch((error: unknown) => {\n reject(error);\n });\n });\n}\n\nasync function signFile(file: IFile) {\n const { provider } = strapi.plugins.upload;\n const { provider: providerName } = strapi.config.get('plugin.upload') as { provider: string };\n const isPrivate = await provider.isPrivate();\n if (file?.provider === providerName && isPrivate) {\n const signUrl = async (file: IFile) => {\n const signedUrl = await provider.getSignedUrl(file);\n file.url = signedUrl.url;\n };\n\n // Sign the original file\n await signUrl(file);\n // Sign each file format\n if (file.formats) {\n for (const format of Object.keys(file.formats)) {\n await signUrl(file.formats[format]);\n }\n }\n }\n}\n\n/**\n * Generate and consume assets streams in order to stream each file individually\n */\nexport const createAssetsStream = (strapi: Core.Strapi): Duplex => {\n const generator: () => AsyncGenerator<IAsset, void> = async function* () {\n const stream: Readable = strapi.db\n .queryBuilder('plugin::upload.file')\n // Create a query builder instance (default type is 'select')\n // Fetch all columns\n .select('*')\n // Get a readable stream\n .stream();\n\n for await (const file of stream) {\n const isLocalProvider = file.provider === 'local';\n if (!isLocalProvider) {\n await signFile(file);\n }\n const filepath = isLocalProvider ? join(strapi.dirs.static.public, file.url) : file.url;\n const stats = await getFileStats(filepath, strapi, isLocalProvider);\n const stream = getFileStream(filepath, strapi, isLocalProvider);\n\n yield {\n metadata: file,\n filepath,\n filename: file.hash + file.ext,\n stream,\n stats: { size: stats.size },\n };\n\n if (file.formats) {\n for (const format of Object.keys(file.formats)) {\n const fileFormat = file.formats[format];\n const fileFormatFilepath = isLocalProvider\n ? join(strapi.dirs.static.public, fileFormat.url)\n : fileFormat.url;\n const fileFormatStats = await getFileStats(fileFormatFilepath, strapi, isLocalProvider);\n const fileFormatStream = getFileStream(fileFormatFilepath, strapi, isLocalProvider);\n const metadata = { ...fileFormat, type: format, id: file.id, mainHash: file.hash };\n yield {\n metadata,\n filepath: fileFormatFilepath,\n filename: fileFormat.hash + fileFormat.ext,\n stream: fileFormatStream,\n stats: { size: fileFormatStats.size },\n };\n }\n }\n }\n };\n\n return Duplex.from(generator());\n};\n"],"names":["getFileStream","filepath","strapi","isLocal","createReadStream","readableStream","PassThrough","fetch","then","res","status","emit","Error","body","Readable","fromWeb","pipe","catch","error","getFileStats","stat","Promise","resolve","reject","contentLength","headers","get","stats","size","parseInt","signFile","file","provider","plugins","upload","providerName","config","isPrivate","signUrl","signedUrl","getSignedUrl","url","formats","format","Object","keys","createAssetsStream","generator","stream","db","queryBuilder","select","isLocalProvider","join","dirs","static","public","metadata","filename","hash","ext","fileFormat","fileFormatFilepath","fileFormatStats","fileFormatStream","type","id","mainHash","Duplex","from"],"mappings":";;;;;;AAQA,SAASA,cACPC,QAAgB,EAChBC,OAAmB,EACnBC,UAAU,KAAK,EAAA;AAEf,IAAA,IAAIA,OAAAA,EAAS;;AAEX,QAAA,OAAOC,
|
|
1
|
+
{"version":3,"file":"assets.js","sources":["../../../../src/strapi/providers/local-source/assets.ts"],"sourcesContent":["import { join } from 'path';\nimport { Duplex, PassThrough, Readable } from 'stream';\nimport { stat, createReadStream, ReadStream } from 'fs-extra';\nimport * as webStream from 'stream/web';\nimport type { Core } from '@strapi/types';\n\nimport type { IAsset, IFile } from '../../../../types';\n\nfunction getFileStream(\n filepath: string,\n strapi: Core.Strapi,\n isLocal = false\n): PassThrough | ReadStream {\n if (isLocal) {\n // Todo: handle errors\n return createReadStream(filepath);\n }\n\n const readableStream = new PassThrough();\n\n // fetch the image from remote url and stream it\n strapi\n .fetch(filepath)\n .then((res: Response) => {\n if (res.status !== 200) {\n readableStream.emit('error', new Error(`Request failed with status code ${res.status}`));\n return;\n }\n\n if (res.body) {\n // pipe the image data\n Readable.fromWeb(res.body as webStream.ReadableStream<Uint8Array>).pipe(readableStream);\n } else {\n readableStream.emit('error', new Error('Empty data found for file'));\n }\n })\n .catch((error: unknown) => {\n readableStream.emit('error', error);\n });\n\n return readableStream;\n}\n\nfunction getFileStats(\n filepath: string,\n strapi: Core.Strapi,\n isLocal = false\n): Promise<{ size: number }> {\n if (isLocal) {\n return stat(filepath);\n }\n return new Promise((resolve, reject) => {\n strapi\n .fetch(filepath)\n .then((res: Response) => {\n if (res.status !== 200) {\n reject(new Error(`Request failed with status code ${res.status}`));\n return;\n }\n\n const contentLength = res.headers.get('content-length');\n const stats = {\n size: contentLength ? parseInt(contentLength, 10) : 0,\n };\n\n resolve(stats);\n })\n .catch((error: unknown) => {\n reject(error);\n });\n });\n}\n\nasync function signFile(file: IFile) {\n const { provider } = strapi.plugins.upload;\n const { provider: providerName } = strapi.config.get('plugin.upload') as { provider: string };\n const isPrivate = await provider.isPrivate();\n if (file?.provider === providerName && isPrivate) {\n const signUrl = async (file: IFile) => {\n const signedUrl = await provider.getSignedUrl(file);\n file.url = signedUrl.url;\n };\n\n // Sign the original file\n await signUrl(file);\n // Sign each file format\n if (file.formats) {\n for (const format of Object.keys(file.formats)) {\n await signUrl(file.formats[format]);\n }\n }\n }\n}\n\n/**\n * Generate and consume assets streams in order to stream each file individually\n */\nexport const createAssetsStream = (strapi: Core.Strapi): Duplex => {\n const generator: () => AsyncGenerator<IAsset, void> = async function* () {\n const stream: Readable = strapi.db\n .queryBuilder('plugin::upload.file')\n // Create a query builder instance (default type is 'select')\n // Fetch all columns\n .select('*')\n // Get a readable stream\n .stream();\n\n for await (const file of stream) {\n const isLocalProvider = file.provider === 'local';\n if (!isLocalProvider) {\n await signFile(file);\n }\n const filepath = isLocalProvider ? join(strapi.dirs.static.public, file.url) : file.url;\n const stats = await getFileStats(filepath, strapi, isLocalProvider);\n const stream = getFileStream(filepath, strapi, isLocalProvider);\n\n yield {\n metadata: file,\n filepath,\n filename: file.hash + file.ext,\n stream,\n stats: { size: stats.size },\n };\n\n if (file.formats) {\n for (const format of Object.keys(file.formats)) {\n const fileFormat = file.formats[format];\n const fileFormatFilepath = isLocalProvider\n ? join(strapi.dirs.static.public, fileFormat.url)\n : fileFormat.url;\n const fileFormatStats = await getFileStats(fileFormatFilepath, strapi, isLocalProvider);\n const fileFormatStream = getFileStream(fileFormatFilepath, strapi, isLocalProvider);\n const metadata = { ...fileFormat, type: format, id: file.id, mainHash: file.hash };\n yield {\n metadata,\n filepath: fileFormatFilepath,\n filename: fileFormat.hash + fileFormat.ext,\n stream: fileFormatStream,\n stats: { size: fileFormatStats.size },\n };\n }\n }\n }\n };\n\n return Duplex.from(generator());\n};\n"],"names":["getFileStream","filepath","strapi","isLocal","createReadStream","readableStream","PassThrough","fetch","then","res","status","emit","Error","body","Readable","fromWeb","pipe","catch","error","getFileStats","stat","Promise","resolve","reject","contentLength","headers","get","stats","size","parseInt","signFile","file","provider","plugins","upload","providerName","config","isPrivate","signUrl","signedUrl","getSignedUrl","url","formats","format","Object","keys","createAssetsStream","generator","stream","db","queryBuilder","select","isLocalProvider","join","dirs","static","public","metadata","filename","hash","ext","fileFormat","fileFormatFilepath","fileFormatStats","fileFormatStream","type","id","mainHash","Duplex","from"],"mappings":";;;;;;AAQA,SAASA,cACPC,QAAgB,EAChBC,OAAmB,EACnBC,UAAU,KAAK,EAAA;AAEf,IAAA,IAAIA,OAAAA,EAAS;;AAEX,QAAA,OAAOC,mBAAAA,CAAiBH,QAAAA,CAAAA;AAC1B,IAAA;AAEA,IAAA,MAAMI,iBAAiB,IAAIC,kBAAAA,EAAAA;;AAG3BJ,IAAAA,OAAAA,CACGK,KAAK,CAACN,QAAAA,CAAAA,CACNO,IAAI,CAAC,CAACC,GAAAA,GAAAA;QACL,IAAIA,GAAAA,CAAIC,MAAM,KAAK,GAAA,EAAK;YACtBL,cAAAA,CAAeM,IAAI,CAAC,OAAA,EAAS,IAAIC,KAAAA,CAAM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pB,GAAG;AAClB,oBAAA,MAAMsB,eAAAA,GAAkB,MAAM5C,YAAAA,CAAa2C,kBAAAA,EAAoB5D,OAAAA,EAAQkD,eAAAA,CAAAA;oBACvE,MAAMY,gBAAAA,GAAmBhE,aAAAA,CAAc8D,kBAAAA,EAAoB5D,OAAAA,EAAQkD,eAAAA,CAAAA;AACnE,oBAAA,MAAMK,QAAAA,GAAW;AAAE,wBAAA,GAAGI,UAAU;wBAAEI,IAAAA,EAAMtB,MAAAA;AAAQuB,wBAAAA,EAAAA,EAAInC,KAAKmC,EAAE;AAAEC,wBAAAA,QAAAA,EAAUpC,KAAK4B;AAAK,qBAAA;oBACjF,MAAM;AACJF,wBAAAA,QAAAA;wBACAxD,QAAAA,EAAU6D,kBAAAA;AACVJ,wBAAAA,QAAAA,EAAUG,UAAAA,CAAWF,IAAI,GAAGE,UAAAA,CAAWD,GAAG;wBAC1CZ,MAAAA,EAAQgB,gBAAAA;wBACRrC,KAAAA,EAAO;AAAEC,4BAAAA,IAAAA,EAAMmC,gBAAgBnC;AAAK;AACtC,qBAAA;AACF,gBAAA;AACF,YAAA;AACF,QAAA;AACF,IAAA,CAAA;IAEA,OAAOwC,aAAAA,CAAOC,IAAI,CAACtB,SAAAA,EAAAA,CAAAA;AACrB;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/data-transfer",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.42.1",
|
|
4
4
|
"description": "Data transfer capabilities for Strapi",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"strapi",
|
|
@@ -51,15 +51,15 @@
|
|
|
51
51
|
"watch": "run -T rollup -c -w"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@strapi/logger": "5.
|
|
55
|
-
"@strapi/types": "5.
|
|
56
|
-
"@strapi/utils": "5.
|
|
54
|
+
"@strapi/logger": "5.42.1",
|
|
55
|
+
"@strapi/types": "5.42.1",
|
|
56
|
+
"@strapi/utils": "5.42.1",
|
|
57
57
|
"chalk": "4.1.2",
|
|
58
58
|
"cli-table3": "0.6.5",
|
|
59
59
|
"commander": "8.3.0",
|
|
60
60
|
"fs-extra": "11.2.0",
|
|
61
61
|
"inquirer": "9.3.8",
|
|
62
|
-
"lodash": "4.
|
|
62
|
+
"lodash": "4.18.1",
|
|
63
63
|
"ora": "5.4.1",
|
|
64
64
|
"resolve-cwd": "3.0.0",
|
|
65
65
|
"semver": "7.5.4",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"ws": "8.17.1"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
|
-
"@strapi/database": "5.
|
|
73
|
+
"@strapi/database": "5.42.1",
|
|
74
74
|
"@types/fs-extra": "11.0.4",
|
|
75
75
|
"@types/jest": "29.5.2",
|
|
76
76
|
"@types/koa": "2.13.4",
|