@strapi/data-transfer 4.20.2 → 4.20.3

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.mjs CHANGED
@@ -2043,6 +2043,7 @@ class LocalStrapiDestinationProvider {
2043
2043
  const strapi2 = this.strapi;
2044
2044
  const transaction2 = this.transaction;
2045
2045
  const backupDirectory = this.uploadsBackupDirectoryName;
2046
+ const fileEntitiesMapper = this.#entitiesMapper["plugin::upload.file"];
2046
2047
  const restoreMediaEntitiesContent = this.#isContentTypeIncluded("plugin::upload.file");
2047
2048
  return new Writable({
2048
2049
  objectMode: true,
@@ -2089,15 +2090,16 @@ class LocalStrapiDestinationProvider {
2089
2090
  return callback();
2090
2091
  }
2091
2092
  if (uploadData?.type) {
2093
+ const condition = uploadData?.id ? { id: fileEntitiesMapper[uploadData.id] } : { hash: uploadData.mainHash };
2092
2094
  const entry2 = await strapi2.db.query("plugin::upload.file").findOne({
2093
- where: { hash: uploadData.mainHash }
2095
+ where: condition
2094
2096
  });
2095
2097
  const specificFormat = entry2?.formats?.[uploadData.type];
2096
2098
  if (specificFormat) {
2097
2099
  specificFormat.url = uploadData.url;
2098
2100
  }
2099
2101
  await strapi2.db.query("plugin::upload.file").update({
2100
- where: { hash: uploadData.mainHash },
2102
+ where: { id: entry2.id },
2101
2103
  data: {
2102
2104
  formats: entry2.formats,
2103
2105
  provider
@@ -2106,11 +2108,11 @@ class LocalStrapiDestinationProvider {
2106
2108
  return callback();
2107
2109
  }
2108
2110
  const entry = await strapi2.db.query("plugin::upload.file").findOne({
2109
- where: { hash: uploadData.hash }
2111
+ where: { id: fileEntitiesMapper[uploadData.id] }
2110
2112
  });
2111
2113
  entry.url = uploadData.url;
2112
2114
  await strapi2.db.query("plugin::upload.file").update({
2113
- where: { hash: uploadData.hash },
2115
+ where: { id: entry.id },
2114
2116
  data: {
2115
2117
  url: entry.url,
2116
2118
  provider
@@ -2295,7 +2297,7 @@ const createAssetsStream = (strapi2) => {
2295
2297
  const fileFormatFilepath = isLocalProvider ? join(strapi2.dirs.static.public, fileFormat.url) : fileFormat.url;
2296
2298
  const fileFormatStats = await getFileStats(fileFormatFilepath, isLocalProvider);
2297
2299
  const fileFormatStream = getFileStream(fileFormatFilepath, isLocalProvider);
2298
- const metadata = { ...fileFormat, type: format, mainHash: file2.hash };
2300
+ const metadata = { ...fileFormat, type: format, id: file2.id, mainHash: file2.hash };
2299
2301
  yield {
2300
2302
  metadata,
2301
2303
  filepath: fileFormatFilepath,
@@ -2374,7 +2376,7 @@ class LocalStrapiSourceProvider {
2374
2376
  }
2375
2377
  const createDispatcher = (ws, retryMessageOptions = {
2376
2378
  retryMessageMaxRetries: 5,
2377
- retryMessageTimeout: 15e3
2379
+ retryMessageTimeout: 3e4
2378
2380
  }) => {
2379
2381
  const state = {};
2380
2382
  const dispatch = async (message, options = {}) => {
@@ -2802,16 +2804,15 @@ class RemoteStrapiSourceProvider {
2802
2804
  }
2803
2805
  const { uuid, data: message } = parsed;
2804
2806
  const { ended, error, data } = message;
2805
- if (ended) {
2807
+ if (error) {
2806
2808
  await this.#respond(uuid);
2807
- await this.#endStep(stage);
2808
- stream2.end();
2809
+ stream2.destroy(error);
2809
2810
  return;
2810
2811
  }
2811
- if (error) {
2812
+ if (ended) {
2812
2813
  await this.#respond(uuid);
2813
2814
  await this.#endStep(stage);
2814
- stream2.destroy(error);
2815
+ stream2.end();
2815
2816
  return;
2816
2817
  }
2817
2818
  for (const item of castArray(data)) {
@@ -3719,13 +3720,23 @@ const createPullController = handlerControllerFactory((proto) => ({
3719
3720
  }
3720
3721
  try {
3721
3722
  for await (const chunk of stream2) {
3722
- batch.push(chunk);
3723
- if (batchLength() >= batchSize) {
3724
- await sendBatch();
3725
- batch = [];
3723
+ if (stage !== "assets") {
3724
+ batch.push(chunk);
3725
+ if (batchLength() >= batchSize) {
3726
+ await sendBatch();
3727
+ batch = [];
3728
+ }
3729
+ } else {
3730
+ await this.confirm({
3731
+ type: "transfer",
3732
+ data: [chunk],
3733
+ ended: false,
3734
+ error: null,
3735
+ id
3736
+ });
3726
3737
  }
3727
3738
  }
3728
- if (batch.length > 0) {
3739
+ if (batch.length > 0 && stage !== "assets") {
3729
3740
  await sendBatch();
3730
3741
  batch = [];
3731
3742
  }