mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 16:38:19 +01:00
fix(api): 🐛 Fix various data encoding bugs
This commit is contained in:
parent
de4381e151
commit
2779b76f44
|
|
@ -34,6 +34,7 @@ export const schemas = {
|
||||||
"timeline[]": z
|
"timeline[]": z
|
||||||
.array(z.enum(["home", "notifications"]))
|
.array(z.enum(["home", "notifications"]))
|
||||||
.max(2)
|
.max(2)
|
||||||
|
.or(z.enum(["home", "notifications"]))
|
||||||
.optional(),
|
.optional(),
|
||||||
"home[last_read_id]": z.string().regex(idValidator).optional(),
|
"home[last_read_id]": z.string().regex(idValidator).optional(),
|
||||||
"notifications[last_read_id]": z.string().regex(idValidator).optional(),
|
"notifications[last_read_id]": z.string().regex(idValidator).optional(),
|
||||||
|
|
@ -47,9 +48,11 @@ export default (app: Hono) =>
|
||||||
zValidator("query", schemas.query, handleZodError),
|
zValidator("query", schemas.query, handleZodError),
|
||||||
auth(meta.auth),
|
auth(meta.auth),
|
||||||
async (context) => {
|
async (context) => {
|
||||||
const { "timeline[]": timeline } = context.req.valid("query");
|
const { "timeline[]": timelines } = context.req.valid("query");
|
||||||
const { user } = context.req.valid("header");
|
const { user } = context.req.valid("header");
|
||||||
|
|
||||||
|
const timeline = Array.isArray(timelines) ? timelines : [];
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return errorResponse("Unauthorized", 401);
|
return errorResponse("Unauthorized", 401);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -178,13 +178,15 @@ describe(meta.route, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should create a post with visibility", async () => {
|
test("should create a post with visibility", async () => {
|
||||||
|
// This one uses JSON to test the interop
|
||||||
const response = await sendTestRequest(
|
const response = await sendTestRequest(
|
||||||
new Request(new URL(meta.route, config.http.base_url), {
|
new Request(new URL(meta.route, config.http.base_url), {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens[0].accessToken}`,
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
||||||
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: new URLSearchParams({
|
body: JSON.stringify({
|
||||||
status: "Hello, world!",
|
status: "Hello, world!",
|
||||||
visibility: "unlisted",
|
visibility: "unlisted",
|
||||||
federate: "false",
|
federate: "false",
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { applyConfig, auth, handleZodError, qs } from "@api";
|
import { applyConfig, auth, handleZodError, jsonOrForm, qs } from "@api";
|
||||||
import { zValidator } from "@hono/zod-validator";
|
import { zValidator } from "@hono/zod-validator";
|
||||||
import { errorResponse, jsonResponse } from "@response";
|
import { errorResponse, jsonResponse } from "@response";
|
||||||
import { config } from "config-manager";
|
import { config } from "config-manager";
|
||||||
|
|
@ -83,7 +83,7 @@ export default (app: Hono) =>
|
||||||
app.on(
|
app.on(
|
||||||
meta.allowedMethods,
|
meta.allowedMethods,
|
||||||
meta.route,
|
meta.route,
|
||||||
qs(),
|
jsonOrForm(),
|
||||||
zValidator("form", schemas.form, handleZodError),
|
zValidator("form", schemas.form, handleZodError),
|
||||||
auth(meta.auth),
|
auth(meta.auth),
|
||||||
async (context) => {
|
async (context) => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue