@blocklet/pages-kit-block-studio 0.6.15 → 0.6.16

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.
@@ -159,6 +159,40 @@ initBlockStudioRouter.post('/', async (req, res) => {
159
159
  });
160
160
  }
161
161
  }
162
+ // check if the properties has mediaKitUrl
163
+ if (isMetadataFile(filePath) && content.properties) {
164
+ const downloadPromises = [];
165
+ Object.keys(content.properties).forEach((key) => {
166
+ const property = content.properties[key].data;
167
+ if (property.type === 'url') {
168
+ Object.keys(property.locales).forEach((locale) => {
169
+ if (property.locales[locale].defaultValue?.mediaKitUrl?.startsWith('mediakit://')) {
170
+ const downloadPromise = (async () => {
171
+ try {
172
+ const fileName = path.basename(property.locales[locale].defaultValue.mediaKitUrl);
173
+ const targetPath = path.join(dir, getPreviewImageRelativePath(fileName));
174
+ if (fs.existsSync(targetPath)) {
175
+ return;
176
+ }
177
+ await downloadAsset({
178
+ asset: fileName,
179
+ savePath: targetPath,
180
+ componentDid: process.env.BLOCKLET_COMPONENT_DID || '',
181
+ });
182
+ }
183
+ catch (error) {
184
+ console.error('Download media kit file failed:', error.message);
185
+ }
186
+ })();
187
+ downloadPromises.push(downloadPromise);
188
+ }
189
+ });
190
+ }
191
+ });
192
+ if (downloadPromises.length > 0) {
193
+ await Promise.allSettled(downloadPromises);
194
+ }
195
+ }
162
196
  fs.writeFileSync(filePath, JSON.stringify(mergedContent, null, 2));
163
197
  return res.json({ success: true, content: mergedContent, message: 'Updated' });
164
198
  }