Test-CentralFeedbackEndpoint.ps1 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. [CmdletBinding()]
  2. param(
  3. [Parameter(Mandatory = $true)][ValidatePattern('^https://')][string]$Endpoint,
  4. [Parameter(Mandatory = $true)][ValidatePattern('^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$')][string]$ProjectId
  5. )
  6. $ErrorActionPreference = 'Stop'
  7. $fileBytes = $null
  8. try {
  9. $testText = "# Central feedback endpoint test`r`n`r`nThis file verifies the public endpoint and Feishu delivery path. It contains no project data.`r`n"
  10. $fileBytes = [Text.Encoding]::UTF8.GetBytes($testText)
  11. $payload = @{
  12. project_id = $ProjectId
  13. record_version = 'v1.0.0'
  14. trigger = 'OWNER-REQUEST'
  15. file_name = ($ProjectId + '-endpoint-test-v1.0.0.md')
  16. file_base64 = [Convert]::ToBase64String($fileBytes)
  17. } | ConvertTo-Json -Compress
  18. [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
  19. $uri = $Endpoint.TrimEnd('/') + '/v1/feedback'
  20. $result = Invoke-RestMethod -Method Post -Uri $uri -ContentType 'application/json' -Body $payload -TimeoutSec 120
  21. $result
  22. }
  23. catch {
  24. $message = $_.Exception.Message
  25. if ($_.ErrorDetails -and $_.ErrorDetails.Message) { $message = $_.ErrorDetails.Message }
  26. [pscustomobject]@{ status = 'not_sent'; detail = $message }
  27. exit 1
  28. }
  29. finally {
  30. if ($fileBytes) { [Array]::Clear($fileBytes, 0, $fileBytes.Length) }
  31. }