File size: 951 Bytes
caa2240
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { RenderedScene, RenderRequest } from "../types.mts"
import { upscaleImage } from "../utils/upscaleImage.mts"

export async function renderImageUpscaling(
  request: RenderRequest,
  response: RenderedScene,
): Promise<RenderedScene> {
  
  try {
    // note: this converts a base64 PNG to a base64 JPG (which is good, actually!)
    response.assetUrl = await upscaleImage(response.assetUrl)
    console.log(`upscaling worked on the first try!`)
  } catch (err) {
    console.error(`upscaling failed the first time.. let's try again..`)
    try {
      response.assetUrl = await upscaleImage(response.assetUrl)
      console.log(`upscaling worked on the second try!`)
    } catch (err) {
      console.error(`upscaling failed on the second attempt.. let's keep the low-res image then :|`)
      // no need to log a catastrophic failure here, since we still have the original (low-res image)
      // to work with
    }
  }

  return response
}