@@ -2,11 +2,13 @@ import { load } from 'cheerio';
22
33import type { Route } from '@/types' ;
44import { ViewType } from '@/types' ;
5- import got from '@/utils/got ' ;
5+ import ofetch from '@/utils/ofetch ' ;
66import { parseDate } from '@/utils/parse-date' ;
77
8+ import { renderDescription } from './templates/description' ;
9+
810export const route : Route = {
9- path : '/user/video/:uid' ,
11+ path : '/user/video/:uid/:embed? ' ,
1012 radar : [
1113 {
1214 source : [ 'www.acfun.cn/u/:id' ] ,
@@ -16,6 +18,7 @@ export const route: Route = {
1618 name : '用户投稿' ,
1719 parameters : {
1820 uid : '用户 UID' ,
21+ embed : '默认为开启内嵌视频, 任意值为关闭' ,
1922 } ,
2023 categories : [ 'anime' ] ,
2124 example : '/acfun/user/video/6102' ,
@@ -26,39 +29,37 @@ export const route: Route = {
2629
2730async function handler ( ctx ) {
2831 const uid = ctx . req . param ( 'uid' ) ;
29- const url = `https://www.acfun.cn/u/ ${ uid } ` ;
32+ const embed = ! ctx . req . param ( 'embed' ) ;
3033 const host = 'https://www.acfun.cn' ;
31- const response = await got ( url , {
32- headers : {
33- Referer : host ,
34- } ,
35- } ) ;
36- const data = response . data ;
34+ const link = `${ host } /u/${ uid } ` ;
35+ const response = await ofetch ( link ) ;
3736
38- const $ = load ( data ) ;
37+ const $ = load ( response ) ;
3938 const title = $ ( 'title' ) . text ( ) ;
4039 const description = $ ( '.signature .complete' ) . text ( ) ;
4140 const list = $ ( '#ac-space-video-list a' ) . toArray ( ) ;
42- const image = $ ( 'head style' )
41+ const image = $ ( 'head style:contains("user-photo") ' )
4342 . text ( )
44- . match ( / .u s e r - p h o t o { \n \s * b a c k g r o u n d : u r l \( ( .* ) \) 0 % 0 % \/ 1 0 0 % n o - r e p e a t ; / ) [ 1 ] ;
43+ . match ( / .u s e r - p h o t o { \n \s * b a c k g r o u n d : u r l \( ( .* ) \) 0 % 0 % \/ 1 0 0 % n o - r e p e a t ; / ) ?. [ 1 ] ;
4544
4645 return {
4746 title,
48- link : url ,
47+ link,
4948 description,
5049 image,
5150 item : list . map ( ( item ) => {
52- item = $ ( item ) ;
51+ const $ item = $ ( item ) ;
5352
54- const itemTitle = item . find ( 'p.title' ) . text ( ) ;
55- const itemImg = item . find ( 'figure img' ) . attr ( 'src' ) ;
56- const itemUrl = item . attr ( 'href' ) ;
57- const itemDate = item . find ( '.date' ) . text ( ) ;
53+ const itemTitle = $item . find ( 'p.title' ) . text ( ) ;
54+ const itemImg = $item . find ( 'figure img' ) . attr ( 'src' ) ;
55+ const itemUrl = $item . attr ( 'href' ) ! ;
56+ const itemDate = $item . find ( '.date' ) . text ( ) ;
57+ const wbInfo = JSON . parse ( ( $item . data ( 'wb-info' ) as string ) || '{}' ) ;
58+ const aid = wbInfo . atmid || wbInfo . mediaId || itemUrl . match ( / \/ v \/ ( a c \d + ) / ) ?. [ 1 ] ;
5859
5960 return {
6061 title : itemTitle ,
61- description : `< img src=" ${ itemImg . split ( '?' ) [ 0 ] } ">` ,
62+ description : renderDescription ( { embed , aid , img : itemImg ? .split ( '?' ) [ 0 ] } ) ,
6263 link : host + itemUrl ,
6364 pubDate : parseDate ( itemDate , 'YYYY/MM/DD' ) ,
6465 } ;
0 commit comments