fix: arch-03 worker system metric

This commit is contained in:
2026-03-13 13:40:30 +01:00
parent c6d5843022
commit 6eddc11253
5 changed files with 302 additions and 108 deletions

View File

@@ -1,4 +1,3 @@
import { Readable } from "node:stream"
import {
runSsh,
shellQuote,
@@ -16,37 +15,13 @@ function buildContentDisposition(fileName: string) {
return `attachment; filename="${asciiName}"; filename*=UTF-8''${encodeURIComponent(fileName)}`
}
function speedtestStream(event: H3Event) {
const size = 128 * 1024 * 1024
let sent = 0
const stream = new Readable({
read(chunkSize) {
if (sent >= size) {
this.push(null)
return
}
const remaining = size - sent
const chunk = Buffer.alloc(Math.min(chunkSize, remaining), "a")
sent += chunk.length
this.push(chunk)
}
})
setHeader(event, "Content-Type", "application/octet-stream")
setHeader(event, "Content-Length", size)
return stream
}
export default defineEventHandler(async (event) => {
const { folder, file } = getQuery(event)
const folderName = typeof folder === "string" ? folder : null
const fileName = typeof file === "string" ? file : null
// Compat mode: utilisé par le test de débit.
if (!folderName || !fileName) {
return speedtestStream(event)
throw createError({ statusCode: 400, statusMessage: "Paramètres manquants" })
}
if (!isSafeFolder(folderName) || !isSafeFile(fileName)) {

View File

@@ -0,0 +1,24 @@
import { Readable } from "node:stream"
export default defineEventHandler((event) => {
const size = 128 * 1024 * 1024
let sent = 0
const stream = new Readable({
read(chunkSize) {
if (sent >= size) {
this.push(null)
return
}
const remaining = size - sent
const chunk = Buffer.alloc(Math.min(chunkSize, remaining), "a")
sent += chunk.length
this.push(chunk)
}
})
setHeader(event, "Content-Type", "application/octet-stream")
setHeader(event, "Content-Length", size)
return stream
})