Skip to content

Commit

Permalink
Get-Pixoo: Adding -Liked (Fixes #63)
Browse files Browse the repository at this point in the history
  • Loading branch information
James Brundage committed Nov 9, 2022
1 parent f1c3450 commit 0ae18f0
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions Functions/Pixoo/Get-Pixoo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ function Get-Pixoo
[switch]
$Upload,

# If set, will get liked images.
[Parameter(Mandatory,ParameterSetName='Likes')]
[Alias('Likes')]
[switch]
$Liked,

# If set, will clear any cached results.
[switch]
$Force
Expand Down Expand Up @@ -96,7 +102,7 @@ function Get-Pixoo
}
}

if ($PSCmdlet.ParameterSetName -eq 'Uploads') {
if ($PSCmdlet.ParameterSetName -in 'Uploads', 'Likes') {
foreach ($ip in $script:PixooCache.Keys) {

$deviceId = $script:PixooCache[$ip].DeviceID -as [int64]
Expand All @@ -106,16 +112,24 @@ function Get-Pixoo
} | ConvertTo-Json
$dataCacheKey = "$ip.$($PSCmdlet.ParameterSetName)"
if (-not $script:PixooDataCache[$dataCacheKey]) {

$restResults = Invoke-RestMethod -uri "https://app.divoom-gz.com/Device/GetImgUploadList" -Method Post -Body $body
$dataUri =
switch ($PSCmdlet.ParameterSetName) {
Uploads {
"https://app.divoom-gz.com/Device/GetImgUploadList"
}
Likes {
"https://app.divoom-gz.com/Device/GetImgLikeList"
}
}
$restResults = Invoke-RestMethod -uri $dataUri -Method Post -Body $body
$script:PixooDataCache[$dataCacheKey] = $restResults.ImgList | & { process {
if (-not $_) {
Write-Warning "Did not receive results for $deviceID. Try again in a second (Pixoo's API can be slow)."
return
}
$img = $_
$img.pstypenames.clear()
$img.pstypenames.add('Divoom.Upload')
$img.pstypenames.add("Divoom.$($PSCmdlet.ParameterSetName.TrimEnd('s'))")
$img.psobject.properties.Add([psnoteproperty]::new("IPAddress", $ip))
$img.psobject.properties.Add([psnoteproperty]::new("DeviceID", $deviceId))
$img
Expand Down

0 comments on commit 0ae18f0

Please sign in to comment.