mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 10:31:47 +00:00
fix(api-server): fix #3572
This commit is contained in:
@ -19,7 +19,7 @@ export const backend = createBackend<BackendType, APIServerConfig>({
|
||||
async start(ctx) {
|
||||
const config = await ctx.getConfig();
|
||||
|
||||
await this.init(ctx);
|
||||
this.init(ctx);
|
||||
registerCallback((songInfo) => {
|
||||
this.songInfo = songInfo;
|
||||
});
|
||||
@ -60,8 +60,7 @@ export const backend = createBackend<BackendType, APIServerConfig>({
|
||||
},
|
||||
|
||||
// Custom
|
||||
async init(ctx) {
|
||||
const config = await ctx.getConfig();
|
||||
init(backendCtx) {
|
||||
this.app = new Hono();
|
||||
|
||||
this.app.use('*', cors());
|
||||
@ -74,6 +73,8 @@ export const backend = createBackend<BackendType, APIServerConfig>({
|
||||
|
||||
// middlewares
|
||||
this.app.use('/api/*', async (ctx, next) => {
|
||||
const config = await backendCtx.getConfig();
|
||||
|
||||
if (config.authStrategy !== AuthStrategy.NONE) {
|
||||
return await jwt({
|
||||
secret: config.secret,
|
||||
@ -83,6 +84,7 @@ export const backend = createBackend<BackendType, APIServerConfig>({
|
||||
});
|
||||
this.app.use('/api/*', async (ctx, next) => {
|
||||
const result = await JWTPayloadSchema.spa(await ctx.get('jwtPayload'));
|
||||
const config = await backendCtx.getConfig();
|
||||
|
||||
const isAuthorized =
|
||||
config.authStrategy === AuthStrategy.NONE ||
|
||||
@ -98,12 +100,12 @@ export const backend = createBackend<BackendType, APIServerConfig>({
|
||||
// routes
|
||||
registerControl(
|
||||
this.app,
|
||||
ctx,
|
||||
backendCtx,
|
||||
() => this.songInfo,
|
||||
() => this.currentRepeatMode,
|
||||
() => this.volume,
|
||||
);
|
||||
registerAuth(this.app, ctx);
|
||||
registerAuth(this.app, backendCtx);
|
||||
|
||||
// swagger
|
||||
this.app.openAPIRegistry.registerComponent(
|
||||
|
||||
@ -15,7 +15,7 @@ export type BackendType = {
|
||||
currentRepeatMode?: RepeatMode;
|
||||
volume?: number;
|
||||
|
||||
init: (ctx: BackendContext<APIServerConfig>) => Promise<void>;
|
||||
init: (ctx: BackendContext<APIServerConfig>) => void;
|
||||
run: (hostname: string, port: number) => void;
|
||||
end: () => void;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user