From d6865d86e530cda9b4075f7f37654da4e48855cb Mon Sep 17 00:00:00 2001 From: undefined Date: Tue, 29 Apr 2025 22:12:15 +0800 Subject: [PATCH] core: fix api projection --- framework/framework/api.ts | 2 +- packages/hydrooj/src/upgrade.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/framework/api.ts b/framework/framework/api.ts index 20cb73ede..c4910092b 100644 --- a/framework/framework/api.ts +++ b/framework/framework/api.ts @@ -126,7 +126,7 @@ export class ApiService extends Service { await emitHook?.(`api/before/${callOrName}`, args); } const result = await func(context, args as any); - return project ? projection(result, project) : result; + return (project && typeof result === 'object' && result !== null) ? projection(result, project) : result; } } diff --git a/packages/hydrooj/src/upgrade.ts b/packages/hydrooj/src/upgrade.ts index ee2c28489..6317423c2 100644 --- a/packages/hydrooj/src/upgrade.ts +++ b/packages/hydrooj/src/upgrade.ts @@ -609,7 +609,7 @@ export const coreScripts: MigrationScript[] = [ const docs = await c.oauth.coll.find({ id: { $type: 'number' as any } }).toArray(); const op = c.oauth.coll.initializeUnorderedBulkOp(); for (const doc of docs) { - op.find({ _id: doc._id }).updateOne({ id: doc.id.toString() }); + op.find({ _id: doc._id }).updateOne({ $set: { id: doc.id.toString() } }); } if (op.length) await op.execute(); });