mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
refactor: 🚨 Remove unnecessary async keywords
This commit is contained in:
parent
132bec4d5b
commit
b1d8595a7c
|
|
@ -81,7 +81,7 @@ export default apiRoute((app) =>
|
||||||
);
|
);
|
||||||
|
|
||||||
return context.json(
|
return context.json(
|
||||||
await Promise.all(favourites.map(async (note) => note.toApi(user))),
|
await Promise.all(favourites.map((note) => note.toApi(user))),
|
||||||
200,
|
200,
|
||||||
{
|
{
|
||||||
Link: link,
|
Link: link,
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ const route = createRoute({
|
||||||
});
|
});
|
||||||
|
|
||||||
export default apiRoute((app) =>
|
export default apiRoute((app) =>
|
||||||
app.openapi(route, async (context) => {
|
app.openapi(route, (context) => {
|
||||||
return context.json(
|
return context.json(
|
||||||
config.signups.rules.map((rule, index) => ({
|
config.signups.rules.map((rule, index) => ({
|
||||||
id: String(index),
|
id: String(index),
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ export default apiRoute((app) =>
|
||||||
);
|
);
|
||||||
|
|
||||||
return context.json(
|
return context.json(
|
||||||
await Promise.all(objects.map(async (note) => note.toApi(user))),
|
await Promise.all(objects.map((note) => note.toApi(user))),
|
||||||
200,
|
200,
|
||||||
{
|
{
|
||||||
Link: link,
|
Link: link,
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@ export default apiRoute((app) =>
|
||||||
);
|
);
|
||||||
|
|
||||||
return context.json(
|
return context.json(
|
||||||
await Promise.all(objects.map(async (note) => note.toApi(user))),
|
await Promise.all(objects.map((note) => note.toApi(user))),
|
||||||
200,
|
200,
|
||||||
{
|
{
|
||||||
Link: link,
|
Link: link,
|
||||||
|
|
|
||||||
|
|
@ -11,30 +11,29 @@ export class BlurhashPreprocessor implements MediaPreprocessor {
|
||||||
const metadata = await sharp(arrayBuffer).metadata();
|
const metadata = await sharp(arrayBuffer).metadata();
|
||||||
|
|
||||||
const blurhash = await new Promise<string | null>((resolve) => {
|
const blurhash = await new Promise<string | null>((resolve) => {
|
||||||
(async () =>
|
sharp(arrayBuffer)
|
||||||
sharp(arrayBuffer)
|
.raw()
|
||||||
.raw()
|
.ensureAlpha()
|
||||||
.ensureAlpha()
|
.toBuffer((err, buffer) => {
|
||||||
.toBuffer((err, buffer) => {
|
if (err) {
|
||||||
if (err) {
|
resolve(null);
|
||||||
resolve(null);
|
return;
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
resolve(
|
resolve(
|
||||||
encode(
|
encode(
|
||||||
new Uint8ClampedArray(buffer),
|
new Uint8ClampedArray(buffer),
|
||||||
metadata?.width ?? 0,
|
metadata?.width ?? 0,
|
||||||
metadata?.height ?? 0,
|
metadata?.height ?? 0,
|
||||||
4,
|
4,
|
||||||
4,
|
4,
|
||||||
) as string,
|
) as string,
|
||||||
);
|
);
|
||||||
} catch {
|
} catch {
|
||||||
resolve(null);
|
resolve(null);
|
||||||
}
|
}
|
||||||
}))();
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return { file, blurhash };
|
return { file, blurhash };
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ describe("PluginLoader", () => {
|
||||||
test("parseManifestFile should parse JSON manifest", async () => {
|
test("parseManifestFile should parse JSON manifest", async () => {
|
||||||
const manifestContent = { name: "test-plugin" };
|
const manifestContent = { name: "test-plugin" };
|
||||||
Bun.file = jest.fn().mockReturnValue({
|
Bun.file = jest.fn().mockReturnValue({
|
||||||
text: async () => JSON.stringify(manifestContent),
|
text: () => Promise.resolve(JSON.stringify(manifestContent)),
|
||||||
});
|
});
|
||||||
|
|
||||||
// biome-ignore lint/complexity/useLiteralKeys: Private method
|
// biome-ignore lint/complexity/useLiteralKeys: Private method
|
||||||
|
|
@ -111,7 +111,7 @@ describe("PluginLoader", () => {
|
||||||
};
|
};
|
||||||
mockReaddir.mockResolvedValue(["manifest.json"]);
|
mockReaddir.mockResolvedValue(["manifest.json"]);
|
||||||
Bun.file = jest.fn().mockReturnValue({
|
Bun.file = jest.fn().mockReturnValue({
|
||||||
text: async () => JSON.stringify(manifestContent),
|
text: () => Promise.resolve(JSON.stringify(manifestContent)),
|
||||||
});
|
});
|
||||||
manifestSchema.safeParseAsync = jest.fn().mockResolvedValue({
|
manifestSchema.safeParseAsync = jest.fn().mockResolvedValue({
|
||||||
success: true,
|
success: true,
|
||||||
|
|
@ -141,7 +141,7 @@ describe("PluginLoader", () => {
|
||||||
};
|
};
|
||||||
mockReaddir.mockResolvedValue(["manifest.json"]);
|
mockReaddir.mockResolvedValue(["manifest.json"]);
|
||||||
Bun.file = jest.fn().mockReturnValue({
|
Bun.file = jest.fn().mockReturnValue({
|
||||||
text: async () => JSON.stringify(manifestContent),
|
text: () => Promise.resolve(JSON.stringify(manifestContent)),
|
||||||
});
|
});
|
||||||
manifestSchema.safeParseAsync = jest.fn().mockResolvedValue({
|
manifestSchema.safeParseAsync = jest.fn().mockResolvedValue({
|
||||||
success: false,
|
success: false,
|
||||||
|
|
@ -188,7 +188,7 @@ describe("PluginLoader", () => {
|
||||||
])
|
])
|
||||||
.mockResolvedValue(["manifest.json", "index.ts"]);
|
.mockResolvedValue(["manifest.json", "index.ts"]);
|
||||||
Bun.file = jest.fn().mockReturnValue({
|
Bun.file = jest.fn().mockReturnValue({
|
||||||
text: async () => JSON.stringify(manifestContent),
|
text: () => Promise.resolve(JSON.stringify(manifestContent)),
|
||||||
});
|
});
|
||||||
manifestSchema.safeParseAsync = jest.fn().mockResolvedValue({
|
manifestSchema.safeParseAsync = jest.fn().mockResolvedValue({
|
||||||
success: true,
|
success: true,
|
||||||
|
|
|
||||||
|
|
@ -149,7 +149,7 @@ export class SonicSearchManager {
|
||||||
* @param n Batch number
|
* @param n Batch number
|
||||||
* @param batchSize Size of the batch
|
* @param batchSize Size of the batch
|
||||||
*/
|
*/
|
||||||
private async getNthDatabaseAccountBatch(
|
private getNthDatabaseAccountBatch(
|
||||||
n: number,
|
n: number,
|
||||||
batchSize = 1000,
|
batchSize = 1000,
|
||||||
): Promise<Record<string, string | Date>[]> {
|
): Promise<Record<string, string | Date>[]> {
|
||||||
|
|
@ -172,7 +172,7 @@ export class SonicSearchManager {
|
||||||
* @param n Batch number
|
* @param n Batch number
|
||||||
* @param batchSize Size of the batch
|
* @param batchSize Size of the batch
|
||||||
*/
|
*/
|
||||||
private async getNthDatabaseStatusBatch(
|
private getNthDatabaseStatusBatch(
|
||||||
n: number,
|
n: number,
|
||||||
batchSize = 1000,
|
batchSize = 1000,
|
||||||
): Promise<Record<string, string | Date>[]> {
|
): Promise<Record<string, string | Date>[]> {
|
||||||
|
|
|
||||||
|
|
@ -172,10 +172,10 @@ export class Emoji extends BaseInterface<typeof Emojis, EmojiWithInstance> {
|
||||||
* @param text The text to parse
|
* @param text The text to parse
|
||||||
* @returns An array of emojis
|
* @returns An array of emojis
|
||||||
*/
|
*/
|
||||||
public static async parseFromText(text: string): Promise<Emoji[]> {
|
public static parseFromText(text: string): Promise<Emoji[]> {
|
||||||
const matches = text.match(emojiValidatorWithColons);
|
const matches = text.match(emojiValidatorWithColons);
|
||||||
if (!matches || matches.length === 0) {
|
if (!matches || matches.length === 0) {
|
||||||
return [];
|
return Promise.resolve([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Emoji.manyFromSql(
|
return Emoji.manyFromSql(
|
||||||
|
|
|
||||||
|
|
@ -395,8 +395,8 @@ export const setContextFormDataToObject = (
|
||||||
setTo: object,
|
setTo: object,
|
||||||
): Context => {
|
): Context => {
|
||||||
context.req.bodyCache.json = setTo;
|
context.req.bodyCache.json = setTo;
|
||||||
context.req.parseBody = async () => context.req.bodyCache.json;
|
context.req.parseBody = () => Promise.resolve(context.req.bodyCache.json);
|
||||||
context.req.json = async () => context.req.bodyCache.json;
|
context.req.json = () => Promise.resolve(context.req.bodyCache.json);
|
||||||
|
|
||||||
return context;
|
return context;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -47,11 +47,11 @@ export const urlToContentFormat = (url?: string): ContentFormat | null => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const mimeLookup = async (url: string) => {
|
export const mimeLookup = (url: string): Promise<string> => {
|
||||||
const naiveLookup = lookup(url.replace(new URL(url).search, ""));
|
const naiveLookup = lookup(url.replace(new URL(url).search, ""));
|
||||||
|
|
||||||
if (naiveLookup) {
|
if (naiveLookup) {
|
||||||
return naiveLookup;
|
return Promise.resolve(naiveLookup);
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchLookup = fetch(url, {
|
const fetchLookup = fetch(url, {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue