@strapi/data-transfer 4.20.2 → 4.20.4

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/index.js CHANGED
@@ -2076,6 +2076,7 @@ class LocalStrapiDestinationProvider {
2076
2076
  const strapi2 = this.strapi;
2077
2077
  const transaction2 = this.transaction;
2078
2078
  const backupDirectory = this.uploadsBackupDirectoryName;
2079
+ const fileEntitiesMapper = this.#entitiesMapper["plugin::upload.file"];
2079
2080
  const restoreMediaEntitiesContent = this.#isContentTypeIncluded("plugin::upload.file");
2080
2081
  return new stream$1.Writable({
2081
2082
  objectMode: true,
@@ -2122,15 +2123,16 @@ class LocalStrapiDestinationProvider {
2122
2123
  return callback();
2123
2124
  }
2124
2125
  if (uploadData?.type) {
2126
+ const condition = uploadData?.id ? { id: fileEntitiesMapper[uploadData.id] } : { hash: uploadData.mainHash };
2125
2127
  const entry2 = await strapi2.db.query("plugin::upload.file").findOne({
2126
- where: { hash: uploadData.mainHash }
2128
+ where: condition
2127
2129
  });
2128
2130
  const specificFormat = entry2?.formats?.[uploadData.type];
2129
2131
  if (specificFormat) {
2130
2132
  specificFormat.url = uploadData.url;
2131
2133
  }
2132
2134
  await strapi2.db.query("plugin::upload.file").update({
2133
- where: { hash: uploadData.mainHash },
2135
+ where: { id: entry2.id },
2134
2136
  data: {
2135
2137
  formats: entry2.formats,
2136
2138
  provider
@@ -2139,11 +2141,11 @@ class LocalStrapiDestinationProvider {
2139
2141
  return callback();
2140
2142
  }
2141
2143
  const entry = await strapi2.db.query("plugin::upload.file").findOne({
2142
- where: { hash: uploadData.hash }
2144
+ where: { id: fileEntitiesMapper[uploadData.id] }
2143
2145
  });
2144
2146
  entry.url = uploadData.url;
2145
2147
  await strapi2.db.query("plugin::upload.file").update({
2146
- where: { hash: uploadData.hash },
2148
+ where: { id: entry.id },
2147
2149
  data: {
2148
2150
  url: entry.url,
2149
2151
  provider
@@ -2328,7 +2330,7 @@ const createAssetsStream = (strapi2) => {
2328
2330
  const fileFormatFilepath = isLocalProvider ? path.join(strapi2.dirs.static.public, fileFormat.url) : fileFormat.url;
2329
2331
  const fileFormatStats = await getFileStats(fileFormatFilepath, isLocalProvider);
2330
2332
  const fileFormatStream = getFileStream(fileFormatFilepath, isLocalProvider);
2331
- const metadata = { ...fileFormat, type: format, mainHash: file2.hash };
2333
+ const metadata = { ...fileFormat, type: format, id: file2.id, mainHash: file2.hash };
2332
2334
  yield {
2333
2335
  metadata,
2334
2336
  filepath: fileFormatFilepath,
@@ -2407,7 +2409,7 @@ class LocalStrapiSourceProvider {
2407
2409
  }
2408
2410
  const createDispatcher = (ws2, retryMessageOptions = {
2409
2411
  retryMessageMaxRetries: 5,
2410
- retryMessageTimeout: 15e3
2412
+ retryMessageTimeout: 3e4
2411
2413
  }) => {
2412
2414
  const state = {};
2413
2415
  const dispatch = async (message, options = {}) => {
@@ -2835,16 +2837,15 @@ class RemoteStrapiSourceProvider {
2835
2837
  }
2836
2838
  const { uuid, data: message } = parsed;
2837
2839
  const { ended, error, data } = message;
2838
- if (ended) {
2840
+ if (error) {
2839
2841
  await this.#respond(uuid);
2840
- await this.#endStep(stage);
2841
- stream2.end();
2842
+ stream2.destroy(error);
2842
2843
  return;
2843
2844
  }
2844
- if (error) {
2845
+ if (ended) {
2845
2846
  await this.#respond(uuid);
2846
2847
  await this.#endStep(stage);
2847
- stream2.destroy(error);
2848
+ stream2.end();
2848
2849
  return;
2849
2850
  }
2850
2851
  for (const item of fp.castArray(data)) {
@@ -3752,13 +3753,23 @@ const createPullController = handlerControllerFactory((proto) => ({
3752
3753
  }
3753
3754
  try {
3754
3755
  for await (const chunk of stream2) {
3755
- batch.push(chunk);
3756
- if (batchLength() >= batchSize) {
3757
- await sendBatch();
3758
- batch = [];
3756
+ if (stage !== "assets") {
3757
+ batch.push(chunk);
3758
+ if (batchLength() >= batchSize) {
3759
+ await sendBatch();
3760
+ batch = [];
3761
+ }
3762
+ } else {
3763
+ await this.confirm({
3764
+ type: "transfer",
3765
+ data: [chunk],
3766
+ ended: false,
3767
+ error: null,
3768
+ id
3769
+ });
3759
3770
  }
3760
3771
  }
3761
- if (batch.length > 0) {
3772
+ if (batch.length > 0 && stage !== "assets") {
3762
3773
  await sendBatch();
3763
3774
  batch = [];
3764
3775
  }