Skip to content

Commit

Permalink
Optimise code for Opera apps #487
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronparker committed Sep 20, 2023
1 parent acaeb0a commit 6aa82ad
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 87 deletions.
32 changes: 5 additions & 27 deletions Evergreen/Apps/Get-OperaBrowser.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,14 @@ function Get-OperaBrowser {
Twitter: @stealthpuppy
#>
[OutputType([System.Management.Automation.PSObject])]
[CmdletBinding(SupportsShouldProcess = $False)]
[CmdletBinding(SupportsShouldProcess = $false)]
param (
[Parameter(Mandatory = $False, Position = 0)]
[ValidateNotNull()]
[Parameter(Mandatory = $false, Position = 0)]
[ValidateNotNullOrEmpty()]
[System.Management.Automation.PSObject]
$res = (Get-FunctionResource -AppName ("$($MyInvocation.MyCommand)".Split("-"))[1])
)

foreach ($Channel in $res.Get.Update.Channels) {
$Update = Invoke-RestMethodWrapper -Uri $res.Get.Update.Uri[$Channel]

if ($Null -ne $Update.($res.Get.Update.Property)) {
Write-Verbose -Message "$($MyInvocation.MyCommand): checking property: $($res.Get.Update.Property)."
Write-Verbose -Message "$($MyInvocation.MyCommand): found version: $($Update.($res.Get.Update.Property))"

# Step through each installer type
foreach ($Architecture in $res.Get.Download.Architectures) {

# Build the output object; Output object to the pipeline
$Url = $res.Get.Download.Uri[$Channel] -replace $res.Get.Download.ReplaceText, $Update.($res.Get.Update.Property) `
-replace "#architecture", $res.Get.Download.Architecture[$Architecture]
$PSObject = [PSCustomObject] @{
Version = $Update.($res.Get.Update.Property)
Channel = $Channel
Architecture = $Architecture
Type = Get-FileType -File $Url
URI = $Url
}
Write-Output -InputObject $PSObject
}
}
}
$Output = Get-OperaApp -res $res
Write-Output -InputObject $Output
}
32 changes: 5 additions & 27 deletions Evergreen/Apps/Get-OperaCryptoBrowser.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,14 @@ function Get-OperaCryptoBrowser {
Twitter: @stealthpuppy
#>
[OutputType([System.Management.Automation.PSObject])]
[CmdletBinding(SupportsShouldProcess = $False)]
[CmdletBinding(SupportsShouldProcess = $false)]
param (
[Parameter(Mandatory = $False, Position = 0)]
[ValidateNotNull()]
[Parameter(Mandatory = $false, Position = 0)]
[ValidateNotNullOrEmpty()]
[System.Management.Automation.PSObject]
$res = (Get-FunctionResource -AppName ("$($MyInvocation.MyCommand)".Split("-"))[1])
)

foreach ($Channel in $res.Get.Update.Channels) {
$Update = Invoke-RestMethodWrapper -Uri $res.Get.Update.Uri[$Channel]

if ($Null -ne $Update.($res.Get.Update.Property)) {
Write-Verbose -Message "$($MyInvocation.MyCommand): checking property: $($res.Get.Update.Property)."
Write-Verbose -Message "$($MyInvocation.MyCommand): found version: $($Update.($res.Get.Update.Property))"

# Step through each installer type
foreach ($Architecture in $res.Get.Download.Architectures) {

# Build the output object; Output object to the pipeline
$Url = $res.Get.Download.Uri[$Channel] -replace $res.Get.Download.ReplaceText, $Update.($res.Get.Update.Property) `
-replace "#architecture", $res.Get.Download.Architecture[$Architecture]
$PSObject = [PSCustomObject] @{
Version = $Update.($res.Get.Update.Property)
Channel = $Channel
Architecture = $Architecture
Type = Get-FileType -File $Url
URI = $Url
}
Write-Output -InputObject $PSObject
}
}
}
$Output = Get-OperaApp -res $res
Write-Output -InputObject $Output
}
32 changes: 5 additions & 27 deletions Evergreen/Apps/Get-OperaGXBrowser.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,14 @@ function Get-OperaGXBrowser {
Twitter: @stealthpuppy
#>
[OutputType([System.Management.Automation.PSObject])]
[CmdletBinding(SupportsShouldProcess = $False)]
[CmdletBinding(SupportsShouldProcess = $false)]
param (
[Parameter(Mandatory = $False, Position = 0)]
[ValidateNotNull()]
[Parameter(Mandatory = $false, Position = 0)]
[ValidateNotNullOrEmpty()]
[System.Management.Automation.PSObject]
$res = (Get-FunctionResource -AppName ("$($MyInvocation.MyCommand)".Split("-"))[1])
)

foreach ($Channel in $res.Get.Update.Channels) {
$Update = Invoke-RestMethodWrapper -Uri $res.Get.Update.Uri[$Channel]

if ($Null -ne $Update.($res.Get.Update.Property)) {
Write-Verbose -Message "$($MyInvocation.MyCommand): checking property: $($res.Get.Update.Property)."
Write-Verbose -Message "$($MyInvocation.MyCommand): found version: $($Update.($res.Get.Update.Property))"

# Step through each installer type
foreach ($Architecture in $res.Get.Download.Architectures) {

# Build the output object; Output object to the pipeline
$Url = $res.Get.Download.Uri[$Channel] -replace $res.Get.Download.ReplaceText, $Update.($res.Get.Update.Property) `
-replace "#architecture", $res.Get.Download.Architecture[$Architecture]
$PSObject = [PSCustomObject] @{
Version = $Update.($res.Get.Update.Property)
Channel = $Channel
Architecture = $Architecture
Type = Get-FileType -File $Url
URI = $Url
}
Write-Output -InputObject $PSObject
}
}
}
$Output = Get-OperaApp -res $res
Write-Output -InputObject $Output
}
3 changes: 1 addition & 2 deletions Evergreen/Manifests/OperaBrowser.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
"Architectures": [
"x64",
"x86"
],
"ReplaceText": "#version"
]
}
},
"Install": {
Expand Down
3 changes: 1 addition & 2 deletions Evergreen/Manifests/OperaCryptoBrowser.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
},
"Architectures": [
"x64"
],
"ReplaceText": "#version"
]
}
},
"Install": {
Expand Down
3 changes: 1 addition & 2 deletions Evergreen/Manifests/OperaGXBrowser.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
"Architectures": [
"x64",
"x86"
],
"ReplaceText": "#version"
]
}
},
"Install": {
Expand Down
45 changes: 45 additions & 0 deletions Evergreen/Shared/Get-OperaApp.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
function Get-OperaApp {
<#
.SYNOPSIS
Returns the available version and URIs for Opera apps
.NOTES
Author: Aaron Parker
Twitter: @stealthpuppy
#>
[OutputType([System.Management.Automation.PSObject])]
[CmdletBinding(SupportsShouldProcess = $false)]
param (
[Parameter(Mandatory = $false, Position = 0)]
[ValidateNotNullOrEmpty()]
[System.Management.Automation.PSObject]
$res = (Get-FunctionResource -AppName ("$($MyInvocation.MyCommand)".Split("-"))[1])
)

foreach ($Channel in $res.Get.Update.Channels) {
$Update = Invoke-RestMethodWrapper -Uri $res.Get.Update.Uri[$Channel]

if ($null -ne $Update.($res.Get.Update.Property)) {
Write-Verbose -Message "$($MyInvocation.MyCommand): checking property: $($res.Get.Update.Property)."
Write-Verbose -Message "$($MyInvocation.MyCommand): found version: $($Update.($res.Get.Update.Property))"

# Step through each installer type
foreach ($Architecture in $res.Get.Download.Architectures) {

# Create the URL
$Url = $res.Get.Download.Uri[$Channel] -replace "#version", $Update.($res.Get.Update.Property) `
-replace "#architecture", $res.Get.Download.Architecture[$Architecture]

# Build the output object; Output object to the pipeline
$PSObject = [PSCustomObject] @{
Version = $Update.($res.Get.Update.Property)
Channel = $Channel
Architecture = $Architecture
Type = Get-FileType -File $Url
URI = $Url
}
Write-Output -InputObject $PSObject
}
}
}
}

0 comments on commit 6aa82ad

Please sign in to comment.