Skip to content

Commit

Permalink
restore image fetching to image task (rebase accident)
Browse files Browse the repository at this point in the history
  • Loading branch information
AWare committed Oct 29, 2019
1 parent f5c2207 commit 3776ace
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions projects/archiver/src/tasks/image/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ import { ImageUse } from '../../../../common/src'
import { Image, ImageSize, imageSizes } from '../../../common'
import { handleAndNotifyOnError } from '../../services/task-handler'
import { FrontTaskOutput } from '../front'
import { getAndUploadImageUse, getImageUses } from './helpers/media'
import {
getAndUploadImageUse,
getImageUses,
getImagesFromFront,
} from './helpers/media'
import pAll = require('p-all')
import { getFront } from '../../utils/backend-client'

type ImageTaskInput = FrontTaskOutput
export interface ImageTaskOutput extends Omit<FrontTaskOutput, 'images'> {
Expand All @@ -18,16 +23,24 @@ export const handler: Handler<
> = handleAndNotifyOnError(
async ({ issuePublication, issue, frontId, ...params }) => {
const { publishedId } = issue
const maybeFront = await getFront(publishedId, frontId)

const imagesWithUses: [Image, ImageSize, ImageUse][] = unnest(
if (hasFailed(maybeFront)) {
console.error(JSON.stringify(attempt))
throw new Error(`Could not download front ${frontId}`)
}

console.log(`succesfully download front ${frontId}`, maybeFront)

const images: Image[] = unnest(getImagesFromFront(maybeFront))
type ImageSizeUse = [Image, ImageSize, ImageUse]
const imagesWithUses: ImageSizeUse[] = unnest(
unnest(
images.map(image =>
imageSizes.map(size =>
getImageUses(image).map((use): [
Image,
ImageSize,
ImageUse,
] => [image, size, use]),
getImageUses(image).map(
(use): ImageSizeUse => [image, size, use],
),
),
),
),
Expand Down

0 comments on commit 3776ace

Please sign in to comment.