fix(api): 🐛 Correctly return empty body without content-type headers, when returning empty responses

This commit is contained in:
Jesse Wierzbinski 2024-12-07 12:20:06 +01:00
parent 2743528727
commit 06376cf58a
No known key found for this signature in database
15 changed files with 18 additions and 18 deletions

View file

@ -146,7 +146,7 @@ export default apiRoute((app) => {
await role.linkUser(targetUser.id); await role.linkUser(targetUser.id);
return context.newResponse(null, 204); return context.body(null, 204);
}); });
app.openapi(routeDelete, async (context) => { app.openapi(routeDelete, async (context) => {
@ -186,6 +186,6 @@ export default apiRoute((app) => {
await role.unlinkUser(targetUser.id); await role.unlinkUser(targetUser.id);
return context.newResponse(null, 204); return context.body(null, 204);
}); });
}); });

View file

@ -337,6 +337,6 @@ export default apiRoute((app) =>
email: email ?? "", email: email ?? "",
}); });
return context.newResponse(null, 200); return context.body(null, 200);
}), }),
); );

View file

@ -352,6 +352,6 @@ export default apiRoute((app) => {
await db.delete(Emojis).where(eq(Emojis.id, id)); await db.delete(Emojis).where(eq(Emojis.id, id));
return context.newResponse(null, 204); return context.body(null, 204);
}); });
}); });

View file

@ -68,6 +68,6 @@ export default apiRoute((app) =>
dismissed: true, dismissed: true,
}); });
return context.newResponse(null, 200); return context.body(null, 200);
}), }),
); );

View file

@ -47,6 +47,6 @@ export default apiRoute((app) =>
await user.clearAllNotifications(); await user.clearAllNotifications();
return context.newResponse(null, 200); return context.body(null, 200);
}), }),
); );

View file

@ -60,6 +60,6 @@ export default apiRoute((app) =>
await user.clearSomeNotifications(ids); await user.clearSomeNotifications(ids);
return context.newResponse(null, 200); return context.body(null, 200);
}), }),
); );

View file

@ -226,7 +226,7 @@ export default apiRoute((app) => {
visible, visible,
}); });
return context.newResponse(null, 204); return context.body(null, 204);
}); });
app.openapi(routeDelete, async (context) => { app.openapi(routeDelete, async (context) => {
@ -261,6 +261,6 @@ export default apiRoute((app) => {
await role.delete(); await role.delete();
return context.newResponse(null, 204); return context.body(null, 204);
}); });
}); });

View file

@ -343,6 +343,6 @@ export default apiRoute((app) => {
.delete(Filters) .delete(Filters)
.where(and(eq(Filters.userId, user.id), eq(Filters.id, id))); .where(and(eq(Filters.userId, user.id), eq(Filters.id, id)));
return context.newResponse(null, 204); return context.body(null, 204);
}); });
}); });

View file

@ -65,7 +65,7 @@ export default apiRoute((app) =>
ip: context.env.ip ?? null, ip: context.env.ip ?? null,
}); });
return context.newResponse( return context.body(
"Request processing initiated.\nImplement the Instance Messaging Extension to receive any eventual feedback (errors, etc.)", "Request processing initiated.\nImplement the Instance Messaging Extension to receive any eventual feedback (errors, etc.)",
200, 200,
); );

View file

@ -76,7 +76,7 @@ export default apiRoute((app) =>
} }
// Can't directly copy file into Response because this crashes Bun for now // Can't directly copy file into Response because this crashes Bun for now
return context.newResponse(buffer, 200, { return context.body(buffer, 200, {
"Content-Type": file.type || "application/octet-stream", "Content-Type": file.type || "application/octet-stream",
"Content-Length": `${file.size - start}`, "Content-Length": `${file.size - start}`,
"Content-Range": `bytes ${start}-${end}/${file.size}`, "Content-Range": `bytes ${start}-${end}/${file.size}`,

View file

@ -85,7 +85,7 @@ export default apiRoute((app) =>
.get("Content-Disposition") .get("Content-Disposition")
?.match(/filename="(.+)"/)?.[1] || id.split("/").pop(); ?.match(/filename="(.+)"/)?.[1] || id.split("/").pop();
return context.newResponse(media.body, media.status as StatusCode, { return context.body(media.body, media.status as StatusCode, {
"Content-Type": "Content-Type":
media.headers.get("Content-Type") || "application/octet-stream", media.headers.get("Content-Type") || "application/octet-stream",
"Content-Length": media.headers.get("Content-Length") || "0", "Content-Length": media.headers.get("Content-Length") || "0",

View file

@ -43,6 +43,6 @@ export default apiRoute((app) =>
getLogger(["federation", "messaging"]) getLogger(["federation", "messaging"])
.info`Received message via ${chalk.bold("Instance Messaging")}:\n${content}`; .info`Received message via ${chalk.bold("Instance Messaging")}:\n${content}`;
return context.newResponse(null, 200); return context.body(null, 200);
}), }),
); );

View file

@ -116,7 +116,7 @@ export default apiRoute((app) =>
ip: context.env.ip ?? null, ip: context.env.ip ?? null,
}); });
return context.newResponse( return context.body(
"Request processing initiated.\nImplement the Instance Messaging Extension to receive any eventual feedback (errors, etc.)", "Request processing initiated.\nImplement the Instance Messaging Extension to receive any eventual feedback (errors, etc.)",
200, 200,
); );

View file

@ -33,7 +33,7 @@ export const bait = createMiddleware(async (context, next) => {
if (requestIp?.address) { if (requestIp?.address) {
for (const ip of config.http.bait.bait_ips) { for (const ip of config.http.bait.bait_ips) {
if (matches(ip, requestIp.address)) { if (matches(ip, requestIp.address)) {
return context.newResponse(file.stream()); return context.body(file.stream());
} }
} }
} }
@ -43,7 +43,7 @@ export const bait = createMiddleware(async (context, next) => {
for (const agent of config.http.bait.bait_user_agents) { for (const agent of config.http.bait.bait_user_agents) {
if (new RegExp(agent).test(ua)) { if (new RegExp(agent).test(ua)) {
return context.newResponse(file.stream()); return context.body(file.stream());
} }
} }

View file

@ -201,7 +201,7 @@ export default (plugin: PluginType): void => {
.delete(OpenIdAccounts) .delete(OpenIdAccounts)
.where(eq(OpenIdAccounts.id, account.id)); .where(eq(OpenIdAccounts.id, account.id));
return context.newResponse(null, 204); return context.body(null, 204);
}, },
); );
}); });