mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-22 01:47:39 -07:00
[mastodon-client] Replace array helper function with preexisting prelude function
This commit is contained in:
parent
2a64fe4ebf
commit
f0cedf4f39
3 changed files with 8 additions and 9 deletions
|
@ -9,6 +9,7 @@ import { PaginationHelpers } from "@/server/api/mastodon/helpers/pagination.js";
|
|||
import { UserLists } from "@/models/index.js";
|
||||
import { NoteHelpers } from "@/server/api/mastodon/helpers/note.js";
|
||||
import { getUser } from "@/server/api/common/getters.js";
|
||||
import { toArray } from "@/prelude/array.js";
|
||||
|
||||
export function setupEndpointsList(router: Router): void {
|
||||
router.get("/v1/lists", async (ctx, reply) => {
|
||||
|
@ -192,7 +193,7 @@ export function setupEndpointsList(router: Router): void {
|
|||
return;
|
||||
}
|
||||
|
||||
const ids = NoteHelpers.normalizeToArray(body['account_ids']).map(p => convertId(p, IdType.IceshrimpId));
|
||||
const ids = toArray(body['account_ids']).map(p => convertId(p, IdType.IceshrimpId));
|
||||
const targets = await Promise.all(ids.map(p => getUser(p)));
|
||||
await ListHelpers.addToList(user, list, targets);
|
||||
ctx.body = {}
|
||||
|
@ -229,7 +230,7 @@ export function setupEndpointsList(router: Router): void {
|
|||
return;
|
||||
}
|
||||
|
||||
const ids = NoteHelpers.normalizeToArray(body['account_ids']).map(p => convertId(p, IdType.IceshrimpId));
|
||||
const ids = toArray(body['account_ids']).map(p => convertId(p, IdType.IceshrimpId));
|
||||
const targets = await Promise.all(ids.map(p => getUser(p)));
|
||||
await ListHelpers.removeFromList(user, list, targets);
|
||||
ctx.body = {}
|
||||
|
|
|
@ -13,6 +13,7 @@ import { Cache } from "@/misc/cache.js";
|
|||
import AsyncLock from "async-lock";
|
||||
import { ILocalUser } from "@/models/entities/user.js";
|
||||
import { PollHelpers } from "@/server/api/mastodon/helpers/poll.js";
|
||||
import { toArray } from "@/prelude/array.js";
|
||||
|
||||
const postIdempotencyCache = new Cache<{ status?: MastodonEntity.Status }>('postIdempotencyCache', 60 * 60);
|
||||
const postIdempotencyLocks = new AsyncLock();
|
||||
|
@ -640,7 +641,7 @@ export function setupEndpointsStatus(router: Router): void {
|
|||
}
|
||||
|
||||
const body: any = ctx.request.body;
|
||||
const choices = NoteHelpers.normalizeToArray(body.choices ?? []).map(p => parseInt(p));
|
||||
const choices = toArray(body.choices ?? []).map(p => parseInt(p));
|
||||
if (choices.length < 1) {
|
||||
ctx.status = 400;
|
||||
ctx.body = {error: 'Must vote for at least one option'};
|
||||
|
|
|
@ -23,6 +23,7 @@ import { VisibilityConverter } from "@/server/api/mastodon/converters/visibility
|
|||
import mfm from "mfm-js";
|
||||
import { FileConverter } from "@/server/api/mastodon/converters/file.js";
|
||||
import { MfmHelpers } from "@/server/api/mastodon/helpers/mfm.js";
|
||||
import { toArray } from "@/prelude/array.js";
|
||||
|
||||
export class NoteHelpers {
|
||||
public static async getDefaultReaction(): Promise<string> {
|
||||
|
@ -331,7 +332,7 @@ export class NoteHelpers {
|
|||
result.in_reply_to_id = convertId(body.in_reply_to_id, IdType.IceshrimpId);
|
||||
if (body.media_ids)
|
||||
result.media_ids = body.media_ids && body.media_ids.length > 0
|
||||
? this.normalizeToArray(body.media_ids)
|
||||
? toArray(body.media_ids)
|
||||
.map(p => convertId(p, IdType.IceshrimpId))
|
||||
: undefined;
|
||||
|
||||
|
@ -359,7 +360,7 @@ export class NoteHelpers {
|
|||
result.language = body.language;
|
||||
if (body.media_ids)
|
||||
result.media_ids = body.media_ids && body.media_ids.length > 0
|
||||
? this.normalizeToArray(body.media_ids)
|
||||
? toArray(body.media_ids)
|
||||
.map(p => convertId(p, IdType.IceshrimpId))
|
||||
: undefined;
|
||||
|
||||
|
@ -375,8 +376,4 @@ export class NoteHelpers {
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static normalizeToArray<T>(subject: T | T[]) {
|
||||
return Array.isArray(subject) ? subject : [subject];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue