Skip to content

Commit

Permalink
Merge pull request #268 from CrowdStrike/2.2.4
Browse files Browse the repository at this point in the history
2.2.4
  • Loading branch information
bk-cs authored Jan 17, 2023
2 parents b07531f + b934519 commit 23d107a
Show file tree
Hide file tree
Showing 65 changed files with 3,643 additions and 1,470 deletions.
38 changes: 38 additions & 0 deletions Class/Class.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class ApiClient {
[System.IO.FileMode]::Open)
$Filename = [System.IO.Path]::GetFileName($this.Path($_.Value))
$StreamContent = [System.Net.Http.StreamContent]::New($FileStream)
$FileType = $this.StreamType($Filename)
if ($FileType) { $StreamContent.Headers.ContentType = $FileType }
$Message.Content.Add($StreamContent,$_.Key,$Filename)
@($_.Key,'<StreamContent>') -join '='
} else {
Expand Down Expand Up @@ -74,6 +76,9 @@ class ApiClient {
if ($Output.Result.Headers) {
Write-Verbose "[ApiClient.Invoke] $($Output.Result.Headers.GetEnumerator().foreach{
@($_.Key,(@($_.Value) -join ', ')) -join '=' } -join ', ')"
($Output.Result.Headers.GetEnumerator().Where({ $_.Key -match '^X-Api-Deprecation' })).foreach{
Write-Warning ([string]$_.Key,[string]$_.Value -join ': ')
}
}
if ($Output.Result -and $this.Collector.Enable -contains 'responses') { $this.Log($Output.Result) }
} catch {
Expand Down Expand Up @@ -135,4 +140,37 @@ class ApiClient {
Remove-Job -Id $_.Id
}
}
[string] StreamType([string]$String) {
[string]$Extension = [System.IO.Path]::GetExtension($String) -replace '^\.',$null
$Output = switch -Regex ($Extension) {
'^(bmp|gif|jp(e?)g|png)$' { "image/$_" }
'^(pdf|zip)$' { "application/$_" }
'^7z$' { 'application/x-7z-compressed' }
'^(csv|txt)$' {
if ($_ -eq 'txt') { 'text/plain' } else { "text/$_" }
}
'^doc(x?)$' {
if ($_ -match 'x$') {
'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
} else {
'application/msword'
}
}
'^ppt(x?)$' {
if ($_ -match 'x$') {
'application/vnd.openxmlformats-officedocument.presentationml.presentation'
} else {
'application/vnd.ms-powerpoint'
}
}
'^xls(x?)$' {
if ($_ -match 'x$') {
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
} else {
'application/vnd.ms-excel'
}
}
}
return $Output
}
}
Loading

0 comments on commit 23d107a

Please sign in to comment.