File size: 1,508 Bytes
44fe180
 
 
 
 
 
 
c4b02b2
44fe180
 
 
b785e1d
 
 
44fe180
 
c4b02b2
 
 
 
 
 
44fe180
 
 
 
 
 
 
 
 
 
b785e1d
c4b02b2
44fe180
 
 
c4b02b2
 
44fe180
 
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { RenderRequest } from "../types.mts"
import { generateSeed } from "./generateSeed.mts"
import { getValidBoolean } from "./getValidBoolean.mts"
import { getValidNumber } from "./getValidNumber.mts"

export function parseRenderRequest(request: RenderRequest) {

  console.log("parseRenderRequest: "+JSON.stringify(request, null, 2))
  try {
    request.nbFrames = getValidNumber(request.nbFrames, 1, 24, 16)

    // wait! if we uncomment this, this will invalidate all the images already in cache..
    // request.negativePrompt = request.negativePrompt || ""

    const isVideo = request?.nbFrames === 1

    // note that we accept a seed of 0
    // (this ensure we are able to cache the whote request by signing it)
    request.seed = getValidNumber(request.seed, 0, 2147483647, 0)

    // but obviously we will treat 0 as the random seed at a later stage

    request.nbSteps = getValidNumber(request.nbSteps, 5, 50, 10)

    if (isVideo) {
      request.width = getValidNumber(request.width, 256, 1024, 1024)
      request.height = getValidNumber(request.height, 256, 1024, 512)
    } else {
      request.width = getValidNumber(request.width, 256, 1280, 576)
      request.height = getValidNumber(request.height, 256, 720, 320)
    }

    request.wait = request?.wait || false
    request.cache = request?.cache || "ignore"
  } catch (err) {
    console.error(`failed to parse the render request: ${err}`)
  }

  console.log("parsed request: "+JSON.stringify(request, null, 2))
  return request
}