@strapi/data-transfer 5.42.1 → 5.43.0

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.
Files changed (126) hide show
  1. package/dist/directory/providers/source/index.d.ts.map +1 -1
  2. package/dist/directory/providers/source/index.js +3 -2
  3. package/dist/directory/providers/source/index.js.map +1 -1
  4. package/dist/directory/providers/source/index.mjs +3 -2
  5. package/dist/directory/providers/source/index.mjs.map +1 -1
  6. package/dist/engine/index.d.ts.map +1 -1
  7. package/dist/engine/index.js +130 -5
  8. package/dist/engine/index.js.map +1 -1
  9. package/dist/engine/index.mjs +130 -5
  10. package/dist/engine/index.mjs.map +1 -1
  11. package/dist/engine/validation/schemas/index.js +2 -0
  12. package/dist/engine/validation/schemas/index.js.map +1 -1
  13. package/dist/engine/validation/schemas/index.mjs +2 -0
  14. package/dist/engine/validation/schemas/index.mjs.map +1 -1
  15. package/dist/file/providers/source/index.d.ts.map +1 -1
  16. package/dist/file/providers/source/index.js +84 -45
  17. package/dist/file/providers/source/index.js.map +1 -1
  18. package/dist/file/providers/source/index.mjs +85 -46
  19. package/dist/file/providers/source/index.mjs.map +1 -1
  20. package/dist/strapi/providers/index.js +2 -0
  21. package/dist/strapi/providers/index.js.map +1 -1
  22. package/dist/strapi/providers/index.mjs +1 -0
  23. package/dist/strapi/providers/index.mjs.map +1 -1
  24. package/dist/strapi/providers/local-destination/assets-destination-writable.d.ts +22 -0
  25. package/dist/strapi/providers/local-destination/assets-destination-writable.d.ts.map +1 -0
  26. package/dist/strapi/providers/local-destination/assets-destination-writable.js +107 -0
  27. package/dist/strapi/providers/local-destination/assets-destination-writable.js.map +1 -0
  28. package/dist/strapi/providers/local-destination/assets-destination-writable.mjs +105 -0
  29. package/dist/strapi/providers/local-destination/assets-destination-writable.mjs.map +1 -0
  30. package/dist/strapi/providers/local-destination/index.d.ts +2 -0
  31. package/dist/strapi/providers/local-destination/index.d.ts.map +1 -1
  32. package/dist/strapi/providers/local-destination/index.js +18 -79
  33. package/dist/strapi/providers/local-destination/index.js.map +1 -1
  34. package/dist/strapi/providers/local-destination/index.mjs +18 -79
  35. package/dist/strapi/providers/local-destination/index.mjs.map +1 -1
  36. package/dist/strapi/providers/local-destination/strategies/restore/entities.js +2 -0
  37. package/dist/strapi/providers/local-destination/strategies/restore/entities.js.map +1 -1
  38. package/dist/strapi/providers/local-destination/strategies/restore/entities.mjs +2 -0
  39. package/dist/strapi/providers/local-destination/strategies/restore/entities.mjs.map +1 -1
  40. package/dist/strapi/providers/local-destination/strategies/restore/index.js +2 -0
  41. package/dist/strapi/providers/local-destination/strategies/restore/index.js.map +1 -1
  42. package/dist/strapi/providers/local-destination/strategies/restore/index.mjs +2 -0
  43. package/dist/strapi/providers/local-destination/strategies/restore/index.mjs.map +1 -1
  44. package/dist/strapi/providers/local-source/assets.d.ts +8 -1
  45. package/dist/strapi/providers/local-source/assets.d.ts.map +1 -1
  46. package/dist/strapi/providers/local-source/assets.js +47 -19
  47. package/dist/strapi/providers/local-source/assets.js.map +1 -1
  48. package/dist/strapi/providers/local-source/assets.mjs +46 -20
  49. package/dist/strapi/providers/local-source/assets.mjs.map +1 -1
  50. package/dist/strapi/providers/local-source/estimate-asset-totals.d.ts +11 -0
  51. package/dist/strapi/providers/local-source/estimate-asset-totals.d.ts.map +1 -0
  52. package/dist/strapi/providers/local-source/estimate-asset-totals.js +130 -0
  53. package/dist/strapi/providers/local-source/estimate-asset-totals.js.map +1 -0
  54. package/dist/strapi/providers/local-source/estimate-asset-totals.mjs +128 -0
  55. package/dist/strapi/providers/local-source/estimate-asset-totals.mjs.map +1 -0
  56. package/dist/strapi/providers/local-source/index.d.ts +3 -2
  57. package/dist/strapi/providers/local-source/index.d.ts.map +1 -1
  58. package/dist/strapi/providers/local-source/index.js +30 -3
  59. package/dist/strapi/providers/local-source/index.js.map +1 -1
  60. package/dist/strapi/providers/local-source/index.mjs +30 -4
  61. package/dist/strapi/providers/local-source/index.mjs.map +1 -1
  62. package/dist/strapi/providers/remote-destination/index.d.ts +3 -1
  63. package/dist/strapi/providers/remote-destination/index.d.ts.map +1 -1
  64. package/dist/strapi/providers/remote-destination/index.js +88 -19
  65. package/dist/strapi/providers/remote-destination/index.js.map +1 -1
  66. package/dist/strapi/providers/remote-destination/index.mjs +89 -20
  67. package/dist/strapi/providers/remote-destination/index.mjs.map +1 -1
  68. package/dist/strapi/providers/remote-source/index.d.ts +6 -3
  69. package/dist/strapi/providers/remote-source/index.d.ts.map +1 -1
  70. package/dist/strapi/providers/remote-source/index.js +180 -47
  71. package/dist/strapi/providers/remote-source/index.js.map +1 -1
  72. package/dist/strapi/providers/remote-source/index.mjs +181 -48
  73. package/dist/strapi/providers/remote-source/index.mjs.map +1 -1
  74. package/dist/strapi/providers/utils.d.ts +9 -6
  75. package/dist/strapi/providers/utils.d.ts.map +1 -1
  76. package/dist/strapi/providers/utils.js +9 -4
  77. package/dist/strapi/providers/utils.js.map +1 -1
  78. package/dist/strapi/providers/utils.mjs +9 -4
  79. package/dist/strapi/providers/utils.mjs.map +1 -1
  80. package/dist/strapi/remote/handlers/pull.d.ts +1 -0
  81. package/dist/strapi/remote/handlers/pull.d.ts.map +1 -1
  82. package/dist/strapi/remote/handlers/pull.js +36 -15
  83. package/dist/strapi/remote/handlers/pull.js.map +1 -1
  84. package/dist/strapi/remote/handlers/pull.mjs +37 -16
  85. package/dist/strapi/remote/handlers/pull.mjs.map +1 -1
  86. package/dist/strapi/remote/handlers/push.d.ts +13 -2
  87. package/dist/strapi/remote/handlers/push.d.ts.map +1 -1
  88. package/dist/strapi/remote/handlers/push.js +81 -34
  89. package/dist/strapi/remote/handlers/push.js.map +1 -1
  90. package/dist/strapi/remote/handlers/push.mjs +82 -35
  91. package/dist/strapi/remote/handlers/push.mjs.map +1 -1
  92. package/dist/strapi/remote/handlers/utils.d.ts.map +1 -1
  93. package/dist/strapi/remote/handlers/utils.js +5 -3
  94. package/dist/strapi/remote/handlers/utils.js.map +1 -1
  95. package/dist/strapi/remote/handlers/utils.mjs +5 -3
  96. package/dist/strapi/remote/handlers/utils.mjs.map +1 -1
  97. package/dist/utils/index.d.ts +2 -0
  98. package/dist/utils/index.d.ts.map +1 -1
  99. package/dist/utils/index.js +7 -0
  100. package/dist/utils/index.js.map +1 -1
  101. package/dist/utils/index.mjs +2 -0
  102. package/dist/utils/index.mjs.map +1 -1
  103. package/dist/utils/stream.d.ts.map +1 -1
  104. package/dist/utils/stream.js +40 -3
  105. package/dist/utils/stream.js.map +1 -1
  106. package/dist/utils/stream.mjs +40 -3
  107. package/dist/utils/stream.mjs.map +1 -1
  108. package/dist/utils/transfer-asset-chunk.d.ts +41 -0
  109. package/dist/utils/transfer-asset-chunk.d.ts.map +1 -0
  110. package/dist/utils/transfer-asset-chunk.js +93 -0
  111. package/dist/utils/transfer-asset-chunk.js.map +1 -0
  112. package/dist/utils/transfer-asset-chunk.mjs +88 -0
  113. package/dist/utils/transfer-asset-chunk.mjs.map +1 -0
  114. package/dist/utils/transfer-websocket-json.d.ts +24 -0
  115. package/dist/utils/transfer-websocket-json.d.ts.map +1 -0
  116. package/dist/utils/transfer-websocket-json.js +67 -0
  117. package/dist/utils/transfer-websocket-json.js.map +1 -0
  118. package/dist/utils/transfer-websocket-json.mjs +63 -0
  119. package/dist/utils/transfer-websocket-json.mjs.map +1 -0
  120. package/dist/utils/writable-async-write.d.ts +17 -0
  121. package/dist/utils/writable-async-write.d.ts.map +1 -0
  122. package/dist/utils/writable-async-write.js +61 -0
  123. package/dist/utils/writable-async-write.js.map +1 -0
  124. package/dist/utils/writable-async-write.mjs +59 -0
  125. package/dist/utils/writable-async-write.mjs.map +1 -0
  126. package/package.json +5 -5
