Skip to content

Commit

Permalink
Fix RegEx
Browse files Browse the repository at this point in the history
  • Loading branch information
niheaven authored Mar 21, 2022
1 parent 34b4d00 commit 6d0d0ad
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions lib/core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1032,16 +1032,15 @@ function handle_special_urls($url)
}

# github.com
if ($url -match "github.com\/(?<owner>[^\/]+)\/(?<repo>[^\/]+)\/releases\/download\/(?<tag>[^\/]+)\/(?<file>[^\/#]+)(?<filename>.*)" -and (get_config 'checkver_token')) {
if ($url -match 'github.com/(?<owner>[^/]+)/(?<repo>[^/]+)/releases/download/(?<tag>[^/]+)/(?<file>[^/#]+)(?<filename>.*)' -and ($token = get_config 'checkver_token')) {
$headers = @{
"Authorization" = "token $(get_config 'checkver_token')"
"Authorization" = "token $token"
}
$privateUrl = "https://api.github.com/repos/$($matches['owner'])/$($matches['repo'])"
$assetUrl="https://api.github.com/repos/$($matches['owner'])/$($matches['repo'])/releases/tags/$($matches['tag'])"
$privateUrl = "https://api.github.com/repos/$($Matches.owner)/$($Matches.repo)"
$assetUrl = "https://api.github.com/repos/$($Matches.owner)/$($Matches.repo)/releases/tags/$($Matches.tag)"

$isPrivate = (Invoke-RestMethod -Uri $privateUrl -Headers $headers).private
if ($isPrivate) {
$url = ((Invoke-RestMethod -Uri $assetUrl -Headers $headers).assets | Where-Object { $_.name -eq $matches['file'] }).url + $($matches['filename'])
if ((Invoke-RestMethod -Uri $privateUrl -Headers $headers).Private) {
$url = ((Invoke-RestMethod -Uri $assetUrl -Headers $headers).Assets | Where-Object -Property Name -EQ -Value $Matches.file).Url, $Matches.filename -join ''
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ function dl($url, $to, $cookies, $progress) {
if (-not ($url -imatch "sourceforge\.net" -or $url -imatch "portableapps\.com")) {
$wreq.referer = strip_filename $url
}
if ($url -imatch "api\.github\.com\/repos") {
if ($url -imatch "api\.github\.com/repos") {
$wreq.accept = "application/octet-stream"
$wreq.headers["Authorization"] = "token $(get_config 'checkver_token')"
}
Expand Down

0 comments on commit 6d0d0ad

Please sign in to comment.