File size: 2,095 Bytes
08b23ce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
param(
  [string]$BaseUrl = "https://seungminkwak-puppeteer-api.hf.space",
  [string]$Token   = "",
  [string]$MeshUrl = "https://cdn.jsdelivr.net/gh/KhronosGroup/glTF-Sample-Models@master/2.0/CesiumMan/glTF-Binary/CesiumMan.glb",
  [string]$Workdir = "job-cesium",
  [int]$MaxTries = 12,
  [int]$DelaySec = 10
)

$ErrorActionPreference = "Stop"

Write-Host "=== Puppeteer API quick test ==="
Write-Host "[1] /health"
$health = Invoke-RestMethod -Uri "$BaseUrl/health" -Headers @{ Authorization = "Bearer $Token" }
$health | ConvertTo-Json -Depth 6 | Write-Host

Write-Host "[2] /rig"
$body = @{ mesh_url = $MeshUrl; workdir = $Workdir } | ConvertTo-Json -Depth 6
$resp = Invoke-RestMethod -Uri "$BaseUrl/rig" -Headers @{ Authorization = "Bearer $Token"; "Content-Type"="application/json" } -Method POST -Body $body
$resp | ConvertTo-Json -Depth 6 | Write-Host

Write-Host "[3] Poll /list"
$files = @()
for ($i=1; $i -le $MaxTries; $i++) {
  try {
    $list = Invoke-RestMethod -Uri "$BaseUrl/list" -Headers @{ Authorization = "Bearer $Token" }
    if ($list.files_preview) {
      $files = $list.files_preview
      Write-Host (" -> Found: {0}" -f ($files -join ", "))
      break
    } else {
      Write-Host (" -> Try {0}/{1}: no files yet" -f $i, $MaxTries)
    }
  } catch {
    Write-Host (" -> Try {0}/{1}: error {2}" -f $i, $MaxTries, $_.Exception.Message)
  }
  Start-Sleep -Seconds $DelaySec
}

if (-not $files -or $files.Count -eq 0) {
  Write-Host "No result files found." -ForegroundColor Red
  exit 2
}

# choose a file
$preferred = "/data/results/rigged.glb"
$target = if ($files -contains $preferred) { $preferred } else { $files[0] }
Write-Host ("[4] Download {0}" -f $target)

$enc = [uri]::EscapeDataString($target)
$newDir = Join-Path $PWD "results"
New-Item -ItemType Directory -Path $newDir -Force | Out-Null
$out = Join-Path $newDir (Split-Path -Leaf $target)
Invoke-WebRequest -Uri "$BaseUrl/download?path=$enc" -Headers @{ Authorization = "Bearer $Token" } -OutFile $out
Write-Host ("Saved to {0}" -f $out)
try { ii $out | Out-Null } catch {}
Write-Host "=== Done ==="