@@ -2,14 +2,14 @@ import { join } from 'path';
2
2
  import { Duplex, PassThrough, Readable } from 'stream';
3
3
  import { stat, createReadStream } from 'fs-extra';
4
4
 
5
- function getFileStream(filepath, strapi1, isLocal = false) {
5
+ function getFileStream(filepath, strapi, isLocal = false) {
6
6
  if (isLocal) {
7
7
  // Todo: handle errors
8
8
  return createReadStream(filepath);
9
9
  }
10
10
  const readableStream = new PassThrough();
11
11
  // fetch the image from remote url and stream it
12
- strapi1.fetch(filepath).then((res)=>{
12
+ strapi.fetch(filepath).then((res)=>{
13
13
  if (res.status !== 200) {
14
14
  readableStream.emit('error', new Error(`Request failed with status code ${res.status}`));
15
15
  return;
@@ -25,12 +25,12 @@ function getFileStream(filepath, strapi1, isLocal = false) {
25
25
  });
26
26
  return readableStream;
27
27
  }
28
- function getFileStats(filepath, strapi1, isLocal = false) {
28
+ function getFileStatsForTransfer(filepath, strapi, isLocal = false) {
29
29
  if (isLocal) {
30
30
  return stat(filepath);
31
31
  }
32
32
  return new Promise((resolve, reject)=>{
33
- strapi1.fetch(filepath).then((res)=>{
33
+ strapi.fetch(filepath).then((res)=>{
34
34
  if (res.status !== 200) {
35
35
  reject(new Error(`Request failed with status code ${res.status}`));
36
36
  return;
@@ -45,18 +45,16 @@ function getFileStats(filepath, strapi1, isLocal = false) {
45
45
  });
46
46
  });
47
47
  }
48
- async function signFile(file) {
48
+ async function signUploadFileForTransfer(strapi, file) {
49
49
  const { provider } = strapi.plugins.upload;
50
50
  const { provider: providerName } = strapi.config.get('plugin.upload');
51
51
  const isPrivate = await provider.isPrivate();
52
52
  if (file?.provider === providerName && isPrivate) {
53
- const signUrl = async (file)=>{
54
- const signedUrl = await provider.getSignedUrl(file);
55
- file.url = signedUrl.url;
53
+ const signUrl = async (f)=>{
54
+ const signedUrl = await provider.getSignedUrl(f);
55
+ f.url = signedUrl.url;
56
56
  };
57
- // Sign the original file
58
57
  await signUrl(file);
59
- // Sign each file format
60
58
  if (file.formats) {
61
59
  for (const format of Object.keys(file.formats)){
62
60
  await signUrl(file.formats[format]);
@@ -64,22 +62,40 @@ async function signFile(file) {
64
62
  }
65
63
  }
66
64
  }
65
+ const missingAssetWarningMessage = (file, filepath, format)=>{
66
+ const formatPart = format ? ` (format: ${format})` : '';
67
+ return `[Data transfer] Media item ${file.id} (hash: ${file.hash}) exists in database but no corresponding file was found to transfer${formatPart}. Path: ${filepath}`;
68
+ };
67
69
  /**
68
70
  * Generate and consume assets streams in order to stream each file individually
69
- */ const createAssetsStream = (strapi1)=>{
71
+ */ const createAssetsStream = (strapi, options = {})=>{
72
+ const warnMissingAsset = (message)=>{
73
+ strapi.log.warn(message);
74
+ options.onWarning?.(message);
75
+ };
70
76
  const generator = async function*() {
71
- const stream = strapi1.db.queryBuilder('plugin::upload.file')// Create a query builder instance (default type is 'select')
77
+ const stream = strapi.db.queryBuilder('plugin::upload.file')// Create a query builder instance (default type is 'select')
72
78
  // Fetch all columns
73
79
  .select('*')// Get a readable stream
74
80
  .stream();
75
81
  for await (const file of stream){
76
82
  const isLocalProvider = file.provider === 'local';
77
83
  if (!isLocalProvider) {
78
- await signFile(file);
84
+ await signUploadFileForTransfer(strapi, file);
79
85
  }
80
- const filepath = isLocalProvider ? join(strapi1.dirs.static.public, file.url) : file.url;
81
- const stats = await getFileStats(filepath, strapi1, isLocalProvider);
82
- const stream = getFileStream(filepath, strapi1, isLocalProvider);
86
+ const filepath = isLocalProvider ? join(strapi.dirs.static.public, file.url) : file.url;
87
+ let stats;
88
+ try {
89
+ stats = await getFileStatsForTransfer(filepath, strapi, isLocalProvider);
90
+ } catch (err) {
91
+ const code = err && typeof err === 'object' && 'code' in err ? err.code : undefined;
92
+ if (code === 'ENOENT') {
93
+ warnMissingAsset(missingAssetWarningMessage(file, filepath));
94
+ continue;
95
+ }
96
+ throw err;
97
+ }
98
+ const stream = getFileStream(filepath, strapi, isLocalProvider);
83
99
  yield {
84
100
  metadata: file,
85
101
  filepath,
@@ -92,9 +108,19 @@ async function signFile(file) {
92
108
  if (file.formats) {
93
109
  for (const format of Object.keys(file.formats)){
94
110
  const fileFormat = file.formats[format];
95
- const fileFormatFilepath = isLocalProvider ? join(strapi1.dirs.static.public, fileFormat.url) : fileFormat.url;
96
- const fileFormatStats = await getFileStats(fileFormatFilepath, strapi1, isLocalProvider);
97
- const fileFormatStream = getFileStream(fileFormatFilepath, strapi1, isLocalProvider);
111
+ const fileFormatFilepath = isLocalProvider ? join(strapi.dirs.static.public, fileFormat.url) : fileFormat.url;
112
+ let fileFormatStats;
113
+ try {
114
+ fileFormatStats = await getFileStatsForTransfer(fileFormatFilepath, strapi, isLocalProvider);
115
+ } catch (err) {
116
+ const code = err && typeof err === 'object' && 'code' in err ? err.code : undefined;
117
+ if (code === 'ENOENT') {
118
+ warnMissingAsset(missingAssetWarningMessage(file, fileFormatFilepath, format));
119
+ continue;
120
+ }
121
+ throw err;
122
+ }
123
+ const fileFormatStream = getFileStream(fileFormatFilepath, strapi, isLocalProvider);
98
124
  const metadata = {
99
125
  ...fileFormat,
100
126
  type: format,
@@ -117,5 +143,5 @@ async function signFile(file) {
117
143
  return Duplex.from(generator());
118
144
  };
119
145
 
120
- export { createAssetsStream };
146
+ export { createAssetsStream, getFileStatsForTransfer, signUploadFileForTransfer };
121
147
  //# sourceMappingURL=assets.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"assets.mjs","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,gBAAAA,CAAiBH,QAAAA,CAAAA;AAC1B,IAAA;AAEA,IAAA,MAAMI,iBAAiB,IAAIC,WAAAA,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,CAAC,gCAAgC,EAAEH,GAAAA,CAAIC,MAAM,CAAA,CAAE,CAAA,CAAA;AACtF,YAAA;AACF,QAAA;QAEA,IAAID,GAAAA,CAAII,IAAI,EAAE;;AAEZC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AAAA,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,MAAAA,CAAOC,IAAI,CAACtB,SAAAA,EAAAA,CAAAA;AACrB;;;;"}
1
+ {"version":3,"file":"assets.mjs","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\nexport function getFileStatsForTransfer(\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\nexport async function signUploadFileForTransfer(strapi: Core.Strapi, 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 (f: IFile) => {\n const signedUrl = await provider.getSignedUrl(f);\n f.url = signedUrl.url;\n };\n\n await signUrl(file);\n if (file.formats) {\n for (const format of Object.keys(file.formats)) {\n await signUrl(file.formats[format]);\n }\n }\n }\n}\n\nconst missingAssetWarningMessage = (file: IFile, filepath: string, format?: string): string => {\n const formatPart = format ? ` (format: ${format})` : '';\n return `[Data transfer] Media item ${file.id} (hash: ${file.hash}) exists in database but no corresponding file was found to transfer${formatPart}. Path: ${filepath}`;\n};\n\n/**\n * Generate and consume assets streams in order to stream each file individually\n */\nexport const createAssetsStream = (\n strapi: Core.Strapi,\n options: { onWarning?: (message: string) => void } = {}\n): Duplex => {\n const warnMissingAsset = (message: string) => {\n strapi.log.warn(message);\n options.onWarning?.(message);\n };\n\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 signUploadFileForTransfer(strapi, file);\n }\n const filepath = isLocalProvider ? join(strapi.dirs.static.public, file.url) : file.url;\n let stats: { size: number };\n try {\n stats = await getFileStatsForTransfer(filepath, strapi, isLocalProvider);\n } catch (err: unknown) {\n const code =\n err && typeof err === 'object' && 'code' in err\n ? (err as NodeJS.ErrnoException).code\n : undefined;\n if (code === 'ENOENT') {\n warnMissingAsset(missingAssetWarningMessage(file, filepath));\n continue;\n }\n throw err;\n }\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 let fileFormatStats: { size: number };\n try {\n fileFormatStats = await getFileStatsForTransfer(\n fileFormatFilepath,\n strapi,\n isLocalProvider\n );\n } catch (err: unknown) {\n const code =\n err && typeof err === 'object' && 'code' in err\n ? (err as NodeJS.ErrnoException).code\n : undefined;\n if (code === 'ENOENT') {\n warnMissingAsset(missingAssetWarningMessage(file, fileFormatFilepath, format));\n continue;\n }\n throw err;\n }\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","getFileStatsForTransfer","stat","Promise","resolve","reject","contentLength","headers","get","stats","size","parseInt","signUploadFileForTransfer","file","provider","plugins","upload","providerName","config","isPrivate","signUrl","f","signedUrl","getSignedUrl","url","formats","format","Object","keys","missingAssetWarningMessage","formatPart","id","hash","createAssetsStream","options","warnMissingAsset","message","log","warn","onWarning","generator","stream","db","queryBuilder","select","isLocalProvider","join","dirs","static","public","err","code","undefined","metadata","filename","ext","fileFormat","fileFormatFilepath","fileFormatStats","fileFormatStream","type","mainHash","Duplex","from"],"mappings":";;;;AAQA,SAASA,cACPC,QAAgB,EAChBC,MAAmB,EACnBC,UAAU,KAAK,EAAA;AAEf,IAAA,IAAIA,OAAAA,EAAS;;AAEX,QAAA,OAAOC,gBAAAA,CAAiBH,QAAAA,CAAAA;AAC1B,IAAA;AAEA,IAAA,MAAMI,iBAAiB,IAAIC,WAAAA,EAAAA;;AAG3BJ,IAAAA,MAAAA,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,CAAC,gCAAgC,EAAEH,GAAAA,CAAIC,MAAM,CAAA,CAAE,CAAA,CAAA;AACtF,YAAA;AACF,QAAA;QAEA,IAAID,GAAAA,CAAII,IAAI,EAAE;;AAEZC,YAAAA,QAAAA,CAASC,OAAO,CAACN,GAAAA,CAAII,IAAI,CAAA,CAA0CG,IAAI,CAACX,cAAAA,CAAAA;QAC1E,CAAA,MAAO;AACLA,YAAAA,cAAAA,CAAeM,IAAI,CAAC,OAAA,EAAS,IAAIC,KAAAA,CAAM,2BAAA,CAAA,CAAA;AACzC,QAAA;IACF,CAAA,CAAA,CACCK,KAAK,CAAC,CAACC,KAAAA,GAAAA;QACNb,cAAAA,CAAeM,IAAI,CAAC,OAAA,EAASO,KAAAA,CAAAA;AAC/B,IAAA,CAAA,CAAA;IAEF,OAAOb,cAAAA;AACT;AAEO,SAASc,uBAAAA,CACdlB,QAAgB,EAChBC,MAAmB,EACnBC,UAAU,KAAK,EAAA;AAEf,IA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AAAA;wBACAtE,QAAAA,EAAU0E,kBAAAA;AACVH,wBAAAA,QAAAA,EAAUE,UAAAA,CAAWxB,IAAI,GAAGwB,UAAAA,CAAWD,GAAG;wBAC1Cd,MAAAA,EAAQkB,gBAAAA;wBACRlD,KAAAA,EAAO;AAAEC,4BAAAA,IAAAA,EAAMgD,gBAAgBhD;AAAK;AACtC,qBAAA;AACF,gBAAA;AACF,YAAA;AACF,QAAA;AACF,IAAA,CAAA;IAEA,OAAOoD,MAAAA,CAAOC,IAAI,CAACvB,SAAAA,EAAAA,CAAAA;AACrB;;;;"}
@@ -0,0 +1,11 @@
1
+ import type { Core } from '@strapi/types';
2
+ import type { StageTotalsEstimate } from '../../../../types';
3
+ /**
4
+ * Sum sizes and counts for the same asset rows `createAssetsStream` would yield (main + formats),
5
+ * skipping missing files with ENOENT like the stream does. Used for transfer progress totals / ETA.
6
+ *
7
+ * - **Local (`provider === 'local'`):** `stat` on disk (source of truth; matches ENOENT skips).
8
+ * - **Remote:** sum `size` from DB when present on main and every format; otherwise sign + `fetch` / `Content-Length` like before.
9
+ */
10
+ export declare function estimateAssetTotals(strapi: Core.Strapi): Promise<StageTotalsEstimate>;
11
+ //# sourceMappingURL=estimate-asset-totals.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"estimate-asset-totals.d.ts","sourceRoot":"","sources":["../../../../src/strapi/providers/local-source/estimate-asset-totals.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAE1C,OAAO,KAAK,EAAU,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AA2BrE;;;;;;GAMG;AACH,wBAAsB,mBAAmB,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CA0H3F"}
@@ -0,0 +1,130 @@
1
+ 'use strict';
2
+
3
+ var path = require('path');
4
+ var assets = require('./assets.js');
5
+
6
+ /** Strapi stores byte size on each file record; use for remote totals to avoid per-URL HTTP. */ function hasReliableDbSize(size) {
7
+ return typeof size === 'number' && Number.isFinite(size) && size >= 0;
8
+ }
9
+ /** When every main + format has a DB size, remote rows need no signing or HTTP stat. */ function remoteRowCanUseDbOnly(file) {
10
+ if (!hasReliableDbSize(file.size)) {
11
+ return false;
12
+ }
13
+ if (!file.formats) {
14
+ return true;
15
+ }
16
+ for (const key of Object.keys(file.formats)){
17
+ if (!hasReliableDbSize(file.formats[key].size)) {
18
+ return false;
19
+ }
20
+ }
21
+ return true;
22
+ }
23
+ /**
24
+ * Sum sizes and counts for the same asset rows `createAssetsStream` would yield (main + formats),
25
+ * skipping missing files with ENOENT like the stream does. Used for transfer progress totals / ETA.
26
+ *
27
+ * - **Local (`provider === 'local'`):** `stat` on disk (source of truth; matches ENOENT skips).
28
+ * - **Remote:** sum `size` from DB when present on main and every format; otherwise sign + `fetch` / `Content-Length` like before.
29
+ */ async function estimateAssetTotals(strapi) {
30
+ let totalBytes = 0;
31
+ let totalCount = 0;
32
+ const stream = strapi.db.queryBuilder('plugin::upload.file').select('*').stream();
33
+ for await (const file of stream){
34
+ const isLocalProvider = file.provider === 'local';
35
+ if (isLocalProvider) {
36
+ const filepath = path.join(strapi.dirs.static.public, file.url);
37
+ try {
38
+ const stats = await assets.getFileStatsForTransfer(filepath, strapi, true);
39
+ totalBytes += stats.size;
40
+ totalCount += 1;
41
+ } catch (err) {
42
+ const code = err && typeof err === 'object' && 'code' in err ? err.code : undefined;
43
+ if (code === 'ENOENT') {
44
+ strapi.log.warn(`[Data transfer] Skipping missing asset file: ${filepath}`);
45
+ continue;
46
+ }
47
+ throw err;
48
+ }
49
+ if (file.formats) {
50
+ for (const format of Object.keys(file.formats)){
51
+ const fileFormat = file.formats[format];
52
+ const fileFormatFilepath = path.join(strapi.dirs.static.public, fileFormat.url);
53
+ try {
54
+ const fileFormatStats = await assets.getFileStatsForTransfer(fileFormatFilepath, strapi, true);
55
+ totalBytes += fileFormatStats.size;
56
+ totalCount += 1;
57
+ } catch (err) {
58
+ const code = err && typeof err === 'object' && 'code' in err ? err.code : undefined;
59
+ if (code === 'ENOENT') {
60
+ strapi.log.warn(`[Data transfer] Skipping missing asset file: ${fileFormatFilepath}`);
61
+ continue;
62
+ }
63
+ throw err;
64
+ }
65
+ }
66
+ }
67
+ continue;
68
+ }
69
+ // Remote: prefer DB sizes (fast); fall back to signed URL + HTTP where `size` is missing.
70
+ if (remoteRowCanUseDbOnly(file)) {
71
+ totalBytes += file.size;
72
+ totalCount += 1;
73
+ if (file.formats) {
74
+ for (const format of Object.keys(file.formats)){
75
+ totalBytes += file.formats[format].size;
76
+ totalCount += 1;
77
+ }
78
+ }
79
+ continue;
80
+ }
81
+ await assets.signUploadFileForTransfer(strapi, file);
82
+ if (hasReliableDbSize(file.size)) {
83
+ totalBytes += file.size;
84
+ totalCount += 1;
85
+ } else {
86
+ try {
87
+ const stats = await assets.getFileStatsForTransfer(file.url, strapi, false);
88
+ totalBytes += stats.size;
89
+ totalCount += 1;
90
+ } catch (err) {
91
+ const code = err && typeof err === 'object' && 'code' in err ? err.code : undefined;
92
+ if (code === 'ENOENT') {
93
+ strapi.log.warn(`[Data transfer] Skipping missing asset file: ${file.url}`);
94
+ continue;
95
+ }
96
+ throw err;
97
+ }
98
+ }
99
+ if (file.formats) {
100
+ for (const format of Object.keys(file.formats)){
101
+ const fileFormat = file.formats[format];
102
+ const fileFormatFilepath = fileFormat.url;
103
+ if (hasReliableDbSize(fileFormat.size)) {
104
+ totalBytes += fileFormat.size;
105
+ totalCount += 1;
106
+ } else {
107
+ try {
108
+ const fileFormatStats = await assets.getFileStatsForTransfer(fileFormatFilepath, strapi, false);
109
+ totalBytes += fileFormatStats.size;
110
+ totalCount += 1;
111
+ } catch (err) {
112
+ const code = err && typeof err === 'object' && 'code' in err ? err.code : undefined;
113
+ if (code === 'ENOENT') {
114
+ strapi.log.warn(`[Data transfer] Skipping missing asset file: ${fileFormatFilepath}`);
115
+ continue;
116
+ }
117
+ throw err;
118
+ }
119
+ }
120
+ }
121
+ }
122
+ }
123
+ return {
124
+ totalBytes,
125
+ totalCount
126
+ };
127
+ }
128
+
129
+ exports.estimateAssetTotals = estimateAssetTotals;
130
+ //# sourceMappingURL=estimate-asset-totals.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"estimate-asset-totals.js","sources":["../../../../src/strapi/providers/local-source/estimate-asset-totals.ts"],"sourcesContent":["import { join } from 'path';\nimport type { Readable } from 'stream';\nimport type { Core } from '@strapi/types';\n\nimport type { IAsset, StageTotalsEstimate } from '../../../../types';\n\nimport { getFileStatsForTransfer, signUploadFileForTransfer } from './assets';\n\ntype UploadFileRecord = IAsset['metadata'];\n\n/** Strapi stores byte size on each file record; use for remote totals to avoid per-URL HTTP. */\nfunction hasReliableDbSize(size: unknown): size is number {\n return typeof size === 'number' && Number.isFinite(size) && size >= 0;\n}\n\n/** When every main + format has a DB size, remote rows need no signing or HTTP stat. */\nfunction remoteRowCanUseDbOnly(file: UploadFileRecord): boolean {\n if (!hasReliableDbSize(file.size)) {\n return false;\n }\n if (!file.formats) {\n return true;\n }\n for (const key of Object.keys(file.formats)) {\n if (!hasReliableDbSize(file.formats[key].size)) {\n return false;\n }\n }\n return true;\n}\n\n/**\n * Sum sizes and counts for the same asset rows `createAssetsStream` would yield (main + formats),\n * skipping missing files with ENOENT like the stream does. Used for transfer progress totals / ETA.\n *\n * - **Local (`provider === 'local'`):** `stat` on disk (source of truth; matches ENOENT skips).\n * - **Remote:** sum `size` from DB when present on main and every format; otherwise sign + `fetch` / `Content-Length` like before.\n */\nexport async function estimateAssetTotals(strapi: Core.Strapi): Promise<StageTotalsEstimate> {\n let totalBytes = 0;\n let totalCount = 0;\n\n const stream: Readable = strapi.db.queryBuilder('plugin::upload.file').select('*').stream();\n\n for await (const file of stream) {\n const isLocalProvider = file.provider === 'local';\n\n if (isLocalProvider) {\n const filepath = join(strapi.dirs.static.public, file.url);\n try {\n const stats = await getFileStatsForTransfer(filepath, strapi, true);\n totalBytes += stats.size;\n totalCount += 1;\n } catch (err: unknown) {\n const code =\n err && typeof err === 'object' && 'code' in err\n ? (err as NodeJS.ErrnoException).code\n : undefined;\n if (code === 'ENOENT') {\n strapi.log.warn(`[Data transfer] Skipping missing asset file: ${filepath}`);\n continue;\n }\n throw err;\n }\n\n if (file.formats) {\n for (const format of Object.keys(file.formats)) {\n const fileFormat = file.formats[format];\n const fileFormatFilepath = join(strapi.dirs.static.public, fileFormat.url);\n try {\n const fileFormatStats = await getFileStatsForTransfer(fileFormatFilepath, strapi, true);\n totalBytes += fileFormatStats.size;\n totalCount += 1;\n } catch (err: unknown) {\n const code =\n err && typeof err === 'object' && 'code' in err\n ? (err as NodeJS.ErrnoException).code\n : undefined;\n if (code === 'ENOENT') {\n strapi.log.warn(`[Data transfer] Skipping missing asset file: ${fileFormatFilepath}`);\n continue;\n }\n throw err;\n }\n }\n }\n\n continue;\n }\n\n // Remote: prefer DB sizes (fast); fall back to signed URL + HTTP where `size` is missing.\n if (remoteRowCanUseDbOnly(file)) {\n totalBytes += file.size;\n totalCount += 1;\n if (file.formats) {\n for (const format of Object.keys(file.formats)) {\n totalBytes += file.formats[format].size;\n totalCount += 1;\n }\n }\n continue;\n }\n\n await signUploadFileForTransfer(strapi, file);\n\n if (hasReliableDbSize(file.size)) {\n totalBytes += file.size;\n totalCount += 1;\n } else {\n try {\n const stats = await getFileStatsForTransfer(file.url, strapi, false);\n totalBytes += stats.size;\n totalCount += 1;\n } catch (err: unknown) {\n const code =\n err && typeof err === 'object' && 'code' in err\n ? (err as NodeJS.ErrnoException).code\n : undefined;\n if (code === 'ENOENT') {\n strapi.log.warn(`[Data transfer] Skipping missing asset file: ${file.url}`);\n continue;\n }\n throw err;\n }\n }\n\n if (file.formats) {\n for (const format of Object.keys(file.formats)) {\n const fileFormat = file.formats[format];\n const fileFormatFilepath = fileFormat.url;\n\n if (hasReliableDbSize(fileFormat.size)) {\n totalBytes += fileFormat.size;\n totalCount += 1;\n } else {\n try {\n const fileFormatStats = await getFileStatsForTransfer(\n fileFormatFilepath,\n strapi,\n false\n );\n totalBytes += fileFormatStats.size;\n totalCount += 1;\n } catch (err: unknown) {\n const code =\n err && typeof err === 'object' && 'code' in err\n ? (err as NodeJS.ErrnoException).code\n : undefined;\n if (code === 'ENOENT') {\n strapi.log.warn(`[Data transfer] Skipping missing asset file: ${fileFormatFilepath}`);\n continue;\n }\n throw err;\n }\n }\n }\n }\n }\n\n return { totalBytes, totalCount };\n}\n"],"names":["hasReliableDbSize","size","Number","isFinite","remoteRowCanUseDbOnly","file","formats","key","Object","keys","estimateAssetTotals","strapi","totalBytes","totalCount","stream","db","queryBuilder","select","isLocalProvider","provider","filepath","join","dirs","static","public","url","stats","getFileStatsForTransfer","err","code","undefined","log","warn","format","fileFormat","fileFormatFilepath","fileFormatStats","signUploadFileForTransfer"],"mappings":";;;;;AAUA,iGACA,SAASA,iBAAAA,CAAkBC,IAAa,EAAA;AACtC,IAAA,OAAO,OAAOA,IAAAA,KAAS,QAAA,IAAYC,OAAOC,QAAQ,CAACF,SAASA,IAAAA,IAAQ,CAAA;AACtE;AAEA,yFACA,SAASG,qBAAAA,CAAsBC,IAAsB,EAAA;AACnD,IAAA,IAAI,CAACL,iBAAAA,CAAkBK,IAAAA,CAAKJ,IAAI,CAAA,EAAG;QACjC,OAAO,KAAA;AACT,IAAA;IACA,IAAI,CAACI,IAAAA,CAAKC,OAAO,EAAE;QACjB,OAAO,IAAA;AACT,IAAA;AACA,IAAA,KAAK,MAAMC,GAAAA,IAAOC,MAAAA,CAAOC,IAAI,CAACJ,IAAAA,CAAKC,OAAO,CAAA,CAAG;QAC3C,IAAI,CAACN,kBAAkBK,IAAAA,CAAKC,OAAO,CAACC,GAAAA,CAAI,CAACN,IAAI,CAAA,EAAG;YAC9C,OAAO,KAAA;AACT,QAAA;AACF,IAAA;IACA,OAAO,IAAA;AACT;AAEA;;;;;;IAOO,eAAeS,mBAAAA,CAAoBC,MAAmB,EAAA;AAC3D,IAAA,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AA,CAC5BQ,kBAAAA,EACAxB,MAAAA,EACA,KAAA,CAAA;AAEFC,wBAAAA,UAAAA,IAAcwB,gBAAgBnC,IAAI;wBAClCY,UAAAA,IAAc,CAAA;AAChB,oBAAA,CAAA,CAAE,OAAOe,GAAAA,EAAc;wBACrB,MAAMC,IAAAA,GACJD,GAAAA,IAAO,OAAOA,GAAAA,KAAQ,QAAA,IAAY,UAAUA,GAAAA,GACvCA,GAAAA,CAA8BC,IAAI,GACnCC,SAAAA;AACN,wBAAA,IAAID,SAAS,QAAA,EAAU;AACrBlB,4BAAAA,MAAAA,CAAOoB,GAAG,CAACC,IAAI,CAAC,CAAC,6CAA6C,EAAEG,kBAAAA,CAAAA,CAAoB,CAAA;AACpF,4BAAA;AACF,wBAAA;wBACA,MAAMP,GAAAA;AACR,oBAAA;AACF,gBAAA;AACF,YAAA;AACF,QAAA;AACF,IAAA;IAEA,OAAO;AAAEhB,QAAAA,UAAAA;AAAYC,QAAAA;AAAW,KAAA;AAClC;;;;"}
@@ -0,0 +1,128 @@
1
+ import { join } from 'path';
2
+ import { getFileStatsForTransfer, signUploadFileForTransfer } from './assets.mjs';
3
+
4
+ /** Strapi stores byte size on each file record; use for remote totals to avoid per-URL HTTP. */ function hasReliableDbSize(size) {
5
+ return typeof size === 'number' && Number.isFinite(size) && size >= 0;
6
+ }
7
+ /** When every main + format has a DB size, remote rows need no signing or HTTP stat. */ function remoteRowCanUseDbOnly(file) {
8
+ if (!hasReliableDbSize(file.size)) {
9
+ return false;
10
+ }
11
+ if (!file.formats) {
12
+ return true;
13
+ }
14
+ for (const key of Object.keys(file.formats)){
15
+ if (!hasReliableDbSize(file.formats[key].size)) {
16
+ return false;
17
+ }
18
+ }
19
+ return true;
20
+ }
21
+ /**
22
+ * Sum sizes and counts for the same asset rows `createAssetsStream` would yield (main + formats),
23
+ * skipping missing files with ENOENT like the stream does. Used for transfer progress totals / ETA.
24
+ *
25
+ * - **Local (`provider === 'local'`):** `stat` on disk (source of truth; matches ENOENT skips).
26
+ * - **Remote:** sum `size` from DB when present on main and every format; otherwise sign + `fetch` / `Content-Length` like before.
27
+ */ async function estimateAssetTotals(strapi) {
28
+ let totalBytes = 0;
29
+ let totalCount = 0;
30
+ const stream = strapi.db.queryBuilder('plugin::upload.file').select('*').stream();
31
+ for await (const file of stream){
32
+ const isLocalProvider = file.provider === 'local';
33
+ if (isLocalProvider) {
34
+ const filepath = join(strapi.dirs.static.public, file.url);
35
+ try {
36
+ const stats = await getFileStatsForTransfer(filepath, strapi, true);
37
+ totalBytes += stats.size;
38
+ totalCount += 1;
39
+ } catch (err) {
40
+ const code = err && typeof err === 'object' && 'code' in err ? err.code : undefined;
41
+ if (code === 'ENOENT') {
42
+ strapi.log.warn(`[Data transfer] Skipping missing asset file: ${filepath}`);
43
+ continue;
44
+ }
45
+ throw err;
46
+ }
47
+ if (file.formats) {
48
+ for (const format of Object.keys(file.formats)){
49
+ const fileFormat = file.formats[format];
50
+ const fileFormatFilepath = join(strapi.dirs.static.public, fileFormat.url);
51
+ try {
52
+ const fileFormatStats = await getFileStatsForTransfer(fileFormatFilepath, strapi, true);
53
+ totalBytes += fileFormatStats.size;
54
+ totalCount += 1;
55
+ } catch (err) {
56
+ const code = err && typeof err === 'object' && 'code' in err ? err.code : undefined;
57
+ if (code === 'ENOENT') {
58
+ strapi.log.warn(`[Data transfer] Skipping missing asset file: ${fileFormatFilepath}`);
59
+ continue;
60
+ }
61
+ throw err;
62
+ }
63
+ }
64
+ }
65
+ continue;
66
+ }
67
+ // Remote: prefer DB sizes (fast); fall back to signed URL + HTTP where `size` is missing.
68
+ if (remoteRowCanUseDbOnly(file)) {
69
+ totalBytes += file.size;
70
+ totalCount += 1;
71
+ if (file.formats) {
72
+ for (const format of Object.keys(file.formats)){
73
+ totalBytes += file.formats[format].size;
74
+ totalCount += 1;
75
+ }
76
+ }
77
+ continue;
78
+ }
79
+ await signUploadFileForTransfer(strapi, file);
80
+ if (hasReliableDbSize(file.size)) {
81
+ totalBytes += file.size;
82
+ totalCount += 1;
83
+ } else {
84
+ try {
85
+ const stats = await getFileStatsForTransfer(file.url, strapi, false);
86
+ totalBytes += stats.size;
87
+ totalCount += 1;
88
+ } catch (err) {
89
+ const code = err && typeof err === 'object' && 'code' in err ? err.code : undefined;
90
+ if (code === 'ENOENT') {
91
+ strapi.log.warn(`[Data transfer] Skipping missing asset file: ${file.url}`);
92
+ continue;
93
+ }
94
+ throw err;
95
+ }
96
+ }
97
+ if (file.formats) {
98
+ for (const format of Object.keys(file.formats)){
99
+ const fileFormat = file.formats[format];
100
+ const fileFormatFilepath = fileFormat.url;
101
+ if (hasReliableDbSize(fileFormat.size)) {
102
+ totalBytes += fileFormat.size;
103
+ totalCount += 1;
104
+ } else {
105
+ try {
106
+ const fileFormatStats = await getFileStatsForTransfer(fileFormatFilepath, strapi, false);
107
+ totalBytes += fileFormatStats.size;
108
+ totalCount += 1;
109
+ } catch (err) {
110
+ const code = err && typeof err === 'object' && 'code' in err ? err.code : undefined;
111
+ if (code === 'ENOENT') {
112
+ strapi.log.warn(`[Data transfer] Skipping missing asset file: ${fileFormatFilepath}`);
113
+ continue;
114
+ }
115
+ throw err;
116
+ }
117
+ }
118
+ }
119
+ }
120
+ }
121
+ return {
122
+ totalBytes,
123
+ totalCount
124
+ };
125
+ }
126
+
127
+ export { estimateAssetTotals };
128
+ //# sourceMappingURL=estimate-asset-totals.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"estimate-asset-totals.mjs","sources":["../../../../src/strapi/providers/local-source/estimate-asset-totals.ts"],"sourcesContent":["import { join } from 'path';\nimport type { Readable } from 'stream';\nimport type { Core } from '@strapi/types';\n\nimport type { IAsset, StageTotalsEstimate } from '../../../../types';\n\nimport { getFileStatsForTransfer, signUploadFileForTransfer } from './assets';\n\ntype UploadFileRecord = IAsset['metadata'];\n\n/** Strapi stores byte size on each file record; use for remote totals to avoid per-URL HTTP. */\nfunction hasReliableDbSize(size: unknown): size is number {\n return typeof size === 'number' && Number.isFinite(size) && size >= 0;\n}\n\n/** When every main + format has a DB size, remote rows need no signing or HTTP stat. */\nfunction remoteRowCanUseDbOnly(file: UploadFileRecord): boolean {\n if (!hasReliableDbSize(file.size)) {\n return false;\n }\n if (!file.formats) {\n return true;\n }\n for (const key of Object.keys(file.formats)) {\n if (!hasReliableDbSize(file.formats[key].size)) {\n return false;\n }\n }\n return true;\n}\n\n/**\n * Sum sizes and counts for the same asset rows `createAssetsStream` would yield (main + formats),\n * skipping missing files with ENOENT like the stream does. Used for transfer progress totals / ETA.\n *\n * - **Local (`provider === 'local'`):** `stat` on disk (source of truth; matches ENOENT skips).\n * - **Remote:** sum `size` from DB when present on main and every format; otherwise sign + `fetch` / `Content-Length` like before.\n */\nexport async function estimateAssetTotals(strapi: Core.Strapi): Promise<StageTotalsEstimate> {\n let totalBytes = 0;\n let totalCount = 0;\n\n const stream: Readable = strapi.db.queryBuilder('plugin::upload.file').select('*').stream();\n\n for await (const file of stream) {\n const isLocalProvider = file.provider === 'local';\n\n if (isLocalProvider) {\n const filepath = join(strapi.dirs.static.public, file.url);\n try {\n const stats = await getFileStatsForTransfer(filepath, strapi, true);\n totalBytes += stats.size;\n totalCount += 1;\n } catch (err: unknown) {\n const code =\n err && typeof err === 'object' && 'code' in err\n ? (err as NodeJS.ErrnoException).code\n : undefined;\n if (code === 'ENOENT') {\n strapi.log.warn(`[Data transfer] Skipping missing asset file: ${filepath}`);\n continue;\n }\n throw err;\n }\n\n if (file.formats) {\n for (const format of Object.keys(file.formats)) {\n const fileFormat = file.formats[format];\n const fileFormatFilepath = join(strapi.dirs.static.public, fileFormat.url);\n try {\n const fileFormatStats = await getFileStatsForTransfer(fileFormatFilepath, strapi, true);\n totalBytes += fileFormatStats.size;\n totalCount += 1;\n } catch (err: unknown) {\n const code =\n err && typeof err === 'object' && 'code' in err\n ? (err as NodeJS.ErrnoException).code\n : undefined;\n if (code === 'ENOENT') {\n strapi.log.warn(`[Data transfer] Skipping missing asset file: ${fileFormatFilepath}`);\n continue;\n }\n throw err;\n }\n }\n }\n\n continue;\n }\n\n // Remote: prefer DB sizes (fast); fall back to signed URL + HTTP where `size` is missing.\n if (remoteRowCanUseDbOnly(file)) {\n totalBytes += file.size;\n totalCount += 1;\n if (file.formats) {\n for (const format of Object.keys(file.formats)) {\n totalBytes += file.formats[format].size;\n totalCount += 1;\n }\n }\n continue;\n }\n\n await signUploadFileForTransfer(strapi, file);\n\n if (hasReliableDbSize(file.size)) {\n totalBytes += file.size;\n totalCount += 1;\n } else {\n try {\n const stats = await getFileStatsForTransfer(file.url, strapi, false);\n totalBytes += stats.size;\n totalCount += 1;\n } catch (err: unknown) {\n const code =\n err && typeof err === 'object' && 'code' in err\n ? (err as NodeJS.ErrnoException).code\n : undefined;\n if (code === 'ENOENT') {\n strapi.log.warn(`[Data transfer] Skipping missing asset file: ${file.url}`);\n continue;\n }\n throw err;\n }\n }\n\n if (file.formats) {\n for (const format of Object.keys(file.formats)) {\n const fileFormat = file.formats[format];\n const fileFormatFilepath = fileFormat.url;\n\n if (hasReliableDbSize(fileFormat.size)) {\n totalBytes += fileFormat.size;\n totalCount += 1;\n } else {\n try {\n const fileFormatStats = await getFileStatsForTransfer(\n fileFormatFilepath,\n strapi,\n false\n );\n totalBytes += fileFormatStats.size;\n totalCount += 1;\n } catch (err: unknown) {\n const code =\n err && typeof err === 'object' && 'code' in err\n ? (err as NodeJS.ErrnoException).code\n : undefined;\n if (code === 'ENOENT') {\n strapi.log.warn(`[Data transfer] Skipping missing asset file: ${fileFormatFilepath}`);\n continue;\n }\n throw err;\n }\n }\n }\n }\n }\n\n return { totalBytes, totalCount };\n}\n"],"names":["hasReliableDbSize","size","Number","isFinite","remoteRowCanUseDbOnly","file","formats","key","Object","keys","estimateAssetTotals","strapi","totalBytes","totalCount","stream","db","queryBuilder","select","isLocalProvider","provider","filepath","join","dirs","static","public","url","stats","getFileStatsForTransfer","err","code","undefined","log","warn","format","fileFormat","fileFormatFilepath","fileFormatStats","signUploadFileFor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A;AACF,YAAA;AACF,QAAA;AACF,IAAA;IAEA,OAAO;AAAEhB,QAAAA,UAAAA;AAAYC,QAAAA;AAAW,KAAA;AAClC;;;;"}
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import { Readable } from 'stream';
3
3
  import type { Core, Struct } from '@strapi/types';
4
- import type { IMetadata, ISourceProvider, ProviderType } from '../../../../types';
4
+ import type { IMetadata, ISourceProvider, ProviderType, TransferStage } from '../../../../types';
5
5
  import type { IDiagnosticReporter } from '../../../utils/diagnostic';
6
6
  export interface ILocalStrapiSourceProviderOptions {
7
7
  getStrapi(): Core.Strapi | Promise<Core.Strapi>;
@@ -24,7 +24,8 @@ declare class LocalStrapiSourceProvider implements ISourceProvider {
24
24
  getSchemas(): Record<string, Struct.Schema>;
25
25
  createSchemasReadStream(): Readable;
26
26
  createAssetsReadStream(): Readable;
27
+ getStageTotals(stage: TransferStage): Promise<import("../../../../types").StageTotalsEstimate | null>;
27
28
  }
28
29
  export type ILocalStrapiSourceProvider = InstanceType<typeof LocalStrapiSourceProvider>;
29
- export {};
30
+ export { estimateAssetTotals } from './estimate-asset-totals';
30
31
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/strapi/providers/local-source/index.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAElD,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAClF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAQrE,MAAM,WAAW,iCAAiC;IAChD,SAAS,IAAI,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAEhD,WAAW,CAAC,EAAE,OAAO,C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,+BAA+B,YAAa,iCAAiC,8BAEzF,CAAC;AAEF,cAAM,yBAA0B,YAAW,eAAe;;IACxD,IAAI,SAA0B;IAE9B,IAAI,EAAE,YAAY,CAAY;IAE9B,OAAO,EAAE,iCAAiC,CAAC;IAE3C,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC;gBAIT,OAAO,EAAE,iCAAiC;IAIhD,SAAS,CAAC,WAAW,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IA4D3D,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAU5B,WAAW,IAAI,SAAS;IAclB,wBAAwB,IAAI,OAAO,CAAC,QAAQ,CAAC;IAYnD,qBAAqB,IAAI,QAAQ;IAOjC,6BAA6B,IAAI,QAAQ;IAMzC,UAAU,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC;IAW3C,uBAAuB,IAAI,QAAQ;IAInC,sBAAsB,IAAI,QAAQ;IAc5B,cAAc,CAAC,KAAK,EAAE,aAAa;CAO1C;AAED,MAAM,MAAM,0BAA0B,GAAG,YAAY,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAExF,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC"}
@@ -6,7 +6,10 @@ var entities = require('./entities.js');
6
6
  var links = require('./links.js');
7
7
  var configuration = require('./configuration.js');
8
8
  var assets = require('./assets.js');
9
+ var estimateAssetTotals = require('./estimate-asset-totals.js');
9
10
  require('crypto');
11
+ require('node:events');
12
+ require('node:stream/promises');
10
13
  require('lodash/fp');
11
14
  var schema = require('../../../utils/schema.js');
12
15
  require('events');
@@ -25,7 +28,7 @@ function _class_private_field_loose_key(name) {
25
28
  const createLocalStrapiSourceProvider = (options)=>{
26
29
  return new LocalStrapiSourceProvider(options);
27
30
  };
28
- var _diagnostics = /*#__PURE__*/ _class_private_field_loose_key("_diagnostics"), _reportInfo = /*#__PURE__*/ _class_private_field_loose_key("_reportInfo"), /**
31
+ var _diagnostics = /*#__PURE__*/ _class_private_field_loose_key("_diagnostics"), _reportInfo = /*#__PURE__*/ _class_private_field_loose_key("_reportInfo"), _reportWarning = /*#__PURE__*/ _class_private_field_loose_key("_reportWarning"), /**
29
32
  * Reports an error to the diagnostic reporter.
30
33
  */ _reportError = /*#__PURE__*/ _class_private_field_loose_key("_reportError"), /**
31
34
  * Handles errors that occur in read streams.
@@ -47,7 +50,8 @@ class LocalStrapiSourceProvider {
47
50
  }
48
51
  getMetadata() {
49
52
  _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('getting metadata');
50
- const strapiVersion = strapi.config.get('info.strapi');
53
+ providers.assertValidStrapi(this.strapi);
54
+ const strapiVersion = this.strapi.config.get('info.strapi');
51
55
  const createdAt = new Date().toISOString();
52
56
  return {
53
57
  createdAt,
@@ -91,16 +95,28 @@ class LocalStrapiSourceProvider {
91
95
  createAssetsReadStream() {
92
96
  providers.assertValidStrapi(this.strapi, 'Not able to stream assets');
93
97
  _class_private_field_loose_base(this, _reportInfo)[_reportInfo]('creating assets read stream');
94
- const stream = assets.createAssetsStream(this.strapi);
98
+ const stream = assets.createAssetsStream(this.strapi, {
99
+ onWarning: (message)=>_class_private_field_loose_base(this, _reportWarning)[_reportWarning](message)
100
+ });
95
101
  stream.on('error', (err)=>{
96
102
  _class_private_field_loose_base(this, _handleStreamError)[_handleStreamError]('assets', err);
97
103
  });
98
104
  return stream;
99
105
  }
106
+ async getStageTotals(stage) {
107
+ if (stage !== 'assets') {
108
+ return null;
109
+ }
110
+ providers.assertValidStrapi(this.strapi, 'Not able to estimate asset totals');
111
+ return estimateAssetTotals.estimateAssetTotals(this.strapi);
112
+ }
100
113
  constructor(options){
101
114
  Object.defineProperty(this, _reportInfo, {
102
115
  value: reportInfo
103
116
  });
117
+ Object.defineProperty(this, _reportWarning, {
118
+ value: reportWarning
119
+ });
104
120
  Object.defineProperty(this, _reportError, {
105
121
  value: reportError
106
122
  });
@@ -126,6 +142,16 @@ function reportInfo(message) {
126
142
  kind: 'info'
127
143
  });
128
144
  }
145
+ function reportWarning(message) {
146
+ _class_private_field_loose_base(this, _diagnostics)[_diagnostics]?.report({
147
+ details: {
148
+ createdAt: new Date(),
149
+ message,
150
+ origin: 'local-source-provider'
151
+ },
152
+ kind: 'warning'
153
+ });
154
+ }
129
155
  function reportError(message, error) {
130
156
  _class_private_field_loose_base(this, _diagnostics)[_diagnostics]?.report({
131
157
  details: {
@@ -150,5 +176,6 @@ function handleStreamError(streamType, err) {
150
176
  _class_private_field_loose_base(this, _reportError)[_reportError](formattedError.message, err);
151
177
  }
152
178
 
179
+ exports.estimateAssetTotals = estimateAssetTotals.estimateAssetTotals;
153
180
  exports.createLocalStrapiSourceProvider = createLocalStrapiSourceProvider;
154
181
  //# sourceMappingURL=index.js.map