MCPcopy Create free account
hub / github.com/MCSManager/MCSManager / sendFile

Function sendFile

daemon/src/utils/speed_limit.ts:118–137  ·  view source on GitHub ↗
(ctx: ParameterizedContext, fileAbsPath: string)

Source from the content-addressed store, hash-verified

116}
117
118export async function sendFile(ctx: ParameterizedContext, fileAbsPath: string) {
119 const rate = Number(globalConfiguration.config.downloadSpeedRate) || 0;
120 if (rate <= 0) {
121 const fileDir = path.dirname(fileAbsPath);
122 const fileName = path.basename(fileAbsPath);
123 ctx.set("Content-Type", "application/octet-stream");
124 await send(ctx, fileName, { root: fileDir + "/", hidden: true });
125 return;
126 }
127
128 const fileName = path.basename(fileAbsPath);
129 const stats = await fsPromises.stat(fileAbsPath);
130
131 ctx.set("Content-Type", "application/octet-stream");
132 ctx.set("Content-Disposition", `attachment; filename="${encodeURIComponent(fileName)}"`);
133 ctx.set("Content-Length", stats.size.toString());
134
135 const fileStream = createReadStream(fileAbsPath);
136 ctx.body = fileStream.pipe(new ThrottleTransform(rate));
137}

Callers 1

http_router.tsFile · 0.90

Calls 1

setMethod · 0.45

Tested by

no test coverage detected