mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2025-01-10 23:51:01 -07:00
[mastodon-client] Fix request body handling for polls
This commit is contained in:
parent
fb8b2ce0df
commit
0f497f7fec
2 changed files with 3 additions and 14 deletions
|
@ -13,8 +13,6 @@ import { Cache } from "@/misc/cache.js";
|
||||||
import AsyncLock from "async-lock";
|
import AsyncLock from "async-lock";
|
||||||
import { ILocalUser } from "@/models/entities/user.js";
|
import { ILocalUser } from "@/models/entities/user.js";
|
||||||
import { PollHelpers } from "@/server/api/mastodon/helpers/poll.js";
|
import { PollHelpers } from "@/server/api/mastodon/helpers/poll.js";
|
||||||
import querystring from "node:querystring";
|
|
||||||
import qs from "qs";
|
|
||||||
|
|
||||||
const postIdempotencyCache = new Cache<{status?: MastodonEntity.Status}>('postIdempotencyCache', 60 * 60);
|
const postIdempotencyCache = new Cache<{status?: MastodonEntity.Status}>('postIdempotencyCache', 60 * 60);
|
||||||
const postIdempotencyLocks = new AsyncLock();
|
const postIdempotencyLocks = new AsyncLock();
|
||||||
|
@ -617,7 +615,7 @@ export function setupEndpointsStatus(router: Router): void {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const body: any = qs.parse(querystring.stringify(ctx.request.body as any));
|
const body: any = ctx.request.body;
|
||||||
const choices = NoteHelpers.normalizeToArray(body.choices ?? []).map(p => parseInt(p));
|
const choices = NoteHelpers.normalizeToArray(body.choices ?? []).map(p => parseInt(p));
|
||||||
if (choices.length < 1) {
|
if (choices.length < 1) {
|
||||||
ctx.status = 400;
|
ctx.status = 400;
|
||||||
|
|
|
@ -5,9 +5,7 @@ import {
|
||||||
NoteFavorites,
|
NoteFavorites,
|
||||||
NoteReactions,
|
NoteReactions,
|
||||||
Notes,
|
Notes,
|
||||||
RegistryItems,
|
UserNotePinings
|
||||||
UserNotePinings,
|
|
||||||
Users
|
|
||||||
} from "@/models/index.js";
|
} from "@/models/index.js";
|
||||||
import { generateVisibilityQuery } from "@/server/api/common/generate-visibility-query.js";
|
import { generateVisibilityQuery } from "@/server/api/common/generate-visibility-query.js";
|
||||||
import { generateMutedUserQuery } from "@/server/api/common/generate-muted-user-query.js";
|
import { generateMutedUserQuery } from "@/server/api/common/generate-muted-user-query.js";
|
||||||
|
@ -23,14 +21,11 @@ import deleteNote from "@/services/note/delete.js";
|
||||||
import { genId } from "@/misc/gen-id.js";
|
import { genId } from "@/misc/gen-id.js";
|
||||||
import { PaginationHelpers } from "@/server/api/mastodon/helpers/pagination.js";
|
import { PaginationHelpers } from "@/server/api/mastodon/helpers/pagination.js";
|
||||||
import { UserConverter } from "@/server/api/mastodon/converters/user.js";
|
import { UserConverter } from "@/server/api/mastodon/converters/user.js";
|
||||||
import { AccountCache, LinkPaginationObject, UserHelpers } from "@/server/api/mastodon/helpers/user.js";
|
import { LinkPaginationObject, UserHelpers } from "@/server/api/mastodon/helpers/user.js";
|
||||||
import { addPinned, removePinned } from "@/services/i/pin.js";
|
import { addPinned, removePinned } from "@/services/i/pin.js";
|
||||||
import { NoteConverter } from "@/server/api/mastodon/converters/note.js";
|
import { NoteConverter } from "@/server/api/mastodon/converters/note.js";
|
||||||
import { convertId, IdType } from "@/misc/convert-id.js";
|
import { convertId, IdType } from "@/misc/convert-id.js";
|
||||||
import querystring from "node:querystring";
|
|
||||||
import qs from "qs";
|
|
||||||
import { awaitAll } from "@/prelude/await-all.js";
|
import { awaitAll } from "@/prelude/await-all.js";
|
||||||
import { IsNull } from "typeorm";
|
|
||||||
import { VisibilityConverter } from "@/server/api/mastodon/converters/visibility.js";
|
import { VisibilityConverter } from "@/server/api/mastodon/converters/visibility.js";
|
||||||
import mfm from "mfm-js";
|
import mfm from "mfm-js";
|
||||||
import { FileConverter } from "@/server/api/mastodon/converters/file.js";
|
import { FileConverter } from "@/server/api/mastodon/converters/file.js";
|
||||||
|
@ -321,8 +316,6 @@ export class NoteHelpers {
|
||||||
public static normalizeComposeOptions(body: any): MastodonEntity.StatusCreationRequest {
|
public static normalizeComposeOptions(body: any): MastodonEntity.StatusCreationRequest {
|
||||||
const result: MastodonEntity.StatusCreationRequest = {};
|
const result: MastodonEntity.StatusCreationRequest = {};
|
||||||
|
|
||||||
body = qs.parse(querystring.stringify(body));
|
|
||||||
|
|
||||||
if (body.status !== null)
|
if (body.status !== null)
|
||||||
result.text = body.status;
|
result.text = body.status;
|
||||||
if (body.spoiler_text !== null)
|
if (body.spoiler_text !== null)
|
||||||
|
@ -357,8 +350,6 @@ export class NoteHelpers {
|
||||||
public static normalizeEditOptions(body: any): MastodonEntity.StatusEditRequest {
|
public static normalizeEditOptions(body: any): MastodonEntity.StatusEditRequest {
|
||||||
const result: MastodonEntity.StatusEditRequest = {};
|
const result: MastodonEntity.StatusEditRequest = {};
|
||||||
|
|
||||||
body = qs.parse(querystring.stringify(body));
|
|
||||||
|
|
||||||
if (body.status !== null)
|
if (body.status !== null)
|
||||||
result.text = body.status;
|
result.text = body.status;
|
||||||
if (body.spoiler_text !== null)
|
if (body.spoiler_text !== null)
|
||||||
|
|
Loading…
Reference in a new issue