Skip to content

Commit 822dac2

Browse files
committed
Change function order 🎨
1 parent 8d50ac0 commit 822dac2

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

‎server/script/migrateAssetsLocation.js‎

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -172,27 +172,10 @@ function migrateContentElementData(element, schemaFileMeta) {
172172
return data;
173173
}
174174

175-
async function migrateFileMeta(repositoryId, metaInputs, metaConfigs) {
176-
const repositoryAssetsPath = storage.getPath(repositoryId);
177-
const newMeta = await Promise.reduce(metaConfigs, async (acc, metaKey) => {
178-
const meta = metaInputs[metaKey];
179-
if (!meta) return acc;
180-
const url = get(meta, 'url');
181-
if (!url) return acc;
182-
const { key, newKey } = resolveNewURL(url, repositoryAssetsPath) || {};
183-
if (!key || !newKey) return acc;
184-
await storage.copyFile(key, newKey);
185-
return {
186-
...acc,
187-
[metaKey]: {
188-
...meta,
189-
key: newKey,
190-
url: `${protocol}${newKey}`,
191-
publicUrl: await storage.getFileUrl(newKey)
192-
}
193-
};
194-
}, {});
195-
return { ...metaInputs, ...newMeta };
175+
async function migrateContentElementMeta(element, { elementTypeMetaMap }) {
176+
const { repositoryId, type } = element;
177+
const metaConfigs = get(elementTypeMetaMap, type, []);
178+
return migrateFileMeta(repositoryId, element.meta, metaConfigs);
196179
}
197180

198181
async function migrateRevisionsChunk({ page, options, schemaFileMeta, transaction }) {
@@ -217,12 +200,6 @@ async function migrateRevision(revision, schemaFileMeta) {
217200
return { state: { ...state, ...payload } };
218201
}
219202

220-
async function migrateContentElementMeta(element, { elementTypeMetaMap }) {
221-
const { repositoryId, type } = element;
222-
const metaConfigs = get(elementTypeMetaMap, type, []);
223-
return migrateFileMeta(repositoryId, element.meta, metaConfigs);
224-
}
225-
226203
async function imageMigrationHandler(element) {
227204
const { repositoryId, data } = element;
228205
const repositoryAssetsPath = storage.getPath(repositoryId);
@@ -267,6 +244,29 @@ async function defaultMigrationHandler(element) {
267244
};
268245
}
269246

247+
async function migrateFileMeta(repositoryId, metaInputs, metaConfigs) {
248+
const repositoryAssetsPath = storage.getPath(repositoryId);
249+
const newMeta = await Promise.reduce(metaConfigs, async (acc, metaKey) => {
250+
const meta = metaInputs[metaKey];
251+
if (!meta) return acc;
252+
const url = get(meta, 'url');
253+
if (!url) return acc;
254+
const { key, newKey } = resolveNewURL(url, repositoryAssetsPath) || {};
255+
if (!key || !newKey) return acc;
256+
await storage.copyFile(key, newKey);
257+
return {
258+
...acc,
259+
[metaKey]: {
260+
...meta,
261+
key: newKey,
262+
url: `${protocol}${newKey}`,
263+
publicUrl: await storage.getFileUrl(newKey)
264+
}
265+
};
266+
}, {});
267+
return { ...metaInputs, ...newMeta };
268+
}
269+
270270
function resolveNewURL(assetUrl, targetDir) {
271271
if (assetUrl.startsWith(protocol)) assetUrl = assetUrl.substr(protocol.length);
272272
const result = assetUrl.match(regex);

0 commit comments

Comments
 (0)