core: support oauth bind/unbind account (#971)

Co-authored-by: panda <panda_dtdyy@outlook.com>
This commit is contained in:
undefinedandpanda authored and GitHub committed 2025-04-01 10:55:21 +01:00
1 parent 1a8232899c
commit 536c697f4b
16 files changed
+393 -141

No files matched your search

+4 -4
View File
@@ -3,7 +3,7 @@ import { Logger } from '@hydrooj/utils';
import { Context, Service } from '../context';
import * as system from '../model/system';
export type MigrationScript = null | (() => Promise<boolean | void>);
export type MigrationScript = null | ((ctx: Context) => Promise<boolean | void>);
const logger = new Logger('migration');
declare module '../context' {
@@ -39,7 +39,7 @@ export default class MigrationService extends Service {
const isFresh = !dbVer;
const expected = scripts.length;
if (isFresh) {
await scripts[0]?.();
await scripts[0]?.(this.ctx);
await system.set(name, expected);
continue;
}
@@ -53,11 +53,11 @@ export default class MigrationService extends Service {
if ('dontWait' in func) {
logger.info('[Background Task]');
// For those scripts we don't really care if they fail
func().then(() => {
func(this.ctx).then(() => {
logger.info('Background Task Completed [%s]: from %d to %d', channel, func.dontWait, expected);
}).catch(logger.error);
} else {
const result = await func();
const result = await func(this.ctx);
if (!result) break;
}
dbVer++;
+1
View File
@@ -264,6 +264,7 @@ export async function apply(ctx: Context) {
id: key,
icon: global.Hydro.module.oauth[key].icon,
text: global.Hydro.module.oauth[key].text,
name: global.Hydro.module.oauth[key].name,
}));
if (!h.noCheckPermView && !h.user.hasPriv(PRIV.PRIV_VIEW_ALL_DOMAIN)) h.checkPerm(PERM.PERM_VIEW);
if (h.context.pendingError) throw h.context.pendingError;