mirror of
https://github.com/LizardByte/Sunshine.git
synced 2026-08-07 18:36:34 +00:00
refactor(confighttp): HTML page handlers into generic getPage function (#4645)
This commit is contained in:
+11
-6
@@ -1,15 +1,21 @@
|
||||
function generateExamples(endpoint, method, body = null) {
|
||||
let curlBodyString = '';
|
||||
let curlHeaderString = '';
|
||||
let psBodyString = '';
|
||||
let psContentTypeString = '';
|
||||
let psBodyParams = '';
|
||||
|
||||
if (body) {
|
||||
const curlJsonString = JSON.stringify(body).replace(/"/g, '\\"');
|
||||
curlBodyString = ` -d "${curlJsonString}"`;
|
||||
curlHeaderString = ' -H "Content-Type: application/json"';
|
||||
psBodyString = `-Body (ConvertTo-Json ${JSON.stringify(body)})`;
|
||||
psContentTypeString = '-ContentType \'application/json\'';
|
||||
psBodyParams = ' `\n ' + psBodyString + ' `\n ' + psContentTypeString;
|
||||
}
|
||||
|
||||
return {
|
||||
cURL: `curl -u user:pass -H "Content-Type: application/json" -X ${method.trim()} -k https://localhost:47990${endpoint.trim()}${curlBodyString}`,
|
||||
cURL: `curl -u user:pass${curlHeaderString} -X ${method.trim()} -k https://localhost:47990${endpoint.trim()}${curlBodyString}`,
|
||||
Python: `import json
|
||||
import requests
|
||||
from requests.auth import HTTPBasicAuth
|
||||
@@ -22,19 +28,18 @@ requests.${method.trim().toLowerCase()}(
|
||||
JavaScript: `fetch('https://localhost:47990${endpoint.trim()}', {
|
||||
method: '${method.trim()}',
|
||||
headers: {
|
||||
'Authorization': 'Basic ' + btoa('user:pass'),
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Basic ' + btoa('user:pass'),${body ? `\n 'Content-Type': 'application/json',` : ''}
|
||||
}${body ? `,\n body: JSON.stringify(${JSON.stringify(body)}),` : ''}
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => console.log(data));`,
|
||||
PowerShell: `Invoke-RestMethod \`
|
||||
-SkipCertificateCheck \`
|
||||
-ContentType 'application/json' \`
|
||||
-Uri 'https://localhost:47990${endpoint.trim()}' \`
|
||||
-Method ${method.trim()} \`
|
||||
-Headers @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes('user:pass'))}
|
||||
${psBodyString}`
|
||||
-Headers @{
|
||||
Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes('user:pass'))
|
||||
}${psBodyParams}`
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user