koishi-plugin-kkk 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +57 -0
- package/LICENSE +674 -0
- package/README.md +98 -0
- package/assets/web/assets/CronEditor-CYgFpX-g.js +1 -0
- package/assets/web/assets/DesktopLayout-iI43ij11.js +1 -0
- package/assets/web/assets/MobileLayout-CziU8MCR.js +1 -0
- package/assets/web/assets/ThemeSwitch-DFohhwd9.js +1 -0
- package/assets/web/assets/index-BRROK0vh.js +47 -0
- package/assets/web/assets/index-Dj-StEiS.css +2 -0
- package/assets/web/assets/separator-CxcFlCzz.js +1 -0
- package/assets/web/favicon.svg +1 -0
- package/assets/web/icons.svg +24 -0
- package/assets/web/index.html +15 -0
- package/assets/webui.html +115 -0
- package/client/index.ts +63 -0
- package/config/default_config/app.yaml +64 -0
- package/config/default_config/bilibili.yaml +116 -0
- package/config/default_config/config.json +157 -0
- package/config/default_config/cookies.yaml +11 -0
- package/config/default_config/douyin.yaml +99 -0
- package/config/default_config/kuaishou.yaml +8 -0
- package/config/default_config/pushlist.yaml +37 -0
- package/config/default_config/request.yaml +22 -0
- package/config/default_config/upload.yaml +50 -0
- package/config/default_config/xiaohongshu.yaml +23 -0
- package/dist/index.js +1 -0
- package/lib/compat/axios.js +23 -0
- package/lib/compat/cron.js +77 -0
- package/lib/compat/esm.js +15 -0
- package/lib/compat/express.js +23 -0
- package/lib/compat/heroui.js +12 -0
- package/lib/compat/lodash.js +33 -0
- package/lib/compat/logger.js +118 -0
- package/lib/compat/node-karin.js +1053 -0
- package/lib/compat/phosphor-icons.js +27 -0
- package/lib/compat/qqcard.js +256 -0
- package/lib/compat/root.js +44 -0
- package/lib/compat/runtime.js +87 -0
- package/lib/compat/segment.js +167 -0
- package/lib/compat/sqlite3.js +117 -0
- package/lib/compat/start.js +7 -0
- package/lib/compat/syncConfig.js +65 -0
- package/lib/compat/template-react.js +30 -0
- package/lib/compat/text.js +65 -0
- package/lib/compat/yaml.js +13 -0
- package/lib/configBridge.js +91 -0
- package/lib/index.js +775 -0
- package/lib/karin/app.js +34 -0
- package/lib/karin/apps/__ready.js +9 -0
- package/lib/karin/apps/admin.js +136 -0
- package/lib/karin/apps/help.js +233 -0
- package/lib/karin/apps/push.js +291 -0
- package/lib/karin/apps/qrlogin.js +176 -0
- package/lib/karin/apps/statistics.js +209 -0
- package/lib/karin/apps/testPush.js +247 -0
- package/lib/karin/apps/tools.js +473 -0
- package/lib/karin/apps/update.js +252 -0
- package/lib/karin/index.js +37 -0
- package/lib/karin/module/db/bilibili.js +831 -0
- package/lib/karin/module/db/douyin.js +918 -0
- package/lib/karin/module/db/index.js +165 -0
- package/lib/karin/module/db/migration.js +199 -0
- package/lib/karin/module/db/statistics.js +559 -0
- package/lib/karin/module/index.js +94 -0
- package/lib/karin/module/server/constants/routes.js +48 -0
- package/lib/karin/module/server/controllers/bots.js +230 -0
- package/lib/karin/module/server/controllers/config.js +75 -0
- package/lib/karin/module/server/controllers/video.js +208 -0
- package/lib/karin/module/server/index.js +26 -0
- package/lib/karin/module/server/middlewares/auth.js +133 -0
- package/lib/karin/module/server/routes/amagi.js +57 -0
- package/lib/karin/module/server/routes/api.js +40 -0
- package/lib/karin/module/server/routes/index.js +97 -0
- package/lib/karin/module/server/routes/ssr.js +16 -0
- package/lib/karin/module/server/routes/static.js +43 -0
- package/lib/karin/module/utils/Base.js +403 -0
- package/lib/karin/module/utils/CardParser.js +487 -0
- package/lib/karin/module/utils/Common.js +418 -0
- package/lib/karin/module/utils/Config.js +434 -0
- package/lib/karin/module/utils/EmojiReaction.js +242 -0
- package/lib/karin/module/utils/ErrorHandler/handler.js +114 -0
- package/lib/karin/module/utils/ErrorHandler/index.js +55 -0
- package/lib/karin/module/utils/ErrorHandler/render.js +182 -0
- package/lib/karin/module/utils/ErrorHandler/sender.js +206 -0
- package/lib/karin/module/utils/ErrorHandler/strategy.js +41 -0
- package/lib/karin/module/utils/ErrorHandler/types.js +2 -0
- package/lib/karin/module/utils/ErrorHandler/utils.js +108 -0
- package/lib/karin/module/utils/FFmpeg.js +298 -0
- package/lib/karin/module/utils/ImageHelper.js +91 -0
- package/lib/karin/module/utils/ImageSlice.js +429 -0
- package/lib/karin/module/utils/MotionPhoto.js +250 -0
- package/lib/karin/module/utils/Network/Downloader.js +413 -0
- package/lib/karin/module/utils/Network/ImageDownloader.js +250 -0
- package/lib/karin/module/utils/Network/Network.js +332 -0
- package/lib/karin/module/utils/Network/ThrottleStream.js +71 -0
- package/lib/karin/module/utils/Network/constants.js +129 -0
- package/lib/karin/module/utils/Network/helpers.js +174 -0
- package/lib/karin/module/utils/Network/index.js +34 -0
- package/lib/karin/module/utils/Network/types.js +12 -0
- package/lib/karin/module/utils/Networks.js +17 -0
- package/lib/karin/module/utils/ParseLock.js +34 -0
- package/lib/karin/module/utils/ParseOverride.js +88 -0
- package/lib/karin/module/utils/QqCardResolve.js +114 -0
- package/lib/karin/module/utils/QqPanel.js +879 -0
- package/lib/karin/module/utils/Render/coverTheme.js +256 -0
- package/lib/karin/module/utils/Render/index.js +582 -0
- package/lib/karin/module/utils/amagiClient.js +338 -0
- package/lib/karin/module/utils/avatar.js +201 -0
- package/lib/karin/module/utils/bot.js +141 -0
- package/lib/karin/module/utils/build-metadata.js +50 -0
- package/lib/karin/module/utils/changelog.js +166 -0
- package/lib/karin/module/utils/index.js +26 -0
- package/lib/karin/module/utils/loginSession.js +259 -0
- package/lib/karin/module/utils/parseTip.js +93 -0
- package/lib/karin/module/utils/runtime-report.js +140 -0
- package/lib/karin/module/utils/semver.js +72 -0
- package/lib/karin/module/utils/statisticsAggregate.js +415 -0
- package/lib/karin/platform/bilibili/bilibili.js +1805 -0
- package/lib/karin/platform/bilibili/comments.js +294 -0
- package/lib/karin/platform/bilibili/danmaku.js +555 -0
- package/lib/karin/platform/bilibili/dynamic-text.js +827 -0
- package/lib/karin/platform/bilibili/genParams.js +37 -0
- package/lib/karin/platform/bilibili/getID.js +159 -0
- package/lib/karin/platform/bilibili/index.js +24 -0
- package/lib/karin/platform/bilibili/live-status.js +40 -0
- package/lib/karin/platform/bilibili/login.js +132 -0
- package/lib/karin/platform/bilibili/push.js +1397 -0
- package/lib/karin/platform/bilibili/riskControl.js +133 -0
- package/lib/karin/platform/bilibili/search.js +299 -0
- package/lib/karin/platform/common/danmaku-types.js +12 -0
- package/lib/karin/platform/douyin/comments.js +310 -0
- package/lib/karin/platform/douyin/danmaku.js +893 -0
- package/lib/karin/platform/douyin/douyin.js +1145 -0
- package/lib/karin/platform/douyin/getID.js +94 -0
- package/lib/karin/platform/douyin/index.js +24 -0
- package/lib/karin/platform/douyin/login.js +230 -0
- package/lib/karin/platform/douyin/push/favorite.js +75 -0
- package/lib/karin/platform/douyin/push/index.js +21 -0
- package/lib/karin/platform/douyin/push/live.js +69 -0
- package/lib/karin/platform/douyin/push/post.js +60 -0
- package/lib/karin/platform/douyin/push/recommend.js +74 -0
- package/lib/karin/platform/douyin/push/render.js +621 -0
- package/lib/karin/platform/douyin/push/types.js +2 -0
- package/lib/karin/platform/douyin/push.js +1128 -0
- package/lib/karin/platform/douyin/types.js +13 -0
- package/lib/karin/platform/douyin/videoQuality.js +222 -0
- package/lib/karin/platform/douyin/workType.js +182 -0
- package/lib/karin/platform/index.js +20 -0
- package/lib/karin/platform/kuaishou/comments.js +91 -0
- package/lib/karin/platform/kuaishou/getID.js +43 -0
- package/lib/karin/platform/kuaishou/getdata.js +41 -0
- package/lib/karin/platform/kuaishou/index.js +20 -0
- package/lib/karin/platform/kuaishou/kuaishou.js +122 -0
- package/lib/karin/platform/xiaohongshu/comments.js +162 -0
- package/lib/karin/platform/xiaohongshu/getID.js +129 -0
- package/lib/karin/platform/xiaohongshu/index.js +18 -0
- package/lib/karin/platform/xiaohongshu/xiaohongshu.js +643 -0
- package/lib/karin/root.js +73 -0
- package/lib/karin/setup.js +99 -0
- package/lib/karin/types/config/amagi.js +2 -0
- package/lib/karin/types/config/app.js +2 -0
- package/lib/karin/types/config/bilibili.js +2 -0
- package/lib/karin/types/config/cookies.js +2 -0
- package/lib/karin/types/config/douyin.js +2 -0
- package/lib/karin/types/config/index.js +2 -0
- package/lib/karin/types/config/kuaishou.js +2 -0
- package/lib/karin/types/config/pushlist.js +2 -0
- package/lib/karin/types/config/request.js +2 -0
- package/lib/karin/types/config/upload.js +2 -0
- package/lib/karin/types/config/xiaohongshu.js +2 -0
- package/lib/karin/types/datatypes.js +2 -0
- package/lib/karin/types/index.js +18 -0
- package/lib/karin/types/netrorks/NetworksConfigType.js +2 -0
- package/lib/karin/types/netrorks/index.js +17 -0
- package/lib/karin/web.config.js +49 -0
- package/lib/ktr/registry.js +82 -0
- package/lib/ktr/template/_preview/components/PreviewInfoCard.js +10 -0
- package/lib/ktr/template/_preview/components/PreviewLayout.js +10 -0
- package/lib/ktr/template/_preview/components/PreviewVideoCard.js +8 -0
- package/lib/ktr/template/_preview/render.js +142 -0
- package/lib/ktr/template/_preview/types.js +2 -0
- package/lib/ktr/template/_preview/utils/status.js +31 -0
- package/lib/ktr/template/_preview/utils/time.js +12 -0
- package/lib/ktr/template/bilibili/bangumi/components/bangumi.js +127 -0
- package/lib/ktr/template/bilibili/bangumi/components/types.js +2 -0
- package/lib/ktr/template/bilibili/bangumi/index.js +12 -0
- package/lib/ktr/template/bilibili/comment/components/Comment.js +193 -0
- package/lib/ktr/template/bilibili/comment/components/types.js +2 -0
- package/lib/ktr/template/bilibili/comment/index.js +10 -0
- package/lib/ktr/template/bilibili/components/Icons.js +66 -0
- package/lib/ktr/template/bilibili/components/shared.js +93 -0
- package/lib/ktr/template/bilibili/components/types.js +2 -0
- package/lib/ktr/template/bilibili/dynamic/DYNAMIC_TYPE_ARTICLE/components/DYNAMIC_TYPE_ARTICLE.js +66 -0
- package/lib/ktr/template/bilibili/dynamic/DYNAMIC_TYPE_ARTICLE/components/types.js +2 -0
- package/lib/ktr/template/bilibili/dynamic/DYNAMIC_TYPE_ARTICLE/index.js +10 -0
- package/lib/ktr/template/bilibili/dynamic/DYNAMIC_TYPE_AV/components/DYNAMIC_TYPE_AV.js +87 -0
- package/lib/ktr/template/bilibili/dynamic/DYNAMIC_TYPE_AV/components/types.js +2 -0
- package/lib/ktr/template/bilibili/dynamic/DYNAMIC_TYPE_AV/index.js +10 -0
- package/lib/ktr/template/bilibili/dynamic/DYNAMIC_TYPE_DRAW/components/DYNAMIC_TYPE_DRAW.js +93 -0
- package/lib/ktr/template/bilibili/dynamic/DYNAMIC_TYPE_DRAW/components/types.js +2 -0
- package/lib/ktr/template/bilibili/dynamic/DYNAMIC_TYPE_DRAW/index.js +10 -0
- package/lib/ktr/template/bilibili/dynamic/DYNAMIC_TYPE_FORWARD/components/DYNAMIC_TYPE_FORWARD.js +132 -0
- package/lib/ktr/template/bilibili/dynamic/DYNAMIC_TYPE_FORWARD/components/types.js +2 -0
- package/lib/ktr/template/bilibili/dynamic/DYNAMIC_TYPE_FORWARD/index.js +10 -0
- package/lib/ktr/template/bilibili/dynamic/DYNAMIC_TYPE_LIVE_RCMD/components/DYNAMIC_TYPE_LIVE_RCMD.js +84 -0
- package/lib/ktr/template/bilibili/dynamic/DYNAMIC_TYPE_LIVE_RCMD/components/types.js +2 -0
- package/lib/ktr/template/bilibili/dynamic/DYNAMIC_TYPE_LIVE_RCMD/index.js +10 -0
- package/lib/ktr/template/bilibili/dynamic/DYNAMIC_TYPE_WORD/components/DYNAMIC_TYPE_WORD.js +38 -0
- package/lib/ktr/template/bilibili/dynamic/DYNAMIC_TYPE_WORD/components/types.js +2 -0
- package/lib/ktr/template/bilibili/dynamic/DYNAMIC_TYPE_WORD/index.js +10 -0
- package/lib/ktr/template/bilibili/dynamic/components/AdditionalCard.js +59 -0
- package/lib/ktr/template/bilibili/dynamic/components/CommonComponents.js +30 -0
- package/lib/ktr/template/bilibili/dynamic/types.js +2 -0
- package/lib/ktr/template/bilibili/qrcodeImg/components/qrcodeImg.js +48 -0
- package/lib/ktr/template/bilibili/qrcodeImg/components/types.js +3 -0
- package/lib/ktr/template/bilibili/qrcodeImg/index.js +10 -0
- package/lib/ktr/template/bilibili/userlist/components/UserList.js +53 -0
- package/lib/ktr/template/bilibili/userlist/components/types.js +3 -0
- package/lib/ktr/template/bilibili/userlist/index.js +13 -0
- package/lib/ktr/template/bilibili/videoInfo/components/types.js +2 -0
- package/lib/ktr/template/bilibili/videoInfo/components/videoInfo.js +62 -0
- package/lib/ktr/template/bilibili/videoInfo/index.js +10 -0
- package/lib/ktr/template/components/AmbientCover.js +36 -0
- package/lib/ktr/template/components/DefaultLayout.js +33 -0
- package/lib/ktr/template/components/GlowImage.js +276 -0
- package/lib/ktr/template/components/QRCodeWithAvatar.js +34 -0
- package/lib/ktr/template/components/RolldownLogo.js +6 -0
- package/lib/ktr/template/components/ViteLogo.js +6 -0
- package/lib/ktr/template/components/iconRegistry.js +173 -0
- package/lib/ktr/template/douyin/article-work/components/ArticleWork.js +99 -0
- package/lib/ktr/template/douyin/article-work/components/types.js +3 -0
- package/lib/ktr/template/douyin/article-work/index.js +10 -0
- package/lib/ktr/template/douyin/comment/components/Comment.js +189 -0
- package/lib/ktr/template/douyin/comment/components/types.js +2 -0
- package/lib/ktr/template/douyin/comment/index.js +10 -0
- package/lib/ktr/template/douyin/components/Icons.js +29 -0
- package/lib/ktr/template/douyin/components/types.js +3 -0
- package/lib/ktr/template/douyin/dynamic/components/Dynamic.js +90 -0
- package/lib/ktr/template/douyin/dynamic/components/types.js +3 -0
- package/lib/ktr/template/douyin/dynamic/index.js +10 -0
- package/lib/ktr/template/douyin/favorite-list/components/FavoriteList.js +30 -0
- package/lib/ktr/template/douyin/favorite-list/components/types.js +3 -0
- package/lib/ktr/template/douyin/favorite-list/index.js +10 -0
- package/lib/ktr/template/douyin/image-work/components/ImageWork.js +136 -0
- package/lib/ktr/template/douyin/image-work/components/types.js +2 -0
- package/lib/ktr/template/douyin/image-work/index.js +10 -0
- package/lib/ktr/template/douyin/live/components/Live.js +51 -0
- package/lib/ktr/template/douyin/live/components/types.js +3 -0
- package/lib/ktr/template/douyin/live/index.js +10 -0
- package/lib/ktr/template/douyin/musicinfo/components/MusicInfo.js +60 -0
- package/lib/ktr/template/douyin/musicinfo/components/types.js +3 -0
- package/lib/ktr/template/douyin/musicinfo/index.js +10 -0
- package/lib/ktr/template/douyin/qrcodeImg/components/qrcodeImg.js +39 -0
- package/lib/ktr/template/douyin/qrcodeImg/components/types.js +3 -0
- package/lib/ktr/template/douyin/qrcodeImg/index.js +9 -0
- package/lib/ktr/template/douyin/recommend-list/components/RecommendList.js +30 -0
- package/lib/ktr/template/douyin/recommend-list/components/types.js +3 -0
- package/lib/ktr/template/douyin/recommend-list/index.js +10 -0
- package/lib/ktr/template/douyin/user_profile/components/UserVideoList.js +54 -0
- package/lib/ktr/template/douyin/user_profile/components/types.js +3 -0
- package/lib/ktr/template/douyin/user_profile/index.js +9 -0
- package/lib/ktr/template/douyin/userlist/components/UserList.js +50 -0
- package/lib/ktr/template/douyin/userlist/components/types.js +3 -0
- package/lib/ktr/template/douyin/userlist/index.js +13 -0
- package/lib/ktr/template/douyin/video-work/components/VideoWork.js +127 -0
- package/lib/ktr/template/douyin/video-work/components/types.js +2 -0
- package/lib/ktr/template/douyin/video-work/index.js +10 -0
- package/lib/ktr/template/kuaishou/comment/components/Comment.js +88 -0
- package/lib/ktr/template/kuaishou/comment/components/types.js +2 -0
- package/lib/ktr/template/kuaishou/comment/index.js +10 -0
- package/lib/ktr/template/other/changelog/components/changelog.js +117 -0
- package/lib/ktr/template/other/changelog/components/types.js +3 -0
- package/lib/ktr/template/other/changelog/index.js +9 -0
- package/lib/ktr/template/other/handlerError/components/errorTitles.js +227 -0
- package/lib/ktr/template/other/handlerError/components/handlerError.js +392 -0
- package/lib/ktr/template/other/handlerError/components/stackHighlight.js +109 -0
- package/lib/ktr/template/other/handlerError/components/types.js +2 -0
- package/lib/ktr/template/other/handlerError/index.js +9 -0
- package/lib/ktr/template/other/help/components/Help.js +79 -0
- package/lib/ktr/template/other/help/components/types.js +3 -0
- package/lib/ktr/template/other/help/index.js +12 -0
- package/lib/ktr/template/other/live-photo-tip/components/LivePhotoTip.js +80 -0
- package/lib/ktr/template/other/live-photo-tip/components/types.js +3 -0
- package/lib/ktr/template/other/live-photo-tip/index.js +9 -0
- package/lib/ktr/template/other/qrlogin/components/qrlogin.js +58 -0
- package/lib/ktr/template/other/qrlogin/components/types.js +3 -0
- package/lib/ktr/template/other/qrlogin/index.js +9 -0
- package/lib/ktr/template/other/runtime/components/runtime.js +101 -0
- package/lib/ktr/template/other/runtime/components/types.js +3 -0
- package/lib/ktr/template/other/runtime/index.js +9 -0
- package/lib/ktr/template/other/version_warning/components/VersionWarning.js +38 -0
- package/lib/ktr/template/other/version_warning/components/types.js +3 -0
- package/lib/ktr/template/other/version_warning/index.js +9 -0
- package/lib/ktr/template/statistics/components/BoxplotGuide.js +17 -0
- package/lib/ktr/template/statistics/components/ChartCard.js +15 -0
- package/lib/ktr/template/statistics/components/KpiCard.js +14 -0
- package/lib/ktr/template/statistics/components/PlatformTable.js +20 -0
- package/lib/ktr/template/statistics/components/RankList.js +61 -0
- package/lib/ktr/template/statistics/components/SSRChart.js +22 -0
- package/lib/ktr/template/statistics/components/chartPresets.js +630 -0
- package/lib/ktr/template/statistics/components/chartTheme.js +226 -0
- package/lib/ktr/template/statistics/components/format.js +38 -0
- package/lib/ktr/template/statistics/components/types.js +9 -0
- package/lib/ktr/template/statistics/global/components/GlobalStatistics.js +246 -0
- package/lib/ktr/template/statistics/global/components/types.js +3 -0
- package/lib/ktr/template/statistics/global/index.js +9 -0
- package/lib/ktr/template/statistics/group/components/GroupStatistics.js +181 -0
- package/lib/ktr/template/statistics/group/components/types.js +3 -0
- package/lib/ktr/template/statistics/group/index.js +9 -0
- package/lib/ktr/template/types/ctx.js +2 -0
- package/lib/ktr/template/xiaohongshu/comment/components/Comment.js +99 -0
- package/lib/ktr/template/xiaohongshu/comment/components/types.js +3 -0
- package/lib/ktr/template/xiaohongshu/comment/index.js +9 -0
- package/lib/ktr/template/xiaohongshu/noteInfo/components/noteInfo.js +93 -0
- package/lib/ktr/template/xiaohongshu/noteInfo/components/types.js +2 -0
- package/lib/ktr/template/xiaohongshu/noteInfo/index.js +9 -0
- package/lib/ktr/utils/QRCodeAvatar.js +99 -0
- package/lib/ktr/utils/QRcode.js +56 -0
- package/lib/ktr/utils/avatarProxy.js +45 -0
- package/lib/ktr/utils/cn.js +11 -0
- package/lib/ktr/utils/theme.js +12 -0
- package/lib/qqFields.json +75 -0
- package/lib/qqOptions.js +44 -0
- package/lib/richtext/index.js +25 -0
- package/lib/richtext/parse/index.js +232 -0
- package/lib/richtext/react/cn.js +11 -0
- package/lib/richtext/react/index.js +221 -0
- package/lib/richtext/types.js +2 -0
- package/lib/schema.js +352 -0
- package/lib/webui.js +341 -0
- package/package.json +88 -0
- package/resources/image/bilibili/RICH_TEXT_NODE_TYPE/RICH_TEXT_NODE_TYPE_BV.svg +1 -0
- package/resources/image/bilibili/RICH_TEXT_NODE_TYPE/RICH_TEXT_NODE_TYPE_GOODS.svg +1 -0
- package/resources/image/bilibili/RICH_TEXT_NODE_TYPE/RICH_TEXT_NODE_TYPE_LOTTERY.svg +1 -0
- package/resources/image/bilibili/RICH_TEXT_NODE_TYPE/RICH_TEXT_NODE_TYPE_VIEW_PICTURE.svg +1 -0
- package/resources/image/bilibili/RICH_TEXT_NODE_TYPE/RICH_TEXT_NODE_TYPE_VOTE.svg +1 -0
- package/resources/image/bilibili/RICH_TEXT_NODE_TYPE/RICH_TEXT_NODE_TYPE_WEB.svg +1 -0
- package/resources/image/bilibili/bilibili-dark.png +0 -0
- package/resources/image/bilibili/bilibili-light.png +0 -0
- package/resources/image/bilibili/bilibili.png +0 -0
- package/resources/image/bilibili/id-dark.svg +1 -0
- package/resources/image/bilibili/id-light.svg +1 -0
- package/resources/image/bilibili/level/lv0.svg +1 -0
- package/resources/image/bilibili/level/lv1.svg +1 -0
- package/resources/image/bilibili/level/lv2.svg +1 -0
- package/resources/image/bilibili/level/lv3.svg +1 -0
- package/resources/image/bilibili/level/lv4.svg +1 -0
- package/resources/image/bilibili/level/lv5.svg +1 -0
- package/resources/image/bilibili/level/lv6.svg +1 -0
- package/resources/image/bilibili/level/lv7.svg +1 -0
- package/resources/image/bilibili/like-dark.svg +6 -0
- package/resources/image/bilibili/like-light.svg +6 -0
- package/resources/image/bilibili/play.svg +28 -0
- package/resources/image/bilibili/res-local1.png +0 -0
- package/resources/image/bilibili/up_pb.svg +1 -0
- package/resources/image/bilibili//347/233/264/346/222/255/344/270/255.png +0 -0
- package/resources/image/douyin/douyin.png +0 -0
- package/resources/image/douyin/dylogo-dark.svg +23 -0
- package/resources/image/douyin/dylogo-light.svg +38 -0
- package/resources/image/douyin/search-dark.svg +1 -0
- package/resources/image/douyin/search-light.svg +3 -0
- package/resources/image/douyin//346/212/226/351/237/263-/347/233/264/346/222/255/344/270/255.png +0 -0
- package/resources/image/frame-logo.png +0 -0
- package/resources/image/kuaishou/logo.png +0 -0
- package/resources/image/other/handlerError/Milky.png +0 -0
- package/resources/image/other/handlerError/chronocat.svg +43 -0
- package/resources/image/other/handlerError/conwechat.webp +0 -0
- package/resources/image/other/handlerError/gocq-http.webp +0 -0
- package/resources/image/other/handlerError/lagrange.webp +0 -0
- package/resources/image/other/handlerError/llonebot.webp +0 -0
- package/resources/image/other/handlerError/napcat.webp +0 -0
- package/resources/image/other/handlerError/onebot.png +0 -0
- package/resources/image/other/handlerError/satori.png +0 -0
- package/resources/image/xiaohongshu/logo.png +0 -0
- package/resources/template/style.css +23708 -0
- package/resources/vite.svg +130 -0
- package/scripts/build.mjs +129 -0
- package/scripts/check-schema.cjs +55 -0
- package/scripts/deploy.mjs +78 -0
- package/scripts/make-demo-placeholders.mjs +112 -0
- package/scripts/patch-deps.mjs +46 -0
- package/scripts/patch-webui.mjs +112 -0
- package/scripts/smoke-commands.cjs +39 -0
- package/scripts/smoke-config.cjs +122 -0
- package/scripts/smoke-douyin.cjs +170 -0
- package/scripts/smoke-koishi-commands.cjs +210 -0
- package/scripts/smoke-login.cjs +110 -0
- package/scripts/smoke-parse.cjs +54 -0
- package/scripts/smoke-push-mock.cjs +114 -0
- package/scripts/smoke-push.cjs +104 -0
- package/scripts/smoke-qq.cjs +147 -0
- package/scripts/smoke-qqcard.cjs +108 -0
- package/scripts/smoke-qqpanel.cjs +205 -0
- package/scripts/smoke-render.cjs +106 -0
- package/scripts/smoke-server.cjs +94 -0
- package/src/compat/axios.ts +5 -0
- package/src/compat/cron.ts +86 -0
- package/src/compat/esm.ts +13 -0
- package/src/compat/express.ts +5 -0
- package/src/compat/heroui.tsx +53 -0
- package/src/compat/lodash.ts +32 -0
- package/src/compat/logger.ts +121 -0
- package/src/compat/node-karin.ts +1064 -0
- package/src/compat/phosphor-icons.tsx +25 -0
- package/src/compat/qqcard.ts +251 -0
- package/src/compat/root.ts +44 -0
- package/src/compat/runtime.ts +120 -0
- package/src/compat/segment.ts +161 -0
- package/src/compat/sqlite3.ts +123 -0
- package/src/compat/start.ts +3 -0
- package/src/compat/syncConfig.ts +64 -0
- package/src/compat/template-react.ts +54 -0
- package/src/compat/text.ts +58 -0
- package/src/compat/yaml.ts +6 -0
- package/src/configBridge.ts +94 -0
- package/src/index.ts +769 -0
- package/src/karin/app.ts +1 -0
- package/src/karin/apps/__ready.ts +14 -0
- package/src/karin/apps/admin.ts +127 -0
- package/src/karin/apps/help.ts +228 -0
- package/src/karin/apps/push.ts +327 -0
- package/src/karin/apps/qrlogin.ts +160 -0
- package/src/karin/apps/statistics.ts +203 -0
- package/src/karin/apps/testPush.ts +226 -0
- package/src/karin/apps/tools.ts +510 -0
- package/src/karin/apps/update.ts +239 -0
- package/src/karin/index.ts +9 -0
- package/src/karin/module/db/bilibili.ts +1089 -0
- package/src/karin/module/db/douyin.ts +1218 -0
- package/src/karin/module/db/index.ts +159 -0
- package/src/karin/module/db/migration.ts +249 -0
- package/src/karin/module/db/statistics.ts +817 -0
- package/src/karin/module/index.ts +37 -0
- package/src/karin/module/server/constants/routes.ts +53 -0
- package/src/karin/module/server/controllers/bots.ts +289 -0
- package/src/karin/module/server/controllers/config.ts +85 -0
- package/src/karin/module/server/controllers/video.ts +212 -0
- package/src/karin/module/server/index.ts +11 -0
- package/src/karin/module/server/middlewares/auth.ts +147 -0
- package/src/karin/module/server/routes/amagi.ts +57 -0
- package/src/karin/module/server/routes/api.ts +42 -0
- package/src/karin/module/server/routes/index.ts +68 -0
- package/src/karin/module/server/routes/ssr.ts +14 -0
- package/src/karin/module/server/routes/static.ts +43 -0
- package/src/karin/module/utils/Base.ts +497 -0
- package/src/karin/module/utils/CardParser.ts +503 -0
- package/src/karin/module/utils/Common.ts +448 -0
- package/src/karin/module/utils/Config.ts +443 -0
- package/src/karin/module/utils/EmojiReaction.ts +268 -0
- package/src/karin/module/utils/ErrorHandler/handler.ts +124 -0
- package/src/karin/module/utils/ErrorHandler/index.ts +48 -0
- package/src/karin/module/utils/ErrorHandler/render.ts +180 -0
- package/src/karin/module/utils/ErrorHandler/sender.ts +192 -0
- package/src/karin/module/utils/ErrorHandler/strategy.ts +41 -0
- package/src/karin/module/utils/ErrorHandler/types.ts +122 -0
- package/src/karin/module/utils/ErrorHandler/utils.ts +108 -0
- package/src/karin/module/utils/FFmpeg.ts +357 -0
- package/src/karin/module/utils/ImageHelper.ts +90 -0
- package/src/karin/module/utils/ImageSlice.ts +383 -0
- package/src/karin/module/utils/MotionPhoto.ts +297 -0
- package/src/karin/module/utils/Network/Downloader.ts +481 -0
- package/src/karin/module/utils/Network/ImageDownloader.ts +291 -0
- package/src/karin/module/utils/Network/Network.ts +344 -0
- package/src/karin/module/utils/Network/ThrottleStream.ts +76 -0
- package/src/karin/module/utils/Network/constants.ts +135 -0
- package/src/karin/module/utils/Network/helpers.ts +183 -0
- package/src/karin/module/utils/Network/index.ts +28 -0
- package/src/karin/module/utils/Network/types.ts +46 -0
- package/src/karin/module/utils/Networks.ts +20 -0
- package/src/karin/module/utils/ParseLock.ts +33 -0
- package/src/karin/module/utils/ParseOverride.ts +128 -0
- package/src/karin/module/utils/QqCardResolve.ts +116 -0
- package/src/karin/module/utils/QqPanel.ts +880 -0
- package/src/karin/module/utils/Render/coverTheme.ts +294 -0
- package/src/karin/module/utils/Render/index.ts +574 -0
- package/src/karin/module/utils/amagiClient.ts +368 -0
- package/src/karin/module/utils/avatar.ts +220 -0
- package/src/karin/module/utils/bot.ts +115 -0
- package/src/karin/module/utils/build-metadata.ts +60 -0
- package/src/karin/module/utils/changelog.ts +175 -0
- package/src/karin/module/utils/index.ts +10 -0
- package/src/karin/module/utils/loginSession.ts +291 -0
- package/src/karin/module/utils/parseTip.ts +59 -0
- package/src/karin/module/utils/runtime-report.ts +142 -0
- package/src/karin/module/utils/semver.ts +60 -0
- package/src/karin/module/utils/statisticsAggregate.ts +507 -0
- package/src/karin/platform/bilibili/bilibili.ts +2004 -0
- package/src/karin/platform/bilibili/comments.ts +397 -0
- package/src/karin/platform/bilibili/danmaku.ts +653 -0
- package/src/karin/platform/bilibili/dynamic-text.ts +926 -0
- package/src/karin/platform/bilibili/genParams.ts +30 -0
- package/src/karin/platform/bilibili/getID.ts +163 -0
- package/src/karin/platform/bilibili/index.ts +8 -0
- package/src/karin/platform/bilibili/live-status.ts +36 -0
- package/src/karin/platform/bilibili/login.ts +130 -0
- package/src/karin/platform/bilibili/push.ts +1615 -0
- package/src/karin/platform/bilibili/riskControl.ts +114 -0
- package/src/karin/platform/bilibili/search.ts +305 -0
- package/src/karin/platform/common/danmaku-types.ts +18 -0
- package/src/karin/platform/douyin/comments.ts +404 -0
- package/src/karin/platform/douyin/danmaku.ts +1187 -0
- package/src/karin/platform/douyin/douyin.ts +1244 -0
- package/src/karin/platform/douyin/getID.ts +101 -0
- package/src/karin/platform/douyin/index.ts +8 -0
- package/src/karin/platform/douyin/login.ts +251 -0
- package/src/karin/platform/douyin/push/favorite.ts +97 -0
- package/src/karin/platform/douyin/push/index.ts +5 -0
- package/src/karin/platform/douyin/push/live.ts +86 -0
- package/src/karin/platform/douyin/push/post.ts +75 -0
- package/src/karin/platform/douyin/push/recommend.ts +96 -0
- package/src/karin/platform/douyin/push/render.ts +768 -0
- package/src/karin/platform/douyin/push/types.ts +41 -0
- package/src/karin/platform/douyin/push.ts +1241 -0
- package/src/karin/platform/douyin/types.ts +151 -0
- package/src/karin/platform/douyin/videoQuality.ts +234 -0
- package/src/karin/platform/douyin/workType.ts +238 -0
- package/src/karin/platform/index.ts +4 -0
- package/src/karin/platform/kuaishou/comments.ts +114 -0
- package/src/karin/platform/kuaishou/getID.ts +48 -0
- package/src/karin/platform/kuaishou/getdata.ts +78 -0
- package/src/karin/platform/kuaishou/index.ts +4 -0
- package/src/karin/platform/kuaishou/kuaishou.ts +130 -0
- package/src/karin/platform/xiaohongshu/comments.ts +227 -0
- package/src/karin/platform/xiaohongshu/getID.ts +127 -0
- package/src/karin/platform/xiaohongshu/index.ts +2 -0
- package/src/karin/platform/xiaohongshu/xiaohongshu.ts +733 -0
- package/src/karin/root.ts +78 -0
- package/src/karin/setup.ts +77 -0
- package/src/karin/types/config/amagi.ts +46 -0
- package/src/karin/types/config/app.ts +129 -0
- package/src/karin/types/config/bilibili.ts +121 -0
- package/src/karin/types/config/cookies.ts +11 -0
- package/src/karin/types/config/douyin.ts +93 -0
- package/src/karin/types/config/index.ts +41 -0
- package/src/karin/types/config/kuaishou.ts +10 -0
- package/src/karin/types/config/pushlist.ts +55 -0
- package/src/karin/types/config/request.ts +27 -0
- package/src/karin/types/config/upload.ts +49 -0
- package/src/karin/types/config/xiaohongshu.ts +24 -0
- package/src/karin/types/datatypes.ts +42 -0
- package/src/karin/types/index.ts +4 -0
- package/src/karin/types/netrorks/NetworksConfigType.ts +61 -0
- package/src/karin/types/netrorks/index.ts +1 -0
- package/src/karin/web.config.ts +48 -0
- package/src/ktr/registry.ts +55 -0
- package/src/ktr/template/_preview/components/PreviewInfoCard.tsx +33 -0
- package/src/ktr/template/_preview/components/PreviewLayout.tsx +65 -0
- package/src/ktr/template/_preview/components/PreviewVideoCard.tsx +22 -0
- package/src/ktr/template/_preview/render.ts +158 -0
- package/src/ktr/template/_preview/types.ts +15 -0
- package/src/ktr/template/_preview/utils/status.ts +29 -0
- package/src/ktr/template/_preview/utils/time.ts +8 -0
- package/src/ktr/template/bilibili/bangumi/components/bangumi.tsx +462 -0
- package/src/ktr/template/bilibili/bangumi/components/types.ts +36 -0
- package/src/ktr/template/bilibili/bangumi/index.tsx +9 -0
- package/src/ktr/template/bilibili/comment/components/Comment.tsx +657 -0
- package/src/ktr/template/bilibili/comment/components/types.ts +26 -0
- package/src/ktr/template/bilibili/comment/index.tsx +11 -0
- package/src/ktr/template/bilibili/components/Icons.tsx +209 -0
- package/src/ktr/template/bilibili/components/shared.tsx +162 -0
- package/src/ktr/template/bilibili/components/types.ts +388 -0
- package/src/ktr/template/bilibili/dynamic/DYNAMIC_TYPE_ARTICLE/components/DYNAMIC_TYPE_ARTICLE.tsx +251 -0
- package/src/ktr/template/bilibili/dynamic/DYNAMIC_TYPE_ARTICLE/components/types.ts +67 -0
- package/src/ktr/template/bilibili/dynamic/DYNAMIC_TYPE_ARTICLE/index.tsx +12 -0
- package/src/ktr/template/bilibili/dynamic/DYNAMIC_TYPE_AV/components/DYNAMIC_TYPE_AV.tsx +238 -0
- package/src/ktr/template/bilibili/dynamic/DYNAMIC_TYPE_AV/components/types.ts +39 -0
- package/src/ktr/template/bilibili/dynamic/DYNAMIC_TYPE_AV/index.tsx +12 -0
- package/src/ktr/template/bilibili/dynamic/DYNAMIC_TYPE_DRAW/components/DYNAMIC_TYPE_DRAW.tsx +205 -0
- package/src/ktr/template/bilibili/dynamic/DYNAMIC_TYPE_DRAW/components/types.ts +20 -0
- package/src/ktr/template/bilibili/dynamic/DYNAMIC_TYPE_DRAW/index.tsx +11 -0
- package/src/ktr/template/bilibili/dynamic/DYNAMIC_TYPE_FORWARD/components/DYNAMIC_TYPE_FORWARD.tsx +348 -0
- package/src/ktr/template/bilibili/dynamic/DYNAMIC_TYPE_FORWARD/components/types.ts +16 -0
- package/src/ktr/template/bilibili/dynamic/DYNAMIC_TYPE_FORWARD/index.tsx +12 -0
- package/src/ktr/template/bilibili/dynamic/DYNAMIC_TYPE_LIVE_RCMD/components/DYNAMIC_TYPE_LIVE_RCMD.tsx +264 -0
- package/src/ktr/template/bilibili/dynamic/DYNAMIC_TYPE_LIVE_RCMD/components/types.ts +32 -0
- package/src/ktr/template/bilibili/dynamic/DYNAMIC_TYPE_LIVE_RCMD/index.tsx +12 -0
- package/src/ktr/template/bilibili/dynamic/DYNAMIC_TYPE_WORD/components/DYNAMIC_TYPE_WORD.tsx +68 -0
- package/src/ktr/template/bilibili/dynamic/DYNAMIC_TYPE_WORD/components/types.ts +14 -0
- package/src/ktr/template/bilibili/dynamic/DYNAMIC_TYPE_WORD/index.tsx +12 -0
- package/src/ktr/template/bilibili/dynamic/components/AdditionalCard.tsx +165 -0
- package/src/ktr/template/bilibili/dynamic/components/CommonComponents.tsx +142 -0
- package/src/ktr/template/bilibili/dynamic/types.ts +382 -0
- package/src/ktr/template/bilibili/qrcodeImg/components/qrcodeImg.tsx +179 -0
- package/src/ktr/template/bilibili/qrcodeImg/components/types.ts +9 -0
- package/src/ktr/template/bilibili/qrcodeImg/index.tsx +12 -0
- package/src/ktr/template/bilibili/userlist/components/UserList.tsx +246 -0
- package/src/ktr/template/bilibili/userlist/components/types.ts +35 -0
- package/src/ktr/template/bilibili/userlist/index.tsx +11 -0
- package/src/ktr/template/bilibili/videoInfo/components/types.ts +28 -0
- package/src/ktr/template/bilibili/videoInfo/components/videoInfo.tsx +217 -0
- package/src/ktr/template/bilibili/videoInfo/index.tsx +12 -0
- package/src/ktr/template/components/AmbientCover.tsx +50 -0
- package/src/ktr/template/components/DefaultLayout.tsx +166 -0
- package/src/ktr/template/components/GlowImage.tsx +572 -0
- package/src/ktr/template/components/QRCodeWithAvatar.tsx +52 -0
- package/src/ktr/template/components/RolldownLogo.tsx +110 -0
- package/src/ktr/template/components/ViteLogo.tsx +134 -0
- package/src/ktr/template/components/iconRegistry.ts +294 -0
- package/src/ktr/template/douyin/article-work/components/ArticleWork.tsx +301 -0
- package/src/ktr/template/douyin/article-work/components/types.ts +53 -0
- package/src/ktr/template/douyin/article-work/index.tsx +12 -0
- package/src/ktr/template/douyin/comment/components/Comment.tsx +612 -0
- package/src/ktr/template/douyin/comment/components/types.ts +85 -0
- package/src/ktr/template/douyin/comment/index.tsx +11 -0
- package/src/ktr/template/douyin/components/Icons.tsx +75 -0
- package/src/ktr/template/douyin/components/types.ts +83 -0
- package/src/ktr/template/douyin/dynamic/components/Dynamic.tsx +283 -0
- package/src/ktr/template/douyin/dynamic/components/types.ts +46 -0
- package/src/ktr/template/douyin/dynamic/index.tsx +11 -0
- package/src/ktr/template/douyin/favorite-list/components/FavoriteList.tsx +201 -0
- package/src/ktr/template/douyin/favorite-list/components/types.ts +38 -0
- package/src/ktr/template/douyin/favorite-list/index.tsx +12 -0
- package/src/ktr/template/douyin/image-work/components/ImageWork.tsx +437 -0
- package/src/ktr/template/douyin/image-work/components/types.ts +78 -0
- package/src/ktr/template/douyin/image-work/index.tsx +11 -0
- package/src/ktr/template/douyin/live/components/Live.tsx +229 -0
- package/src/ktr/template/douyin/live/components/types.ts +47 -0
- package/src/ktr/template/douyin/live/index.tsx +11 -0
- package/src/ktr/template/douyin/musicinfo/components/MusicInfo.tsx +187 -0
- package/src/ktr/template/douyin/musicinfo/components/types.ts +31 -0
- package/src/ktr/template/douyin/musicinfo/index.tsx +11 -0
- package/src/ktr/template/douyin/qrcodeImg/components/qrcodeImg.tsx +170 -0
- package/src/ktr/template/douyin/qrcodeImg/components/types.ts +9 -0
- package/src/ktr/template/douyin/qrcodeImg/index.tsx +9 -0
- package/src/ktr/template/douyin/recommend-list/components/RecommendList.tsx +201 -0
- package/src/ktr/template/douyin/recommend-list/components/types.ts +37 -0
- package/src/ktr/template/douyin/recommend-list/index.tsx +12 -0
- package/src/ktr/template/douyin/user_profile/components/UserVideoList.tsx +225 -0
- package/src/ktr/template/douyin/user_profile/components/types.ts +71 -0
- package/src/ktr/template/douyin/user_profile/index.tsx +9 -0
- package/src/ktr/template/douyin/userlist/components/UserList.tsx +229 -0
- package/src/ktr/template/douyin/userlist/components/types.ts +35 -0
- package/src/ktr/template/douyin/userlist/index.tsx +11 -0
- package/src/ktr/template/douyin/video-work/components/VideoWork.tsx +398 -0
- package/src/ktr/template/douyin/video-work/components/types.ts +80 -0
- package/src/ktr/template/douyin/video-work/index.tsx +11 -0
- package/src/ktr/template/font.css +6071 -0
- package/src/ktr/template/global.d.ts +69 -0
- package/src/ktr/template/kuaishou/comment/components/Comment.tsx +207 -0
- package/src/ktr/template/kuaishou/comment/components/types.ts +47 -0
- package/src/ktr/template/kuaishou/comment/index.tsx +11 -0
- package/src/ktr/template/other/changelog/components/changelog.tsx +411 -0
- package/src/ktr/template/other/changelog/components/types.ts +21 -0
- package/src/ktr/template/other/changelog/index.tsx +9 -0
- package/src/ktr/template/other/handlerError/components/errorTitles.ts +224 -0
- package/src/ktr/template/other/handlerError/components/handlerError.tsx +1076 -0
- package/src/ktr/template/other/handlerError/components/stackHighlight.ts +127 -0
- package/src/ktr/template/other/handlerError/components/types.ts +124 -0
- package/src/ktr/template/other/handlerError/index.tsx +9 -0
- package/src/ktr/template/other/help/components/Help.tsx +249 -0
- package/src/ktr/template/other/help/components/types.ts +47 -0
- package/src/ktr/template/other/help/index.tsx +9 -0
- package/src/ktr/template/other/live-photo-tip/components/LivePhotoTip.tsx +295 -0
- package/src/ktr/template/other/live-photo-tip/components/types.ts +8 -0
- package/src/ktr/template/other/live-photo-tip/index.tsx +9 -0
- package/src/ktr/template/other/qrlogin/components/qrlogin.tsx +295 -0
- package/src/ktr/template/other/qrlogin/components/types.ts +11 -0
- package/src/ktr/template/other/qrlogin/index.tsx +9 -0
- package/src/ktr/template/other/runtime/components/runtime.tsx +347 -0
- package/src/ktr/template/other/runtime/components/types.ts +75 -0
- package/src/ktr/template/other/runtime/index.tsx +9 -0
- package/src/ktr/template/other/version_warning/components/VersionWarning.tsx +392 -0
- package/src/ktr/template/other/version_warning/components/types.ts +8 -0
- package/src/ktr/template/other/version_warning/index.tsx +9 -0
- package/src/ktr/template/statistics/components/BoxplotGuide.tsx +57 -0
- package/src/ktr/template/statistics/components/ChartCard.tsx +40 -0
- package/src/ktr/template/statistics/components/KpiCard.tsx +39 -0
- package/src/ktr/template/statistics/components/PlatformTable.tsx +83 -0
- package/src/ktr/template/statistics/components/RankList.tsx +127 -0
- package/src/ktr/template/statistics/components/SSRChart.tsx +41 -0
- package/src/ktr/template/statistics/components/chartPresets.ts +700 -0
- package/src/ktr/template/statistics/components/chartTheme.ts +234 -0
- package/src/ktr/template/statistics/components/format.ts +33 -0
- package/src/ktr/template/statistics/components/types.ts +92 -0
- package/src/ktr/template/statistics/global/components/GlobalStatistics.tsx +597 -0
- package/src/ktr/template/statistics/global/components/types.ts +138 -0
- package/src/ktr/template/statistics/global/index.tsx +9 -0
- package/src/ktr/template/statistics/group/components/GroupStatistics.tsx +468 -0
- package/src/ktr/template/statistics/group/components/types.ts +113 -0
- package/src/ktr/template/statistics/group/index.tsx +9 -0
- package/src/ktr/template/style.css +65 -0
- package/src/ktr/template/types/ctx.ts +42 -0
- package/src/ktr/template/xiaohongshu/comment/components/Comment.tsx +264 -0
- package/src/ktr/template/xiaohongshu/comment/components/types.ts +119 -0
- package/src/ktr/template/xiaohongshu/comment/index.tsx +9 -0
- package/src/ktr/template/xiaohongshu/noteInfo/components/noteInfo.tsx +271 -0
- package/src/ktr/template/xiaohongshu/noteInfo/components/types.ts +66 -0
- package/src/ktr/template/xiaohongshu/noteInfo/index.tsx +9 -0
- package/src/ktr/utils/QRCodeAvatar.ts +102 -0
- package/src/ktr/utils/QRcode.ts +65 -0
- package/src/ktr/utils/avatarProxy.ts +42 -0
- package/src/ktr/utils/cn.ts +6 -0
- package/src/ktr/utils/theme.ts +10 -0
- package/src/qqFields.json +75 -0
- package/src/qqOptions.ts +64 -0
- package/src/richtext/index.ts +9 -0
- package/src/richtext/parse/index.ts +271 -0
- package/src/richtext/react/cn.ts +6 -0
- package/src/richtext/react/index.tsx +582 -0
- package/src/richtext/types.ts +320 -0
- package/src/schema.ts +372 -0
- package/src/webui.ts +352 -0
|
@@ -0,0 +1,926 @@
|
|
|
1
|
+
import { BilibiliArticleContentResponse } from '@ikenxuan/amagi'
|
|
2
|
+
import {
|
|
3
|
+
createAtNode,
|
|
4
|
+
createBlockquoteNode,
|
|
5
|
+
createCodeBlockNode,
|
|
6
|
+
createEmojiNode,
|
|
7
|
+
createHeadingNode,
|
|
8
|
+
createHorizontalRuleNode,
|
|
9
|
+
createImageNode,
|
|
10
|
+
createLineBreakNode,
|
|
11
|
+
createLinkCardNode,
|
|
12
|
+
createListItemNode,
|
|
13
|
+
createListNode,
|
|
14
|
+
createLotteryNode,
|
|
15
|
+
createOpusLinkNode,
|
|
16
|
+
createParagraphNode,
|
|
17
|
+
createRichTextDocument,
|
|
18
|
+
createTextNode,
|
|
19
|
+
createTopicNode,
|
|
20
|
+
createViewPictureNode,
|
|
21
|
+
createVoteNode,
|
|
22
|
+
createWebLinkNode,
|
|
23
|
+
type RichTextDocument,
|
|
24
|
+
type RichTextInlineStyle,
|
|
25
|
+
type RichTextNode
|
|
26
|
+
} from '@kkk/richtext'
|
|
27
|
+
import { logger, segment, type ElementTypes } from 'node-karin'
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 用户名元数据,用于传递 VIP 状态和颜色信息
|
|
31
|
+
*/
|
|
32
|
+
export interface UsernameMetadata {
|
|
33
|
+
name: string
|
|
34
|
+
vipStatus: number
|
|
35
|
+
nicknameColor: string | null
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 检查用户VIP状态并返回用户名元数据
|
|
40
|
+
*/
|
|
41
|
+
export const getUsernameMetadata = (member: { name?: string; vip?: { status?: number; nickname_color?: string } }): UsernameMetadata => {
|
|
42
|
+
const vip = member.vip
|
|
43
|
+
const vipStatus = vip?.status ?? 0
|
|
44
|
+
const nicknameColor = vipStatus === 1 && vip?.nickname_color && vip?.nickname_color !== '' ? vip?.nickname_color : null
|
|
45
|
+
const name = member.name ?? ''
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
name,
|
|
49
|
+
vipStatus,
|
|
50
|
+
nicknameColor
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 构建用户名的富文本。
|
|
56
|
+
* VIP 用户显示彩色名称,普通用户显示灰色名称。
|
|
57
|
+
*/
|
|
58
|
+
export const buildUsernameRichText = (metadata: UsernameMetadata): RichTextDocument => {
|
|
59
|
+
return createRichTextDocument([createTextNode(metadata.name)], {
|
|
60
|
+
platform: 'bilibili'
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 将 B 站动态正文解析成共享富文本 JSON。
|
|
66
|
+
*
|
|
67
|
+
* B站动态的 rich_text_nodes 包含以下类型:
|
|
68
|
+
* - `topic` / `RICH_TEXT_NODE_TYPE_TOPIC`: 话题
|
|
69
|
+
* - `RICH_TEXT_NODE_TYPE_AT`: @提及
|
|
70
|
+
* - `RICH_TEXT_NODE_TYPE_LOTTERY`: 抽奖
|
|
71
|
+
* - `RICH_TEXT_NODE_TYPE_WEB`: 网页链接
|
|
72
|
+
* - `RICH_TEXT_NODE_TYPE_EMOJI`: 表情
|
|
73
|
+
* - `RICH_TEXT_NODE_TYPE_VOTE`: 投票
|
|
74
|
+
* - `RICH_TEXT_NODE_TYPE_VIEW_PICTURE`: 查看图片
|
|
75
|
+
*
|
|
76
|
+
* 核心逻辑:按 richTextNodes 原始顺序遍历,用节点文本在正文 text 中查找位置,
|
|
77
|
+
* 来确定普通文本和富文本节点的边界。
|
|
78
|
+
*/
|
|
79
|
+
|
|
80
|
+
const URL_REGEX = /https?:\/\/[-\w._~:/?#[\]@!$&'()*+,;=%]+/g
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 将单行普通文本解析为文本节点和链接节点,自动提取 URL。
|
|
84
|
+
*/
|
|
85
|
+
const parseTextWithUrls = (text: string): Array<ReturnType<typeof createTextNode | typeof createWebLinkNode>> => {
|
|
86
|
+
const nodes: Array<ReturnType<typeof createTextNode | typeof createWebLinkNode>> = []
|
|
87
|
+
const matches = Array.from(text.matchAll(URL_REGEX))
|
|
88
|
+
let lastIndex = 0
|
|
89
|
+
for (const match of matches) {
|
|
90
|
+
if (match.index! > lastIndex) {
|
|
91
|
+
nodes.push(createTextNode(text.slice(lastIndex, match.index)))
|
|
92
|
+
}
|
|
93
|
+
nodes.push(createWebLinkNode(match[0], match[0]))
|
|
94
|
+
lastIndex = match.index! + match[0].length
|
|
95
|
+
}
|
|
96
|
+
if (lastIndex < text.length) {
|
|
97
|
+
nodes.push(createTextNode(text.slice(lastIndex)))
|
|
98
|
+
}
|
|
99
|
+
return nodes
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export const buildBilibiliDynamicRichText = (
|
|
103
|
+
text: string,
|
|
104
|
+
richTextNodes: Array<{
|
|
105
|
+
type?: string
|
|
106
|
+
orig_text?: string
|
|
107
|
+
text?: string
|
|
108
|
+
emoji?: {
|
|
109
|
+
gif_url?: string
|
|
110
|
+
icon_url?: string
|
|
111
|
+
size?: number
|
|
112
|
+
}
|
|
113
|
+
}>
|
|
114
|
+
): RichTextDocument => {
|
|
115
|
+
const nodes: Array<
|
|
116
|
+
ReturnType<
|
|
117
|
+
| typeof createTextNode
|
|
118
|
+
| typeof createEmojiNode
|
|
119
|
+
| typeof createTopicNode
|
|
120
|
+
| typeof createAtNode
|
|
121
|
+
| typeof createLotteryNode
|
|
122
|
+
| typeof createWebLinkNode
|
|
123
|
+
| typeof createVoteNode
|
|
124
|
+
| typeof createViewPictureNode
|
|
125
|
+
| typeof createLineBreakNode
|
|
126
|
+
>
|
|
127
|
+
> = []
|
|
128
|
+
|
|
129
|
+
if (!richTextNodes || !Array.isArray(richTextNodes) || richTextNodes.length === 0) {
|
|
130
|
+
if (text) {
|
|
131
|
+
const parts = text.split(/(\r?\n)/)
|
|
132
|
+
for (const part of parts) {
|
|
133
|
+
if (part === '\r\n' || part === '\n') {
|
|
134
|
+
nodes.push(createLineBreakNode())
|
|
135
|
+
} else if (part) {
|
|
136
|
+
nodes.push(...parseTextWithUrls(part))
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return createRichTextDocument(nodes, { platform: 'bilibili' })
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// 辅助函数:根据单个 richTextNode 创建对应的富文本节点
|
|
144
|
+
const buildNodesFromTag = (tag: (typeof richTextNodes)[number]): Array<(typeof nodes)[number]> => {
|
|
145
|
+
const matchText = tag.orig_text || tag.text || ''
|
|
146
|
+
if (!matchText) return []
|
|
147
|
+
|
|
148
|
+
const result: Array<(typeof nodes)[number]> = []
|
|
149
|
+
switch (tag.type) {
|
|
150
|
+
case 'RICH_TEXT_NODE_TYPE_TEXT': {
|
|
151
|
+
const parts = matchText.split(/(\r?\n)/)
|
|
152
|
+
for (const part of parts) {
|
|
153
|
+
if (part === '\r\n' || part === '\n') {
|
|
154
|
+
result.push(createLineBreakNode())
|
|
155
|
+
} else if (part) {
|
|
156
|
+
result.push(...parseTextWithUrls(part))
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
break
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
case 'topic':
|
|
163
|
+
case 'RICH_TEXT_NODE_TYPE_TOPIC':
|
|
164
|
+
result.push(createTopicNode(matchText))
|
|
165
|
+
break
|
|
166
|
+
|
|
167
|
+
case 'RICH_TEXT_NODE_TYPE_AT':
|
|
168
|
+
result.push(createAtNode(matchText))
|
|
169
|
+
break
|
|
170
|
+
|
|
171
|
+
case 'RICH_TEXT_NODE_TYPE_LOTTERY':
|
|
172
|
+
result.push(createLotteryNode(matchText))
|
|
173
|
+
break
|
|
174
|
+
|
|
175
|
+
case 'RICH_TEXT_NODE_TYPE_WEB':
|
|
176
|
+
result.push(createWebLinkNode(tag.text || matchText, matchText))
|
|
177
|
+
break
|
|
178
|
+
|
|
179
|
+
case 'RICH_TEXT_NODE_TYPE_EMOJI': {
|
|
180
|
+
const emojiUrl = tag.emoji?.gif_url || tag.emoji?.icon_url
|
|
181
|
+
const scale = tag.emoji?.size === 2 || tag.emoji?.size === 3 ? 2 : undefined
|
|
182
|
+
if (emojiUrl) {
|
|
183
|
+
result.push(createEmojiNode(matchText, emojiUrl, { scale }))
|
|
184
|
+
} else {
|
|
185
|
+
result.push(createTextNode(matchText))
|
|
186
|
+
}
|
|
187
|
+
break
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
case 'RICH_TEXT_NODE_TYPE_VOTE':
|
|
191
|
+
result.push(createVoteNode(tag.text || matchText))
|
|
192
|
+
break
|
|
193
|
+
|
|
194
|
+
case 'RICH_TEXT_NODE_TYPE_VIEW_PICTURE':
|
|
195
|
+
result.push(createViewPictureNode(matchText))
|
|
196
|
+
break
|
|
197
|
+
|
|
198
|
+
default: {
|
|
199
|
+
const parts = matchText.split(/(\r?\n)/)
|
|
200
|
+
for (const part of parts) {
|
|
201
|
+
if (part === '\r\n' || part === '\n') {
|
|
202
|
+
result.push(createLineBreakNode())
|
|
203
|
+
} else if (part) {
|
|
204
|
+
result.push(...parseTextWithUrls(part))
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
break
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return result
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// text 为空字符串时,直接按 richTextNodes 顺序构建节点,无需在 text 中查找位置
|
|
214
|
+
if (!text) {
|
|
215
|
+
for (const tag of richTextNodes) {
|
|
216
|
+
nodes.push(...buildNodesFromTag(tag))
|
|
217
|
+
}
|
|
218
|
+
return createRichTextDocument(nodes, { platform: 'bilibili' })
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// 搜索函数:从给定起始位置开始查找子串在 text 中的位置
|
|
222
|
+
const findInText = (searchText: string, startPos: number): number => {
|
|
223
|
+
return text.indexOf(searchText, startPos)
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
let currentPos = 0 // 当前已处理的 text 位置
|
|
227
|
+
|
|
228
|
+
for (const tag of richTextNodes) {
|
|
229
|
+
const matchText = tag.orig_text || tag.text || ''
|
|
230
|
+
if (!matchText) continue
|
|
231
|
+
|
|
232
|
+
const matchPos = findInText(matchText, currentPos)
|
|
233
|
+
if (matchPos === -1) continue
|
|
234
|
+
|
|
235
|
+
// 添加匹配位置之前的普通文本
|
|
236
|
+
if (matchPos > currentPos) {
|
|
237
|
+
const beforeText = text.slice(currentPos, matchPos)
|
|
238
|
+
// 按换行符分割,分别处理普通文本和换行
|
|
239
|
+
const parts = beforeText.split(/(\r?\n)/)
|
|
240
|
+
for (const part of parts) {
|
|
241
|
+
if (part === '\r\n' || part === '\n') {
|
|
242
|
+
nodes.push(createLineBreakNode())
|
|
243
|
+
} else if (part) {
|
|
244
|
+
nodes.push(...parseTextWithUrls(part))
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
nodes.push(...buildNodesFromTag(tag))
|
|
250
|
+
currentPos = matchPos + matchText.length
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// 添加剩余文本
|
|
254
|
+
if (currentPos < text.length) {
|
|
255
|
+
const remainingText = text.slice(currentPos)
|
|
256
|
+
const parts = remainingText.split(/(\r?\n)/)
|
|
257
|
+
for (const part of parts) {
|
|
258
|
+
if (part === '\r\n' || part === '\n') {
|
|
259
|
+
nodes.push(createLineBreakNode())
|
|
260
|
+
} else if (part) {
|
|
261
|
+
nodes.push(...parseTextWithUrls(part))
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
return createRichTextDocument(nodes, { platform: 'bilibili' })
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* 根据 B站视频详情 desc_v2 构建富文本文档。
|
|
271
|
+
*
|
|
272
|
+
* desc_v2 结构:
|
|
273
|
+
* - type: 1 → 纯文本(含换行、链接)
|
|
274
|
+
* - type: 2 → @提及(biz_id 为用户ID)
|
|
275
|
+
*/
|
|
276
|
+
export const buildBilibiliVideoDescRichText = (descV2: Array<{ raw_text?: string; type?: number; biz_id?: number }>): RichTextDocument => {
|
|
277
|
+
const nodes: RichTextNode[] = []
|
|
278
|
+
for (const item of descV2) {
|
|
279
|
+
const rawText = item.raw_text || ''
|
|
280
|
+
if (!rawText) continue
|
|
281
|
+
switch (item.type) {
|
|
282
|
+
case 1: {
|
|
283
|
+
const parts = rawText.split(/(\r?\n)/)
|
|
284
|
+
for (const part of parts) {
|
|
285
|
+
if (part === '\r\n' || part === '\n') {
|
|
286
|
+
nodes.push(createLineBreakNode())
|
|
287
|
+
} else if (part) {
|
|
288
|
+
nodes.push(...parseTextWithUrls(part))
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
break
|
|
292
|
+
}
|
|
293
|
+
case 2:
|
|
294
|
+
nodes.push(createAtNode(`@${rawText}`, item.biz_id?.toString()))
|
|
295
|
+
break
|
|
296
|
+
default:
|
|
297
|
+
nodes.push(createTextNode(rawText))
|
|
298
|
+
break
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return createRichTextDocument(nodes, { platform: 'bilibili' })
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/** 修复图片 URL 协议。 */
|
|
305
|
+
const fixImageUrl = (url: string): string => {
|
|
306
|
+
if (url.startsWith('//')) {
|
|
307
|
+
return `https:${url}`
|
|
308
|
+
}
|
|
309
|
+
return url
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/** 从 opus word.style 提取 RichTextInlineStyle。 */
|
|
313
|
+
const extractWordStyle = (style: Record<string, any> = {}): RichTextInlineStyle => {
|
|
314
|
+
const result: RichTextInlineStyle = {}
|
|
315
|
+
if (style.bold) result.bold = true
|
|
316
|
+
if (style.italic) result.italic = true
|
|
317
|
+
if (style.strike) result.strike = true
|
|
318
|
+
if (style.color && typeof style.color === 'string') result.color = style.color
|
|
319
|
+
if (style.link && typeof style.link === 'string') result.link = style.link
|
|
320
|
+
return result
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/** 解析 opus 段落中的文本节点为 RichTextNode 数组。 */
|
|
324
|
+
const parseOpusTextNodes = (
|
|
325
|
+
nodes: NonNullable<NonNullable<BilibiliArticleContentResponse['data']>['opus']['content']['paragraphs'][number]['text']>['nodes'],
|
|
326
|
+
useDarkTheme?: boolean
|
|
327
|
+
): RichTextNode[] => {
|
|
328
|
+
const result: RichTextNode[] = []
|
|
329
|
+
for (const node of nodes) {
|
|
330
|
+
// node_type 4:站内图文高亮链接,官方页面渲染成带图文图标的 <a>
|
|
331
|
+
if (node.node_type === 4) {
|
|
332
|
+
const link = node.link
|
|
333
|
+
if (!link?.show_text) {
|
|
334
|
+
logger.error(`[bilibili] opus 富文本遇到 node_type=4 但缺少 link 数据: ${JSON.stringify(node).slice(0, 500)}`)
|
|
335
|
+
continue
|
|
336
|
+
}
|
|
337
|
+
// 缺跳转地址时退化成普通文本,至少不丢正文
|
|
338
|
+
if (link.link) {
|
|
339
|
+
result.push(createOpusLinkNode(link.show_text, link.link))
|
|
340
|
+
} else {
|
|
341
|
+
result.push(createTextNode(link.show_text))
|
|
342
|
+
}
|
|
343
|
+
continue
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
if (node.node_type !== 1 || !node.word) {
|
|
347
|
+
// 记录未适配的节点类型
|
|
348
|
+
if (node.node_type !== undefined && node.node_type !== 1) {
|
|
349
|
+
logger.error(`[bilibili] opus 富文本遇到未适配的 node_type: ${node.node_type},节点数据: ${JSON.stringify(node).slice(0, 500)}`)
|
|
350
|
+
}
|
|
351
|
+
continue
|
|
352
|
+
}
|
|
353
|
+
const words = node.word.words || ''
|
|
354
|
+
if (!words) continue
|
|
355
|
+
|
|
356
|
+
const style = extractWordStyle(node.word.style || {})
|
|
357
|
+
// 合并节点自带的颜色(根据主题选择 color 或 dark_color)
|
|
358
|
+
const colorValue = useDarkTheme ? node.word.dark_color : node.word.color
|
|
359
|
+
if (colorValue && !style.color) {
|
|
360
|
+
style.color = colorValue
|
|
361
|
+
}
|
|
362
|
+
// 注:B站 font_size 基于宽屏布局,模板固定宽度(w-360 / 实际 1440px 渲染后缩放)
|
|
363
|
+
// 直接映射会导致正文(17px)在模板中过小。字号统一由前端控制,后端不提取 font_size。
|
|
364
|
+
|
|
365
|
+
// 按换行符拆分
|
|
366
|
+
const parts = words.split(/(\r?\n)/)
|
|
367
|
+
for (const part of parts) {
|
|
368
|
+
if (part === '\r\n' || part === '\n') {
|
|
369
|
+
result.push(createLineBreakNode())
|
|
370
|
+
} else if (part) {
|
|
371
|
+
result.push(createTextNode(part, Object.keys(style).length > 0 ? style : undefined))
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
return result
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* 将 B 站专栏 opus 结构化数据解析为 RichTextDocument。
|
|
380
|
+
*/
|
|
381
|
+
const parseOpusToRichText = (
|
|
382
|
+
opus: NonNullable<BilibiliArticleContentResponse['data']>['opus'],
|
|
383
|
+
useDarkTheme?: boolean
|
|
384
|
+
): RichTextDocument => {
|
|
385
|
+
const nodes: RichTextNode[] = []
|
|
386
|
+
const paragraphs = opus?.content?.paragraphs
|
|
387
|
+
if (!Array.isArray(paragraphs)) {
|
|
388
|
+
return createRichTextDocument([], { platform: 'bilibili' })
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
let listBuffer: {
|
|
392
|
+
ordered: boolean
|
|
393
|
+
items: RichTextNode[]
|
|
394
|
+
} | null = null
|
|
395
|
+
|
|
396
|
+
const flushList = () => {
|
|
397
|
+
if (listBuffer) {
|
|
398
|
+
nodes.push(createListNode(listBuffer.ordered, listBuffer.items as any))
|
|
399
|
+
listBuffer = null
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
for (const paragraph of paragraphs) {
|
|
404
|
+
const paraType = paragraph.para_type
|
|
405
|
+
|
|
406
|
+
// 图片段落
|
|
407
|
+
if (paraType === 2) {
|
|
408
|
+
flushList()
|
|
409
|
+
const pics = paragraph.pic?.pics
|
|
410
|
+
if (Array.isArray(pics)) {
|
|
411
|
+
for (const pic of pics) {
|
|
412
|
+
if (pic.url) {
|
|
413
|
+
nodes.push(createImageNode(fixImageUrl(pic.url), pic.alt || '专栏图片', pic.comment))
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
continue
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// 分隔线段落
|
|
421
|
+
if (paraType === 3) {
|
|
422
|
+
flushList()
|
|
423
|
+
nodes.push(createHorizontalRuleNode())
|
|
424
|
+
continue
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
// 链接卡片段落(包含视频卡片等)
|
|
428
|
+
if (paraType === 7) {
|
|
429
|
+
flushList()
|
|
430
|
+
const linkCard = paragraph.link_card
|
|
431
|
+
const card = linkCard?.card
|
|
432
|
+
if (card?.link) {
|
|
433
|
+
nodes.push(
|
|
434
|
+
createLinkCardNode(card.show_text || linkCard?.default_text || '链接卡片', card.link, {
|
|
435
|
+
cardType: String(card.link_type || ''),
|
|
436
|
+
meta: { bizId: card.biz_id, contentCard: card.content_card }
|
|
437
|
+
})
|
|
438
|
+
)
|
|
439
|
+
} else {
|
|
440
|
+
logger.error(`[bilibili] opus 富文本遇到 para_type=7 但缺少 link_card 数据: ${JSON.stringify(paragraph).slice(0, 500)}`)
|
|
441
|
+
}
|
|
442
|
+
continue
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
// 代码块段落
|
|
446
|
+
if (paraType === 8) {
|
|
447
|
+
flushList()
|
|
448
|
+
const code = paragraph.code
|
|
449
|
+
if (code?.content) {
|
|
450
|
+
nodes.push(createCodeBlockNode(code.content, code.lang || undefined))
|
|
451
|
+
} else {
|
|
452
|
+
logger.error(`[bilibili] opus 富文本遇到 para_type=8 但缺少 code 数据: ${JSON.stringify(paragraph).slice(0, 500)}`)
|
|
453
|
+
}
|
|
454
|
+
continue
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
// 文本段落或引用段落或标题段落
|
|
458
|
+
const textNodes = paragraph.text?.nodes
|
|
459
|
+
if (!Array.isArray(textNodes) || textNodes.length === 0) {
|
|
460
|
+
// 既不是已知块级类型,也没有文本节点——记录未适配的段落类型
|
|
461
|
+
const knownTypes = [1, 2, 3, 4, 7, 8, 9]
|
|
462
|
+
if (!knownTypes.includes(paraType)) {
|
|
463
|
+
logger.error(`[bilibili] opus 富文本遇到未适配的 para_type: ${paraType},段落数据: ${JSON.stringify(paragraph).slice(0, 500)}`)
|
|
464
|
+
}
|
|
465
|
+
continue
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
// 检查是否是标题段落(通过 format.heading_type、header 样式、或字体大小模拟)
|
|
469
|
+
const headingType = paragraph.format?.heading_type
|
|
470
|
+
const hasHeaderStyle = textNodes.some((n) => n.word?.style?.header && n.node_type === 1)
|
|
471
|
+
// B站有些文章通过 font_size / font_level 模拟标题(para_type 仍为 1)
|
|
472
|
+
const hasLargeFont = textNodes.some((n) => n.node_type === 1 && n.word?.font_size && n.word.font_size >= 20)
|
|
473
|
+
const hasXLargeLevel = textNodes.some((n) => n.node_type === 1 && ['xLarge', 'large'].includes(n.word?.font_level))
|
|
474
|
+
const isHeading = paraType === 9 || headingType !== undefined || hasHeaderStyle || hasLargeFont || hasXLargeLevel
|
|
475
|
+
// 根据 font_size 推断标题级别(用于纯字体模拟的标题)
|
|
476
|
+
const inferredHeadingLevel = (): number => {
|
|
477
|
+
const sizes = textNodes.filter((n) => n.node_type === 1 && n.word?.font_size).map((n) => n.word.font_size)
|
|
478
|
+
if (sizes.length === 0) return 2
|
|
479
|
+
const maxSize = Math.max(...sizes)
|
|
480
|
+
if (maxSize >= 26) return 1
|
|
481
|
+
if (maxSize >= 22) return 2
|
|
482
|
+
if (maxSize >= 20) return 3
|
|
483
|
+
return 2
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
// 检查段落中是否有 list 样式
|
|
487
|
+
const hasList = textNodes.some((n) => n.word?.style?.list && n.node_type === 1)
|
|
488
|
+
// 检查是否是引用段落
|
|
489
|
+
const isBlockquote = paraType === 4
|
|
490
|
+
|
|
491
|
+
const inlineNodes = parseOpusTextNodes(textNodes, useDarkTheme)
|
|
492
|
+
if (inlineNodes.length === 0) continue
|
|
493
|
+
|
|
494
|
+
if (isHeading) {
|
|
495
|
+
flushList()
|
|
496
|
+
// 优先使用 format.heading_type,其次是 style.header,最后是字体大小推断
|
|
497
|
+
let level = inferredHeadingLevel()
|
|
498
|
+
if (typeof headingType === 'number' && headingType >= 1 && headingType <= 6) {
|
|
499
|
+
level = headingType
|
|
500
|
+
} else if (hasHeaderStyle) {
|
|
501
|
+
const headerNode = textNodes.find((n) => n.word?.style?.header)
|
|
502
|
+
const headerLevel = headerNode?.word?.style?.header
|
|
503
|
+
if (typeof headerLevel === 'number' && headerLevel >= 1 && headerLevel <= 6) {
|
|
504
|
+
level = headerLevel
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
nodes.push(createHeadingNode(level as 1 | 2 | 3 | 4 | 5 | 6, inlineNodes))
|
|
508
|
+
} else if (isBlockquote) {
|
|
509
|
+
flushList()
|
|
510
|
+
nodes.push(createBlockquoteNode(inlineNodes))
|
|
511
|
+
} else if (hasList) {
|
|
512
|
+
// 确定列表类型(bullet / ordered)
|
|
513
|
+
const listNode = textNodes.find((n) => n.word?.style?.list)
|
|
514
|
+
const listType = listNode?.word?.style?.list
|
|
515
|
+
const ordered = listType === 'ordered'
|
|
516
|
+
|
|
517
|
+
if (!listBuffer || listBuffer.ordered !== ordered) {
|
|
518
|
+
flushList()
|
|
519
|
+
listBuffer = { ordered, items: [] }
|
|
520
|
+
}
|
|
521
|
+
listBuffer.items.push(createListItemNode(inlineNodes))
|
|
522
|
+
} else {
|
|
523
|
+
flushList()
|
|
524
|
+
nodes.push(createParagraphNode(inlineNodes))
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
flushList()
|
|
529
|
+
return createRichTextDocument(nodes, { platform: 'bilibili' })
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* 尽力解析 HTML content 为 RichTextDocument。
|
|
534
|
+
*
|
|
535
|
+
* 这是一个 "best effort" 解析器,覆盖常见标签:
|
|
536
|
+
* p, h1-h6, blockquote, ul/ol/li, img, br, b/strong, i/em, s/del, a, span(color)。
|
|
537
|
+
*/
|
|
538
|
+
const parseHtmlContentToRichText = (content: string): RichTextDocument => {
|
|
539
|
+
const nodes: RichTextNode[] = []
|
|
540
|
+
|
|
541
|
+
// 块级标签匹配:p, h1-h6, blockquote, ul, ol, li, img, br
|
|
542
|
+
// 把 content 拆分成块级标记和普通文本
|
|
543
|
+
const blockRegex = /<(\/?)(p|h([1-6])|blockquote|ul|ol|li|img|br)(\s[^>]*)?\/?>/gi
|
|
544
|
+
|
|
545
|
+
let lastIndex = 0
|
|
546
|
+
let match: RegExpExecArray | null
|
|
547
|
+
const stack: Array<{ tag: string; level?: 1 | 2 | 3 | 4 | 5 | 6; nodes: RichTextNode[] }> = []
|
|
548
|
+
let currentInline: RichTextNode[] = []
|
|
549
|
+
|
|
550
|
+
const flushInline = (): RichTextNode[] => {
|
|
551
|
+
const result = currentInline
|
|
552
|
+
currentInline = []
|
|
553
|
+
return result
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
const pushBlock = (node: RichTextNode) => {
|
|
557
|
+
if (stack.length > 0) {
|
|
558
|
+
stack[stack.length - 1].nodes.push(node)
|
|
559
|
+
} else {
|
|
560
|
+
nodes.push(node)
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
const parseInlineHtml = (html: string): RichTextNode[] => {
|
|
565
|
+
const result: RichTextNode[] = []
|
|
566
|
+
const inlineRegex = /<(\/?)(b|strong|i|em|s|del|a|span|br)(\s[^>]*)?>/gi
|
|
567
|
+
let inlineLast = 0
|
|
568
|
+
let inlineMatch: RegExpExecArray | null
|
|
569
|
+
const styleStack: RichTextInlineStyle[] = []
|
|
570
|
+
|
|
571
|
+
const currentStyle = (): RichTextInlineStyle | undefined => {
|
|
572
|
+
if (styleStack.length === 0) return undefined
|
|
573
|
+
return styleStack.reduce((acc, s) => ({ ...acc, ...s }), {})
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
const pushText = (text: string) => {
|
|
577
|
+
if (!text) return
|
|
578
|
+
const style = currentStyle()
|
|
579
|
+
// 按换行符拆分
|
|
580
|
+
const parts = text.split(/(\r?\n)/)
|
|
581
|
+
for (const part of parts) {
|
|
582
|
+
if (part === '\r\n' || part === '\n') {
|
|
583
|
+
result.push(createLineBreakNode())
|
|
584
|
+
} else if (part) {
|
|
585
|
+
result.push(createTextNode(part, style))
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
while ((inlineMatch = inlineRegex.exec(html)) !== null) {
|
|
591
|
+
const before = html.slice(inlineLast, inlineMatch.index)
|
|
592
|
+
pushText(before)
|
|
593
|
+
|
|
594
|
+
const isClose = inlineMatch[1] === '/'
|
|
595
|
+
const tag = inlineMatch[2].toLowerCase()
|
|
596
|
+
const attrs = inlineMatch[3] || ''
|
|
597
|
+
|
|
598
|
+
if (tag === 'br') {
|
|
599
|
+
result.push(createLineBreakNode())
|
|
600
|
+
} else if (!isClose) {
|
|
601
|
+
const style: RichTextInlineStyle = {}
|
|
602
|
+
if (tag === 'b' || tag === 'strong') style.bold = true
|
|
603
|
+
if (tag === 'i' || tag === 'em') style.italic = true
|
|
604
|
+
if (tag === 's' || tag === 'del') style.strike = true
|
|
605
|
+
if (tag === 'a') {
|
|
606
|
+
const hrefMatch = /href="([^"]*)"/.exec(attrs)
|
|
607
|
+
if (hrefMatch) style.link = hrefMatch[1]
|
|
608
|
+
}
|
|
609
|
+
if (tag === 'span') {
|
|
610
|
+
const colorMatch = /color:\s*([^;"]+)/.exec(attrs)
|
|
611
|
+
if (colorMatch) style.color = colorMatch[1].trim()
|
|
612
|
+
const styleAttrMatch = /style="([^"]*)"/.exec(attrs)
|
|
613
|
+
if (styleAttrMatch) {
|
|
614
|
+
const colorInStyle = /color:\s*([^;]+)/.exec(styleAttrMatch[1])
|
|
615
|
+
if (colorInStyle) style.color = colorInStyle[1].trim()
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
styleStack.push(style)
|
|
619
|
+
} else {
|
|
620
|
+
styleStack.pop()
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
inlineLast = inlineMatch.index + inlineMatch[0].length
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
pushText(html.slice(inlineLast))
|
|
627
|
+
return result
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
while ((match = blockRegex.exec(content)) !== null) {
|
|
631
|
+
// 块级标签之前的文本(如果在根层则忽略;如果在列表/引用内则作为文本)
|
|
632
|
+
const before = content.slice(lastIndex, match.index)
|
|
633
|
+
if (before && stack.length > 0) {
|
|
634
|
+
// 将文本解析为行内节点并入栈顶
|
|
635
|
+
const inlineNodes = parseInlineHtml(before)
|
|
636
|
+
currentInline.push(...inlineNodes)
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
const isClose = match[1] === '/'
|
|
640
|
+
const tag = match[2].toLowerCase()
|
|
641
|
+
const level = match[3] ? parseInt(match[3], 10) : undefined
|
|
642
|
+
const attrs = match[4] || ''
|
|
643
|
+
|
|
644
|
+
if (!isClose) {
|
|
645
|
+
if (tag === 'img') {
|
|
646
|
+
const srcMatch = /src="([^"]*)"/.exec(attrs)
|
|
647
|
+
if (srcMatch) {
|
|
648
|
+
const src = fixImageUrl(srcMatch[1])
|
|
649
|
+
const altMatch = /alt="([^"]*)"/.exec(attrs)
|
|
650
|
+
const alt = altMatch ? altMatch[1] : '专栏图片'
|
|
651
|
+
pushBlock(createImageNode(src, alt))
|
|
652
|
+
}
|
|
653
|
+
} else if (tag === 'br') {
|
|
654
|
+
currentInline.push(createLineBreakNode())
|
|
655
|
+
} else if (tag === 'li') {
|
|
656
|
+
// 列表项开始:把之前积累的 currentInline 清空
|
|
657
|
+
currentInline = []
|
|
658
|
+
stack.push({ tag: 'li', nodes: [] })
|
|
659
|
+
} else {
|
|
660
|
+
stack.push({ tag, level: level as 1 | 2 | 3 | 4 | 5 | 6, nodes: [] })
|
|
661
|
+
}
|
|
662
|
+
} else {
|
|
663
|
+
// 结束标签
|
|
664
|
+
if (tag === 'li') {
|
|
665
|
+
// 结束前还有 currentInline 里的内容
|
|
666
|
+
const inlineNodes = flushInline()
|
|
667
|
+
const itemNodes = stack.pop()?.nodes || []
|
|
668
|
+
pushBlock(createListItemNode([...itemNodes, ...inlineNodes]))
|
|
669
|
+
} else if (tag === 'p' || tag === 'h1' || tag === 'h2' || tag === 'h3' || tag === 'h4' || tag === 'h5' || tag === 'h6') {
|
|
670
|
+
const frame = stack.pop()
|
|
671
|
+
const inlineNodes = flushInline()
|
|
672
|
+
const childNodes = [...(frame?.nodes || []), ...inlineNodes]
|
|
673
|
+
if (tag.startsWith('h') && frame?.level) {
|
|
674
|
+
pushBlock(createHeadingNode(frame.level as 1 | 2 | 3 | 4 | 5 | 6, childNodes))
|
|
675
|
+
} else {
|
|
676
|
+
pushBlock(createParagraphNode(childNodes))
|
|
677
|
+
}
|
|
678
|
+
} else if (tag === 'blockquote') {
|
|
679
|
+
const frame = stack.pop()
|
|
680
|
+
const inlineNodes = flushInline()
|
|
681
|
+
pushBlock(createBlockquoteNode([...(frame?.nodes || []), ...inlineNodes]))
|
|
682
|
+
} else if (tag === 'ul' || tag === 'ol') {
|
|
683
|
+
const frame = stack.pop()
|
|
684
|
+
const items = (frame?.nodes || []).filter((n) => n.type === 'listItem')
|
|
685
|
+
pushBlock(createListNode(tag === 'ol', items as any))
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
lastIndex = match.index + match[0].length
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
// 尾部未闭合的普通文本
|
|
693
|
+
const tail = content.slice(lastIndex)
|
|
694
|
+
if (tail) {
|
|
695
|
+
const inlineNodes = parseInlineHtml(tail)
|
|
696
|
+
if (inlineNodes.length > 0) {
|
|
697
|
+
if (stack.length === 0) {
|
|
698
|
+
nodes.push(createParagraphNode(inlineNodes))
|
|
699
|
+
} else {
|
|
700
|
+
currentInline.push(...inlineNodes)
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
// 处理未闭合的栈(作为段落兜底)
|
|
706
|
+
while (stack.length > 0) {
|
|
707
|
+
const frame = stack.pop()
|
|
708
|
+
if (!frame) continue
|
|
709
|
+
const inlineNodes = flushInline()
|
|
710
|
+
const childNodes = [...(frame.nodes || []), ...inlineNodes]
|
|
711
|
+
if (frame.tag === 'li') {
|
|
712
|
+
pushBlock(createListItemNode(childNodes))
|
|
713
|
+
} else if (frame.tag.startsWith('h') && frame.level) {
|
|
714
|
+
pushBlock(createHeadingNode(frame.level, childNodes))
|
|
715
|
+
} else if (frame.tag === 'blockquote') {
|
|
716
|
+
pushBlock(createBlockquoteNode(childNodes))
|
|
717
|
+
} else {
|
|
718
|
+
pushBlock(createParagraphNode(childNodes))
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
return createRichTextDocument(nodes, { platform: 'bilibili' })
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
/**
|
|
726
|
+
* 构建 B 站专栏动态的富文本文档。
|
|
727
|
+
*
|
|
728
|
+
* opus 和 content 互斥:优先 opus,其次 content,都没有返回空 document。
|
|
729
|
+
*/
|
|
730
|
+
export const buildBilibiliArticleRichText = (
|
|
731
|
+
opus: NonNullable<BilibiliArticleContentResponse['data']>['opus'],
|
|
732
|
+
content: string | undefined,
|
|
733
|
+
useDarkTheme?: boolean
|
|
734
|
+
): RichTextDocument => {
|
|
735
|
+
if (opus?.content?.paragraphs) {
|
|
736
|
+
return parseOpusToRichText(opus, useDarkTheme)
|
|
737
|
+
}
|
|
738
|
+
if (content) {
|
|
739
|
+
return parseHtmlContentToRichText(content)
|
|
740
|
+
}
|
|
741
|
+
return createRichTextDocument([], { platform: 'bilibili' })
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
type RichTextForwardMessageOptions = {
|
|
745
|
+
title?: string
|
|
746
|
+
summary?: string
|
|
747
|
+
shareUrl?: string
|
|
748
|
+
imageResolver?: (src: string, index: number) => Promise<string> | string
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
const MAX_FORWARD_TEXT_LENGTH = 1800
|
|
752
|
+
|
|
753
|
+
const normalizeForwardText = (text: string): string => {
|
|
754
|
+
return text
|
|
755
|
+
.replace(/\r\n/g, '\n')
|
|
756
|
+
.replace(/[ \t]+\n/g, '\n')
|
|
757
|
+
.replace(/\n{3,}/g, '\n\n')
|
|
758
|
+
.trim()
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
const splitForwardText = (text: string): string[] => {
|
|
762
|
+
const chunks: string[] = []
|
|
763
|
+
let rest = text
|
|
764
|
+
|
|
765
|
+
while (rest.length > MAX_FORWARD_TEXT_LENGTH) {
|
|
766
|
+
let splitAt = rest.lastIndexOf('\n\n', MAX_FORWARD_TEXT_LENGTH)
|
|
767
|
+
if (splitAt < MAX_FORWARD_TEXT_LENGTH / 2) {
|
|
768
|
+
splitAt = rest.lastIndexOf('\n', MAX_FORWARD_TEXT_LENGTH)
|
|
769
|
+
}
|
|
770
|
+
if (splitAt < MAX_FORWARD_TEXT_LENGTH / 2) {
|
|
771
|
+
splitAt = MAX_FORWARD_TEXT_LENGTH
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
const chunk = rest.slice(0, splitAt).trim()
|
|
775
|
+
if (chunk) chunks.push(chunk)
|
|
776
|
+
rest = rest.slice(splitAt).trim()
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
if (rest) chunks.push(rest)
|
|
780
|
+
return chunks
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
const formatRichTextLink = (text: string, url?: string): string => {
|
|
784
|
+
if (!url || url === text) return text
|
|
785
|
+
return `${text} (${url})`
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
const inlineRichTextNodeToText = (node: RichTextNode): string => {
|
|
789
|
+
switch (node.type) {
|
|
790
|
+
case 'text':
|
|
791
|
+
case 'mention':
|
|
792
|
+
case 'searchKeyword':
|
|
793
|
+
case 'topic':
|
|
794
|
+
case 'at':
|
|
795
|
+
case 'lottery':
|
|
796
|
+
case 'vote':
|
|
797
|
+
case 'viewPicture':
|
|
798
|
+
case 'hashtag':
|
|
799
|
+
return node.text
|
|
800
|
+
case 'emoji':
|
|
801
|
+
return node.name
|
|
802
|
+
case 'webLink':
|
|
803
|
+
return formatRichTextLink(node.text, node.jumpUrl)
|
|
804
|
+
case 'opusLink':
|
|
805
|
+
return formatRichTextLink(node.text, node.url)
|
|
806
|
+
case 'lineBreak':
|
|
807
|
+
return '\n'
|
|
808
|
+
default:
|
|
809
|
+
return ''
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
/**
|
|
814
|
+
* 将共享富文本文档转换为 Karin 消息段。
|
|
815
|
+
*
|
|
816
|
+
* 这里用于专栏正文的合并转发:文本节点保留为 text,图片节点保留为 image,
|
|
817
|
+
* 让用户在客户端里能按原文顺序查看图文内容,而不是只能看渲染长图。
|
|
818
|
+
*/
|
|
819
|
+
export const buildBilibiliRichTextForwardMessage = async (
|
|
820
|
+
document: RichTextDocument,
|
|
821
|
+
options: RichTextForwardMessageOptions = {}
|
|
822
|
+
): Promise<ElementTypes[]> => {
|
|
823
|
+
const elements: ElementTypes[] = []
|
|
824
|
+
let textBuffer = ''
|
|
825
|
+
let imageIndex = 0
|
|
826
|
+
|
|
827
|
+
const appendText = (text: string) => {
|
|
828
|
+
if (!text) return
|
|
829
|
+
textBuffer += text
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
const ensureBlockBreak = () => {
|
|
833
|
+
if (!textBuffer) return
|
|
834
|
+
if (textBuffer.endsWith('\n\n')) return
|
|
835
|
+
textBuffer += textBuffer.endsWith('\n') ? '\n' : '\n\n'
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
const flushText = () => {
|
|
839
|
+
const text = normalizeForwardText(textBuffer)
|
|
840
|
+
textBuffer = ''
|
|
841
|
+
for (const chunk of splitForwardText(text)) {
|
|
842
|
+
elements.push(segment.text(chunk))
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
const appendChildren = async (nodes: RichTextNode[]) => {
|
|
847
|
+
for (const node of nodes) {
|
|
848
|
+
await appendNode(node)
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
const appendImage = async (src: string, caption?: string) => {
|
|
853
|
+
flushText()
|
|
854
|
+
const imageUrl = options.imageResolver ? await options.imageResolver(src, imageIndex) : src
|
|
855
|
+
imageIndex += 1
|
|
856
|
+
elements.push(segment.image(imageUrl))
|
|
857
|
+
if (caption) {
|
|
858
|
+
appendText(caption)
|
|
859
|
+
ensureBlockBreak()
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
const appendNode = async (node: RichTextNode): Promise<void> => {
|
|
864
|
+
const inlineText = inlineRichTextNodeToText(node)
|
|
865
|
+
if (inlineText) {
|
|
866
|
+
appendText(inlineText)
|
|
867
|
+
return
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
switch (node.type) {
|
|
871
|
+
case 'heading':
|
|
872
|
+
case 'paragraph':
|
|
873
|
+
case 'blockquote':
|
|
874
|
+
case 'listItem':
|
|
875
|
+
ensureBlockBreak()
|
|
876
|
+
await appendChildren(node.nodes)
|
|
877
|
+
ensureBlockBreak()
|
|
878
|
+
break
|
|
879
|
+
case 'image':
|
|
880
|
+
if (node.src) {
|
|
881
|
+
await appendImage(node.src, node.caption)
|
|
882
|
+
}
|
|
883
|
+
break
|
|
884
|
+
case 'list':
|
|
885
|
+
ensureBlockBreak()
|
|
886
|
+
for (const [index, item] of node.items.entries()) {
|
|
887
|
+
appendText(node.ordered ? `${index + 1}. ` : '- ')
|
|
888
|
+
await appendChildren(item.nodes)
|
|
889
|
+
appendText('\n')
|
|
890
|
+
}
|
|
891
|
+
ensureBlockBreak()
|
|
892
|
+
break
|
|
893
|
+
case 'codeBlock':
|
|
894
|
+
ensureBlockBreak()
|
|
895
|
+
appendText(node.content)
|
|
896
|
+
ensureBlockBreak()
|
|
897
|
+
break
|
|
898
|
+
case 'linkCard':
|
|
899
|
+
ensureBlockBreak()
|
|
900
|
+
appendText(formatRichTextLink(node.title, node.url))
|
|
901
|
+
ensureBlockBreak()
|
|
902
|
+
break
|
|
903
|
+
case 'horizontalRule':
|
|
904
|
+
ensureBlockBreak()
|
|
905
|
+
appendText('---')
|
|
906
|
+
ensureBlockBreak()
|
|
907
|
+
break
|
|
908
|
+
default:
|
|
909
|
+
break
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
const headerLines: string[] = []
|
|
914
|
+
if (options.title) headerLines.push(`标题:${options.title}`)
|
|
915
|
+
if (options.summary) headerLines.push(`简介:${options.summary}`)
|
|
916
|
+
if (options.shareUrl) headerLines.push(`链接:${options.shareUrl}`)
|
|
917
|
+
if (headerLines.length > 0) {
|
|
918
|
+
appendText(headerLines.join('\n'))
|
|
919
|
+
ensureBlockBreak()
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
await appendChildren(document.nodes)
|
|
923
|
+
flushText()
|
|
924
|
+
|
|
925
|
+
return elements
|
|
926
|
+
}
|