diff --git a/src/prisma/prismaservice/src/dobbelOmega/migrateImages.ts b/src/prisma/prismaservice/src/dobbelOmega/migrateImages.ts index af5551de..6fcb7212 100644 --- a/src/prisma/prismaservice/src/dobbelOmega/migrateImages.ts +++ b/src/prisma/prismaservice/src/dobbelOmega/migrateImages.ts @@ -160,9 +160,9 @@ export default async function migrateImages( return migrateImageIdMap } -type Locations = { - fsLocationOriginal: string, - fsLocationSmallSize: string, +type Locations = { + fsLocationOriginal: string, + fsLocationSmallSize: string, fsLocationMediumSize: string, fsLocationLargeSize: string } @@ -183,35 +183,39 @@ async function fetchAllImagesAndUploadToStore { + manifest.info(`Migrating image number ${imageCounter++} of ${images.length}`) + const ext = image.originalName.split('.').pop() || '' + const fsLocationDefaultOldVev = `${process.env.VEVEN_STORE_URL}/image/default/${image.name}` + + `?url=/store/images/${image.name}.${ext}` + const fsLocationMediumOldVev = `${process.env.VEVEN_STORE_URL}/image/resize/${imageSizes.medium}/` + + `${imageSizes.medium}/${image.name}?url=/store/images/${image.name}.${ext}` + const fsLocationSmallOldVev = `${process.env.VEVEN_STORE_URL}/image/resize/${imageSizes.small}/` + + `${imageSizes.small}/${image.name}?url=/store/images/${image.name}.${ext}` + const fsLocationLargeOldVev = `${process.env.VEVEN_STORE_URL}/image/resize/${imageSizes.large}/` + + `${imageSizes.large}/${image.name}?url=/store/images/${image.name}.${ext}` + const fsLocationOriginal = await fetchImageAndUploadToStore(fsLocationDefaultOldVev) + const fsLocationMediumSize = await fetchImageAndUploadToStore(fsLocationMediumOldVev) + const fsLocationSmallSize = await fetchImageAndUploadToStore(fsLocationSmallOldVev) + const fsLocationLargeSize = await fetchImageAndUploadToStore(fsLocationLargeOldVev) + if (!fsLocationOriginal || !fsLocationMediumSize || !fsLocationSmallSize || !fsLocationLargeSize) { + console.error(`Failed to fetch image from ${fsLocationDefaultOldVev}`) + ret.push(null) + } else { + ret.push({ + ...image, + fsLocationSmallSize, + fsLocationMediumSize, + fsLocationOriginal, + fsLocationLargeSize + }) + } + } + + for (const imageBatch of imageBatches) { - await Promise.all(imageBatch.map(async image => { - manifest.info(`Migrating image number ${imageCounter++} of ${images.length}`) - const ext = image.originalName.split('.').pop() || '' - const fsLocationDefaultOldVev = `${process.env.VEVEN_STORE_URL}/image/default/${image.name}` - + `?url=/store/images/${image.name}.${ext}` - const fsLocationMediumOldVev = `${process.env.VEVEN_STORE_URL}/image/resize/${imageSizes.medium}/` - + `${imageSizes.medium}/${image.name}?url=/store/images/${image.name}.${ext}` - const fsLocationSmallOldVev = `${process.env.VEVEN_STORE_URL}/image/resize/${imageSizes.small}/` - + `${imageSizes.small}/${image.name}?url=/store/images/${image.name}.${ext}` - const fsLocationLargeOldVev = `${process.env.VEVEN_STORE_URL}/image/resize/${imageSizes.large}/` - + `${imageSizes.large}/${image.name}?url=/store/images/${image.name}.${ext}` - const fsLocationOriginal = await fetchImageAndUploadToStore(fsLocationDefaultOldVev) - const fsLocationMediumSize = await fetchImageAndUploadToStore(fsLocationMediumOldVev) - const fsLocationSmallSize = await fetchImageAndUploadToStore(fsLocationSmallOldVev) - const fsLocationLargeSize = await fetchImageAndUploadToStore(fsLocationLargeOldVev) - if (!fsLocationOriginal || !fsLocationMediumSize || !fsLocationSmallSize || !fsLocationLargeSize) { - console.error(`Failed to fetch image from ${fsLocationDefaultOldVev}`) - ret.push(null) - } else { - ret.push({ - ...image, - fsLocationSmallSize, - fsLocationMediumSize, - fsLocationOriginal, - fsLocationLargeSize - }) - } - })) + await Promise.all(imageBatch.map(uploadOne)) } return ret } diff --git a/src/prisma/prismaservice/src/dobbelOmega/migrateUsers.ts b/src/prisma/prismaservice/src/dobbelOmega/migrateUsers.ts index 8b0e17d7..94b3be46 100644 --- a/src/prisma/prismaservice/src/dobbelOmega/migrateUsers.ts +++ b/src/prisma/prismaservice/src/dobbelOmega/migrateUsers.ts @@ -1,9 +1,9 @@ -import type { PrismaClient as PrismaClientPn, SEX } from '@/generated/pn' -import type { PrismaClient as PrismaClientVeven, enum_Users_sex as SEXVEVEN } from '@/generated/veven' -import type { Limits } from './migrationLimits' import upsertOrderBasedOnDate from './upsertOrderBasedOnDate' import { type IdMapper, vevenIdToPnId } from './IdMapper' import manifest from '@/src/logger' +import type { PrismaClient as PrismaClientPn, SEX } from '@/generated/pn' +import type { PrismaClient as PrismaClientVeven, enum_Users_sex as SEXVEVEN } from '@/generated/veven' +import type { Limits } from './migrationLimits' /** * TODO: Need migrate reservations (mail reservations) ?, and flairs