forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(route): fanbox * fix * Update lib/routes/fanbox/index.ts Co-authored-by: Tony <[email protected]> * replace `got` with `ofetch` * Update lib/routes/fanbox/utils.ts Co-authored-by: Tony <[email protected]> ---------
- Loading branch information
1 parent
4aebe20
commit b3f0276
Showing
9 changed files
with
502 additions
and
288 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import InvalidParameterError from '@/errors/types/invalid-parameter'; | ||
import type { Data, Route } from '@/types'; | ||
import { isValidHost } from '@/utils/valid-host'; | ||
import type { Context } from 'hono'; | ||
import { getHeaders, parseItem } from './utils'; | ||
import type { PostListResponse, UserInfoResponse } from './types'; | ||
import ofetch from '@/utils/ofetch'; | ||
|
||
export const route: Route = { | ||
path: '/:creator', | ||
categories: ['social-media'], | ||
example: '/fanbox/official', | ||
parameters: { creator: 'fanbox user name' }, | ||
maintainers: ['KarasuShin'], | ||
name: 'Creator', | ||
handler, | ||
features: { | ||
requireConfig: [ | ||
{ | ||
name: 'FANBOX_SESSION_ID', | ||
description: 'Required for private posts. Can be found in browser DevTools -> Application -> Cookies -> https://www.fanbox.cc -> FANBOXSESSID', | ||
optional: true, | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
async function handler(ctx: Context): Promise<Data> { | ||
const creator = ctx.req.param('creator'); | ||
if (!isValidHost(creator)) { | ||
throw new InvalidParameterError('Invalid user name'); | ||
} | ||
|
||
let title = `Fanbox - ${creator}`; | ||
|
||
let description: string | undefined; | ||
|
||
let image: string | undefined; | ||
|
||
try { | ||
const userApi = `https://api.fanbox.cc/creator.get?creatorId=${creator}`; | ||
const userInfoResponse = (await ofetch(userApi, { | ||
headers: getHeaders(), | ||
})) as UserInfoResponse; | ||
title = `Fanbox - ${userInfoResponse.body.user.name}`; | ||
description = userInfoResponse.body.description; | ||
image = userInfoResponse.body.user.iconUrl; | ||
} catch { | ||
// ignore | ||
} | ||
|
||
const postListResponse = (await ofetch(`https://api.fanbox.cc/post.listCreator?creatorId=${creator}&limit=20`, { headers: getHeaders() })) as PostListResponse; | ||
const items = await Promise.all(postListResponse.body.items.map((i) => parseItem(i))); | ||
|
||
return { | ||
title, | ||
link: `https://${creator}.fanbox.cc`, | ||
description, | ||
image, | ||
item: items, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import type { Namespace } from '@/types'; | ||
|
||
export const namespace: Namespace = { | ||
name: 'fanbox', | ||
url: 'https://www.fanbox.cc', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<a href={{postUrl}}> | ||
<h1>{{title}}</h1> | ||
<span style="margin-right:1.6em">{{user.name}}</span> | ||
<br /> | ||
<br /> | ||
<span>{{excerpt}}</span> | ||
</a> |
Oops, something went wrong.