Compare commits
4 commits
7cf4e6bc42
...
98c3388052
Author | SHA1 | Date | |
---|---|---|---|
98c3388052 | |||
68f0de7c02 | |||
3f3d2082a9 | |||
b0875f7649 |
5 changed files with 8 additions and 12 deletions
|
@ -1,12 +1,10 @@
|
||||||
import { unsafeCast } from "./unsafe-cast.js";
|
|
||||||
|
|
||||||
export type Promiseable<T> = {
|
export type Promiseable<T> = {
|
||||||
[K in keyof T]: Promise<T[K]> | T[K];
|
[K in keyof T]: Promise<T[K]> | T[K];
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function awaitAll<T>(obj: Promiseable<T>): Promise<T> {
|
export async function awaitAll<T>(obj: Promiseable<T>): Promise<T> {
|
||||||
const target = {} as T;
|
const target = {} as T;
|
||||||
const keys = unsafeCast<(keyof T)[]>(Object.keys(obj));
|
const keys = Object.keys(obj) as unknown as (keyof T)[];
|
||||||
const values = Object.values(obj) as any[];
|
const values = Object.values(obj) as any[];
|
||||||
|
|
||||||
const resolvedValues = await Promise.all(
|
const resolvedValues = await Promise.all(
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
// unsafe type cast
|
|
||||||
export function unsafeCast<T>(val: unknown): T {
|
|
||||||
return val as T;
|
|
||||||
}
|
|
|
@ -1,8 +1,6 @@
|
||||||
import { Users } from "@/models/index.js";
|
import { Users } from "@/models/index.js";
|
||||||
import { publishInternalEvent } from "@/services/stream.js";
|
import { publishInternalEvent } from "@/services/stream.js";
|
||||||
import define from "../../define.js";
|
import define from "../../define.js";
|
||||||
import type { EmojiModPerm } from "@/models/entities/user.js";
|
|
||||||
import { unsafeCast } from "@/prelude/unsafe-cast.js";
|
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
tags: ["admin"],
|
tags: ["admin"],
|
||||||
|
@ -33,8 +31,12 @@ export default define(meta, paramDef, async (ps) => {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const _emojiModPerm =
|
||||||
|
(ps.emojiModPerm as "unauthorized" | "add" | "mod" | "full") ??
|
||||||
|
"unauthorized";
|
||||||
|
|
||||||
await Users.update(user.id, {
|
await Users.update(user.id, {
|
||||||
emojiModPerm: unsafeCast<EmojiModPerm>(ps.emojiModPerm),
|
emojiModPerm: _emojiModPerm,
|
||||||
});
|
});
|
||||||
|
|
||||||
publishInternalEvent("userChangeModeratorState", {
|
publishInternalEvent("userChangeModeratorState", {
|
||||||
|
|
|
@ -17,7 +17,7 @@ export const paramDef = {
|
||||||
required: ["userId", "text"],
|
required: ["userId", "text"],
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export default define(meta, paramDef, async (ps) => {
|
export default define(meta, paramDef, async (ps, me) => {
|
||||||
const user = await Users.findOneBy({ id: ps.userId });
|
const user = await Users.findOneBy({ id: ps.userId });
|
||||||
|
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
|
|
|
@ -10,7 +10,7 @@ const nonExistingLanguagesCache = new Set<string>();
|
||||||
export const loadLanguage = (lang: string) =>
|
export const loadLanguage = (lang: string) =>
|
||||||
new Promise<void>((resolve, reject) => {
|
new Promise<void>((resolve, reject) => {
|
||||||
// for now
|
// for now
|
||||||
if (!defaultStore.state.useEmojiCdn) return reject();
|
if (!defaultStore.state.useEmojiCdn) return resolve();
|
||||||
// cached non-existing language
|
// cached non-existing language
|
||||||
if (nonExistingLanguagesCache.has(lang)) return reject();
|
if (nonExistingLanguagesCache.has(lang)) return reject();
|
||||||
// load language with autoloader
|
// load language with autoloader
|
||||||
|
|
Loading…
Reference in a new issue