mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-10-29 18:15:13 +08:00
🐤 Sync 2026-08-24 23:23:52
This commit is contained in:
1 parent
73568a624f
commit
1391687e01
82 files changed
+5971
-5537
No files matched your search
@@ -116,6 +116,22 @@ function processLines(buffer, onChunk) {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
// Parse the docker multiplexed stream format, https://docs.docker.com/reference/api/engine/version/v1.43/#stream-format
|
||||
function parse_multiplexed_stream(buffer) {
|
||||
const output = [];
|
||||
|
||||
while (buffer.length > 0) {
|
||||
if (buffer.length < 8) break; // Not enough data for header
|
||||
let stream_type = buffer.charCodeAt(0);
|
||||
let payload_length = (buffer.charCodeAt(4) << 24) | (buffer.charCodeAt(5) << 16) | (buffer.charCodeAt(6) << 8) | buffer.charCodeAt(7);
|
||||
if (buffer.length < 8 + payload_length) break; // Not enough data for payload
|
||||
let payload = buffer.slice(8, 8 + payload_length);
|
||||
output.push({ type: stream_type, payload: payload });
|
||||
buffer = buffer.slice(8 + payload_length);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
function call_docker(method, path, options = {}) {
|
||||
return loadPromise.then(() => {
|
||||
@@ -228,20 +244,24 @@ function call_docker(method, path, options = {}) {
|
||||
let parsed = safeText || text;
|
||||
const contentType = response.headers.get('content-type') || '';
|
||||
|
||||
// Try normal JSON parse first
|
||||
try {
|
||||
parsed = JSON.parse(text);
|
||||
} catch (err) {
|
||||
// If the payload is newline-delimited JSON (Docker events), split and parse each line
|
||||
if (['application/json',
|
||||
'application/x-ndjson',
|
||||
'application/json-seq'].includes(contentType) || safeText.includes('\n')) {
|
||||
const lines = safeText.split(/\r?\n/).filter(Boolean);
|
||||
try {
|
||||
parsed = lines.map(l => JSON.parse(l));
|
||||
} catch (err2) {
|
||||
// Fall back to raw text if parsing fails
|
||||
parsed = text;
|
||||
if ("application/vnd.docker.multiplexed-stream" == contentType) {
|
||||
parsed = parse_multiplexed_stream(safeText);
|
||||
} else {
|
||||
// Try normal JSON parse first
|
||||
try {
|
||||
parsed = JSON.parse(text);
|
||||
} catch (err) {
|
||||
// If the payload is newline-delimited JSON (Docker events), split and parse each line
|
||||
if (['application/json',
|
||||
'application/x-ndjson',
|
||||
'application/json-seq'].includes(contentType) || safeText.includes('\n')) {
|
||||
const lines = safeText.split(/\r?\n/).filter(Boolean);
|
||||
try {
|
||||
parsed = lines.map(l => JSON.parse(l));
|
||||
} catch (err2) {
|
||||
// Fall back to raw text if parsing fails
|
||||
parsed = text;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1280,13 +1280,14 @@ const ansiToHtml = function(text) {
|
||||
// Escape HTML special characters
|
||||
const escapeHtml = (str) => {
|
||||
const map = {
|
||||
' ': ' ',
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
'"': '"',
|
||||
"'": '''
|
||||
};
|
||||
return str.replace(/[&<>"']/g, m => map[m]);
|
||||
return str.replace(/[&<>"' ]/g, m => map[m]);
|
||||
};
|
||||
|
||||
// Split by ANSI escape sequences and process
|
||||
|
||||
Reference in new issue
Block a user