refactor: 🚨 Remove unnecessary async keywords

This commit is contained in:
Jesse Wierzbinski 2024-10-03 11:43:16 +02:00
parent 132bec4d5b
commit b1d8595a7c
No known key found for this signature in database
10 changed files with 38 additions and 39 deletions

View file

@ -11,30 +11,29 @@ export class BlurhashPreprocessor implements MediaPreprocessor {
const metadata = await sharp(arrayBuffer).metadata();
const blurhash = await new Promise<string | null>((resolve) => {
(async () =>
sharp(arrayBuffer)
.raw()
.ensureAlpha()
.toBuffer((err, buffer) => {
if (err) {
resolve(null);
return;
}
sharp(arrayBuffer)
.raw()
.ensureAlpha()
.toBuffer((err, buffer) => {
if (err) {
resolve(null);
return;
}
try {
resolve(
encode(
new Uint8ClampedArray(buffer),
metadata?.width ?? 0,
metadata?.height ?? 0,
4,
4,
) as string,
);
} catch {
resolve(null);
}
}))();
try {
resolve(
encode(
new Uint8ClampedArray(buffer),
metadata?.width ?? 0,
metadata?.height ?? 0,
4,
4,
) as string,
);
} catch {
resolve(null);
}
});
});
return { file, blurhash };

View file

@ -80,7 +80,7 @@ describe("PluginLoader", () => {
test("parseManifestFile should parse JSON manifest", async () => {
const manifestContent = { name: "test-plugin" };
Bun.file = jest.fn().mockReturnValue({
text: async () => JSON.stringify(manifestContent),
text: () => Promise.resolve(JSON.stringify(manifestContent)),
});
// biome-ignore lint/complexity/useLiteralKeys: Private method
@ -111,7 +111,7 @@ describe("PluginLoader", () => {
};
mockReaddir.mockResolvedValue(["manifest.json"]);
Bun.file = jest.fn().mockReturnValue({
text: async () => JSON.stringify(manifestContent),
text: () => Promise.resolve(JSON.stringify(manifestContent)),
});
manifestSchema.safeParseAsync = jest.fn().mockResolvedValue({
success: true,
@ -141,7 +141,7 @@ describe("PluginLoader", () => {
};
mockReaddir.mockResolvedValue(["manifest.json"]);
Bun.file = jest.fn().mockReturnValue({
text: async () => JSON.stringify(manifestContent),
text: () => Promise.resolve(JSON.stringify(manifestContent)),
});
manifestSchema.safeParseAsync = jest.fn().mockResolvedValue({
success: false,
@ -188,7 +188,7 @@ describe("PluginLoader", () => {
])
.mockResolvedValue(["manifest.json", "index.ts"]);
Bun.file = jest.fn().mockReturnValue({
text: async () => JSON.stringify(manifestContent),
text: () => Promise.resolve(JSON.stringify(manifestContent)),
});
manifestSchema.safeParseAsync = jest.fn().mockResolvedValue({
success: true,

View file

@ -149,7 +149,7 @@ export class SonicSearchManager {
* @param n Batch number
* @param batchSize Size of the batch
*/
private async getNthDatabaseAccountBatch(
private getNthDatabaseAccountBatch(
n: number,
batchSize = 1000,
): Promise<Record<string, string | Date>[]> {
@ -172,7 +172,7 @@ export class SonicSearchManager {
* @param n Batch number
* @param batchSize Size of the batch
*/
private async getNthDatabaseStatusBatch(
private getNthDatabaseStatusBatch(
n: number,
batchSize = 1000,
): Promise<Record<string, string | Date>[]> {