Skip to content

Commit

Permalink
fix(route/douban): douban nil topic error
Browse files Browse the repository at this point in the history
  • Loading branch information
pseudoyu committed Oct 19, 2024
1 parent 7ad4465 commit adca4dd
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/routes/douban/other/topic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import got from '@/utils/got';

export const route: Route = {
path: '/topic/:id/:sort?',
categories: ['social-media'],
categories: ['social-media', 'popular'],
example: '/douban/topic/48823',
parameters: { id: '话题id', sort: '排序方式,hot或new,默认为new' },
features: {
Expand All @@ -16,7 +16,7 @@ export const route: Route = {
supportScihub: false,
},
name: '话题',
maintainers: ['LogicJake'],
maintainers: ['LogicJake', 'pseudoyu'],
handler,
};

Expand All @@ -36,8 +36,14 @@ async function handler(ctx) {
});

const data = response.data.items;
const title = data[0].topic.name;
const description = data[0].topic.introduction;

let title = id;
let description = '';

if (data[0].topic !== null) {
title = data[0].topic.name;
description = data[0].topic.introduction;
}

const out = await Promise.all(
data.map(async (item) => {
Expand Down

0 comments on commit adca4dd

Please sign in to comment.