@ttkit/daily-hot-api 0.0.0-stage → 0.1.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/.env.example +77 -0
- package/LICENSE +21 -0
- package/README.md +315 -2
- package/bin/daily-hot-api.js +25 -0
- package/dist/app.controller.d.ts +41 -0
- package/dist/app.controller.js +91 -0
- package/dist/app.controller.js.map +1 -0
- package/dist/app.module.d.ts +4 -0
- package/dist/app.module.js +44 -0
- package/dist/app.module.js.map +1 -0
- package/dist/app.service.d.ts +19 -0
- package/dist/app.service.js +57 -0
- package/dist/app.service.js.map +1 -0
- package/dist/cache/cache.module.d.ts +2 -0
- package/dist/cache/cache.module.js +52 -0
- package/dist/cache/cache.module.js.map +1 -0
- package/dist/cache/cache.service.d.ts +26 -0
- package/dist/cache/cache.service.js +163 -0
- package/dist/cache/cache.service.js.map +1 -0
- package/dist/cli/args.d.ts +24 -0
- package/dist/cli/args.js +261 -0
- package/dist/cli/args.js.map +1 -0
- package/dist/cli/commands/logs.d.ts +3 -0
- package/dist/cli/commands/logs.js +55 -0
- package/dist/cli/commands/logs.js.map +1 -0
- package/dist/cli/commands/restart.d.ts +3 -0
- package/dist/cli/commands/restart.js +62 -0
- package/dist/cli/commands/restart.js.map +1 -0
- package/dist/cli/commands/start.d.ts +3 -0
- package/dist/cli/commands/start.js +280 -0
- package/dist/cli/commands/start.js.map +1 -0
- package/dist/cli/commands/status.d.ts +3 -0
- package/dist/cli/commands/status.js +78 -0
- package/dist/cli/commands/status.js.map +1 -0
- package/dist/cli/commands/stop.d.ts +12 -0
- package/dist/cli/commands/stop.js +135 -0
- package/dist/cli/commands/stop.js.map +1 -0
- package/dist/cli/context.d.ts +4 -0
- package/dist/cli/context.js +3 -0
- package/dist/cli/context.js.map +1 -0
- package/dist/cli/env.d.ts +2 -0
- package/dist/cli/env.js +80 -0
- package/dist/cli/env.js.map +1 -0
- package/dist/cli/errors.d.ts +14 -0
- package/dist/cli/errors.js +25 -0
- package/dist/cli/errors.js.map +1 -0
- package/dist/cli/health.d.ts +2 -0
- package/dist/cli/health.js +44 -0
- package/dist/cli/health.js.map +1 -0
- package/dist/cli/help.d.ts +3 -0
- package/dist/cli/help.js +158 -0
- package/dist/cli/help.js.map +1 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +94 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/log-file.d.ts +8 -0
- package/dist/cli/log-file.js +58 -0
- package/dist/cli/log-file.js.map +1 -0
- package/dist/cli/output.d.ts +7 -0
- package/dist/cli/output.js +46 -0
- package/dist/cli/output.js.map +1 -0
- package/dist/cli/paths.d.ts +33 -0
- package/dist/cli/paths.js +76 -0
- package/dist/cli/paths.js.map +1 -0
- package/dist/cli/run-state.d.ts +25 -0
- package/dist/cli/run-state.js +159 -0
- package/dist/cli/run-state.js.map +1 -0
- package/dist/common/middlewares/logger.middleware.d.ts +7 -0
- package/dist/common/middlewares/logger.middleware.js +29 -0
- package/dist/common/middlewares/logger.middleware.js.map +1 -0
- package/dist/config/config.module.d.ts +2 -0
- package/dist/config/config.module.js +47 -0
- package/dist/config/config.module.js.map +1 -0
- package/dist/config/configuration.d.ts +3 -0
- package/dist/config/configuration.js +5 -0
- package/dist/config/configuration.js.map +1 -0
- package/dist/config/validation.schema.d.ts +114 -0
- package/dist/config/validation.schema.js +69 -0
- package/dist/config/validation.schema.js.map +1 -0
- package/dist/daily-brief/clients/ai-analysis.client.d.ts +20 -0
- package/dist/daily-brief/clients/ai-analysis.client.js +217 -0
- package/dist/daily-brief/clients/ai-analysis.client.js.map +1 -0
- package/dist/daily-brief/clients/brief-search.service.d.ts +11 -0
- package/dist/daily-brief/clients/brief-search.service.js +52 -0
- package/dist/daily-brief/clients/brief-search.service.js.map +1 -0
- package/dist/daily-brief/clients/deepseek-search.client.d.ts +11 -0
- package/dist/daily-brief/clients/deepseek-search.client.js +70 -0
- package/dist/daily-brief/clients/deepseek-search.client.js.map +1 -0
- package/dist/daily-brief/clients/tavily-search.client.d.ts +11 -0
- package/dist/daily-brief/clients/tavily-search.client.js +72 -0
- package/dist/daily-brief/clients/tavily-search.client.js.map +1 -0
- package/dist/daily-brief/daily-brief.config.d.ts +31 -0
- package/dist/daily-brief/daily-brief.config.js +108 -0
- package/dist/daily-brief/daily-brief.config.js.map +1 -0
- package/dist/daily-brief/daily-brief.controller.d.ts +72 -0
- package/dist/daily-brief/daily-brief.controller.js +169 -0
- package/dist/daily-brief/daily-brief.controller.js.map +1 -0
- package/dist/daily-brief/daily-brief.module.d.ts +2 -0
- package/dist/daily-brief/daily-brief.module.js +49 -0
- package/dist/daily-brief/daily-brief.module.js.map +1 -0
- package/dist/daily-brief/daily-brief.scheduler.d.ts +30 -0
- package/dist/daily-brief/daily-brief.scheduler.js +113 -0
- package/dist/daily-brief/daily-brief.scheduler.js.map +1 -0
- package/dist/daily-brief/daily-brief.service.d.ts +101 -0
- package/dist/daily-brief/daily-brief.service.js +412 -0
- package/dist/daily-brief/daily-brief.service.js.map +1 -0
- package/dist/daily-brief/dto/brief-date-param.dto.d.ts +3 -0
- package/dist/daily-brief/dto/brief-date-param.dto.js +23 -0
- package/dist/daily-brief/dto/brief-date-param.dto.js.map +1 -0
- package/dist/daily-brief/dto/generate-brief.dto.d.ts +6 -0
- package/dist/daily-brief/dto/generate-brief.dto.js +39 -0
- package/dist/daily-brief/dto/generate-brief.dto.js.map +1 -0
- package/dist/daily-brief/dto/list-briefs-query.dto.d.ts +6 -0
- package/dist/daily-brief/dto/list-briefs-query.dto.js +42 -0
- package/dist/daily-brief/dto/list-briefs-query.dto.js.map +1 -0
- package/dist/daily-brief/dto/stock-ranking-query.dto.d.ts +6 -0
- package/dist/daily-brief/dto/stock-ranking-query.dto.js +46 -0
- package/dist/daily-brief/dto/stock-ranking-query.dto.js.map +1 -0
- package/dist/daily-brief/interfaces/daily-brief.interface.d.ts +59 -0
- package/dist/daily-brief/interfaces/daily-brief.interface.js +3 -0
- package/dist/daily-brief/interfaces/daily-brief.interface.js.map +1 -0
- package/dist/daily-brief/interfaces/search-provider.interface.d.ts +11 -0
- package/dist/daily-brief/interfaces/search-provider.interface.js +3 -0
- package/dist/daily-brief/interfaces/search-provider.interface.js.map +1 -0
- package/dist/daily-brief/utils/brief-date.d.ts +2 -0
- package/dist/daily-brief/utils/brief-date.js +16 -0
- package/dist/daily-brief/utils/brief-date.js.map +1 -0
- package/dist/daily-brief/utils/concurrency.d.ts +1 -0
- package/dist/daily-brief/utils/concurrency.js +20 -0
- package/dist/daily-brief/utils/concurrency.js.map +1 -0
- package/dist/database/database.module.d.ts +2 -0
- package/dist/database/database.module.js +57 -0
- package/dist/database/database.module.js.map +1 -0
- package/dist/database/repositories/daily-brief.repository.d.ts +96 -0
- package/dist/database/repositories/daily-brief.repository.js +457 -0
- package/dist/database/repositories/daily-brief.repository.js.map +1 -0
- package/dist/database/repositories/hot-item.repository.d.ts +52 -0
- package/dist/database/repositories/hot-item.repository.js +255 -0
- package/dist/database/repositories/hot-item.repository.js.map +1 -0
- package/dist/database/repositories/source-config.repository.d.ts +15 -0
- package/dist/database/repositories/source-config.repository.js +77 -0
- package/dist/database/repositories/source-config.repository.js.map +1 -0
- package/dist/database/schemas/daily-brief.schema.d.ts +30 -0
- package/dist/database/schemas/daily-brief.schema.js +103 -0
- package/dist/database/schemas/daily-brief.schema.js.map +1 -0
- package/dist/database/schemas/hot-item.schema.d.ts +20 -0
- package/dist/database/schemas/hot-item.schema.js +72 -0
- package/dist/database/schemas/hot-item.schema.js.map +1 -0
- package/dist/database/schemas/source-config.schema.d.ts +15 -0
- package/dist/database/schemas/source-config.schema.js +47 -0
- package/dist/database/schemas/source-config.schema.js.map +1 -0
- package/dist/history/dto/history-response.dto.d.ts +17 -0
- package/dist/history/dto/history-response.dto.js +13 -0
- package/dist/history/dto/history-response.dto.js.map +1 -0
- package/dist/history/dto/search-history.dto.d.ts +10 -0
- package/dist/history/dto/search-history.dto.js +72 -0
- package/dist/history/dto/search-history.dto.js.map +1 -0
- package/dist/history/history.controller.d.ts +13 -0
- package/dist/history/history.controller.js +92 -0
- package/dist/history/history.controller.js.map +1 -0
- package/dist/history/history.module.d.ts +2 -0
- package/dist/history/history.module.js +25 -0
- package/dist/history/history.module.js.map +1 -0
- package/dist/history/history.service.d.ts +15 -0
- package/dist/history/history.service.js +68 -0
- package/dist/history/history.service.js.map +1 -0
- package/dist/host-lists/decorators/hot-source.decorator.d.ts +9 -0
- package/dist/host-lists/decorators/hot-source.decorator.js +11 -0
- package/dist/host-lists/decorators/hot-source.decorator.js.map +1 -0
- package/dist/host-lists/dto/hot-list.dto.d.ts +14 -0
- package/dist/host-lists/dto/hot-list.dto.js +94 -0
- package/dist/host-lists/dto/hot-list.dto.js.map +1 -0
- package/dist/host-lists/hot-lists.controller.d.ts +39 -0
- package/dist/host-lists/hot-lists.controller.js +87 -0
- package/dist/host-lists/hot-lists.controller.js.map +1 -0
- package/dist/host-lists/hot-lists.module.d.ts +2 -0
- package/dist/host-lists/hot-lists.module.js +36 -0
- package/dist/host-lists/hot-lists.module.js.map +1 -0
- package/dist/host-lists/hot-lists.service.d.ts +21 -0
- package/dist/host-lists/hot-lists.service.js +115 -0
- package/dist/host-lists/hot-lists.service.js.map +1 -0
- package/dist/host-lists/interfaces/hot-list-source.interface.d.ts +5 -0
- package/dist/host-lists/interfaces/hot-list-source.interface.js +3 -0
- package/dist/host-lists/interfaces/hot-list-source.interface.js.map +1 -0
- package/dist/host-lists/interfaces/hot-list.interface.d.ts +31 -0
- package/dist/host-lists/interfaces/hot-list.interface.js +3 -0
- package/dist/host-lists/interfaces/hot-list.interface.js.map +1 -0
- package/dist/host-lists/interfaces/router-data.interface.d.ts +19 -0
- package/dist/host-lists/interfaces/router-data.interface.js +3 -0
- package/dist/host-lists/interfaces/router-data.interface.js.map +1 -0
- package/dist/host-lists/sources/36kr.source.d.ts +9 -0
- package/dist/host-lists/sources/36kr.source.js +89 -0
- package/dist/host-lists/sources/36kr.source.js.map +1 -0
- package/dist/host-lists/sources/51cto.source.d.ts +11 -0
- package/dist/host-lists/sources/51cto.source.js +71 -0
- package/dist/host-lists/sources/51cto.source.js.map +1 -0
- package/dist/host-lists/sources/52pojie.source.d.ts +9 -0
- package/dist/host-lists/sources/52pojie.source.js +109 -0
- package/dist/host-lists/sources/52pojie.source.js.map +1 -0
- package/dist/host-lists/sources/acfun.source.d.ts +9 -0
- package/dist/host-lists/sources/acfun.source.js +90 -0
- package/dist/host-lists/sources/acfun.source.js.map +1 -0
- package/dist/host-lists/sources/baidu.source.d.ts +9 -0
- package/dist/host-lists/sources/baidu.source.js +85 -0
- package/dist/host-lists/sources/baidu.source.js.map +1 -0
- package/dist/host-lists/sources/bilibili.source.d.ts +14 -0
- package/dist/host-lists/sources/bilibili.source.js +188 -0
- package/dist/host-lists/sources/bilibili.source.js.map +1 -0
- package/dist/host-lists/sources/caixin.source.d.ts +9 -0
- package/dist/host-lists/sources/caixin.source.js +102 -0
- package/dist/host-lists/sources/caixin.source.js.map +1 -0
- package/dist/host-lists/sources/cls.source.d.ts +9 -0
- package/dist/host-lists/sources/cls.source.js +62 -0
- package/dist/host-lists/sources/cls.source.js.map +1 -0
- package/dist/host-lists/sources/coolapk.source.d.ts +9 -0
- package/dist/host-lists/sources/coolapk.source.js +57 -0
- package/dist/host-lists/sources/coolapk.source.js.map +1 -0
- package/dist/host-lists/sources/csdn.source.d.ts +9 -0
- package/dist/host-lists/sources/csdn.source.js +59 -0
- package/dist/host-lists/sources/csdn.source.js.map +1 -0
- package/dist/host-lists/sources/dgtle.source.d.ts +9 -0
- package/dist/host-lists/sources/dgtle.source.js +57 -0
- package/dist/host-lists/sources/dgtle.source.js.map +1 -0
- package/dist/host-lists/sources/douban-group.source.d.ts +11 -0
- package/dist/host-lists/sources/douban-group.source.js +100 -0
- package/dist/host-lists/sources/douban-group.source.js.map +1 -0
- package/dist/host-lists/sources/douban-movie.source.d.ts +10 -0
- package/dist/host-lists/sources/douban-movie.source.js +103 -0
- package/dist/host-lists/sources/douban-movie.source.js.map +1 -0
- package/dist/host-lists/sources/douyin.d.ts +16 -0
- package/dist/host-lists/sources/douyin.js +215 -0
- package/dist/host-lists/sources/douyin.js.map +1 -0
- package/dist/host-lists/sources/eastmoney-stock.source.d.ts +11 -0
- package/dist/host-lists/sources/eastmoney-stock.source.js +151 -0
- package/dist/host-lists/sources/eastmoney-stock.source.js.map +1 -0
- package/dist/host-lists/sources/eastmoney.source.d.ts +9 -0
- package/dist/host-lists/sources/eastmoney.source.js +86 -0
- package/dist/host-lists/sources/eastmoney.source.js.map +1 -0
- package/dist/host-lists/sources/geekpark.source.d.ts +9 -0
- package/dist/host-lists/sources/geekpark.source.js +60 -0
- package/dist/host-lists/sources/geekpark.source.js.map +1 -0
- package/dist/host-lists/sources/gelonghui.source.d.ts +9 -0
- package/dist/host-lists/sources/gelonghui.source.js +139 -0
- package/dist/host-lists/sources/gelonghui.source.js.map +1 -0
- package/dist/host-lists/sources/github.source.d.ts +12 -0
- package/dist/host-lists/sources/github.source.js +171 -0
- package/dist/host-lists/sources/github.source.js.map +1 -0
- package/dist/host-lists/sources/guokr.source.d.ts +11 -0
- package/dist/host-lists/sources/guokr.source.js +98 -0
- package/dist/host-lists/sources/guokr.source.js.map +1 -0
- package/dist/host-lists/sources/hackernews.source.d.ts +11 -0
- package/dist/host-lists/sources/hackernews.source.js +121 -0
- package/dist/host-lists/sources/hackernews.source.js.map +1 -0
- package/dist/host-lists/sources/hellogithub.source.d.ts +11 -0
- package/dist/host-lists/sources/hellogithub.source.js +98 -0
- package/dist/host-lists/sources/hellogithub.source.js.map +1 -0
- package/dist/host-lists/sources/history.source.d.ts +11 -0
- package/dist/host-lists/sources/history.source.js +92 -0
- package/dist/host-lists/sources/history.source.js.map +1 -0
- package/dist/host-lists/sources/honkai.source.d.ts +9 -0
- package/dist/host-lists/sources/honkai.source.js +72 -0
- package/dist/host-lists/sources/honkai.source.js.map +1 -0
- package/dist/host-lists/sources/hostloc.source.d.ts +9 -0
- package/dist/host-lists/sources/hostloc.source.js +75 -0
- package/dist/host-lists/sources/hostloc.source.js.map +1 -0
- package/dist/host-lists/sources/hupu.source.d.ts +9 -0
- package/dist/host-lists/sources/hupu.source.js +73 -0
- package/dist/host-lists/sources/hupu.source.js.map +1 -0
- package/dist/host-lists/sources/huxiu.source.d.ts +9 -0
- package/dist/host-lists/sources/huxiu.source.js +153 -0
- package/dist/host-lists/sources/huxiu.source.js.map +1 -0
- package/dist/host-lists/sources/ifanr.source.d.ts +9 -0
- package/dist/host-lists/sources/ifanr.source.js +57 -0
- package/dist/host-lists/sources/ifanr.source.js.map +1 -0
- package/dist/host-lists/sources/index.d.ts +2 -0
- package/dist/host-lists/sources/index.js +134 -0
- package/dist/host-lists/sources/index.js.map +1 -0
- package/dist/host-lists/sources/ithome-xijiayi.source.d.ts +9 -0
- package/dist/host-lists/sources/ithome-xijiayi.source.js +75 -0
- package/dist/host-lists/sources/ithome-xijiayi.source.js.map +1 -0
- package/dist/host-lists/sources/ithome.source.d.ts +9 -0
- package/dist/host-lists/sources/ithome.source.js +71 -0
- package/dist/host-lists/sources/ithome.source.js.map +1 -0
- package/dist/host-lists/sources/jd.source.d.ts +9 -0
- package/dist/host-lists/sources/jd.source.js +82 -0
- package/dist/host-lists/sources/jd.source.js.map +1 -0
- package/dist/host-lists/sources/jianshu.source.d.ts +9 -0
- package/dist/host-lists/sources/jianshu.source.js +72 -0
- package/dist/host-lists/sources/jianshu.source.js.map +1 -0
- package/dist/host-lists/sources/jin10.source.d.ts +9 -0
- package/dist/host-lists/sources/jin10.source.js +63 -0
- package/dist/host-lists/sources/jin10.source.js.map +1 -0
- package/dist/host-lists/sources/juejin.source.d.ts +10 -0
- package/dist/host-lists/sources/juejin.source.js +81 -0
- package/dist/host-lists/sources/juejin.source.js.map +1 -0
- package/dist/host-lists/sources/kuaishou.source.d.ts +13 -0
- package/dist/host-lists/sources/kuaishou.source.js +179 -0
- package/dist/host-lists/sources/kuaishou.source.js.map +1 -0
- package/dist/host-lists/sources/linuxdo.source.d.ts +9 -0
- package/dist/host-lists/sources/linuxdo.source.js +62 -0
- package/dist/host-lists/sources/linuxdo.source.js.map +1 -0
- package/dist/host-lists/sources/lol.source.d.ts +9 -0
- package/dist/host-lists/sources/lol.source.js +58 -0
- package/dist/host-lists/sources/lol.source.js.map +1 -0
- package/dist/host-lists/sources/miyoushe.source.d.ts +9 -0
- package/dist/host-lists/sources/miyoushe.source.js +88 -0
- package/dist/host-lists/sources/miyoushe.source.js.map +1 -0
- package/dist/host-lists/sources/netease-news.source.d.ts +9 -0
- package/dist/host-lists/sources/netease-news.source.js +56 -0
- package/dist/host-lists/sources/netease-news.source.js.map +1 -0
- package/dist/host-lists/sources/ngabbs.source.d.ts +9 -0
- package/dist/host-lists/sources/ngabbs.source.js +70 -0
- package/dist/host-lists/sources/ngabbs.source.js.map +1 -0
- package/dist/host-lists/sources/nodeseek.source.d.ts +9 -0
- package/dist/host-lists/sources/nodeseek.source.js +62 -0
- package/dist/host-lists/sources/nodeseek.source.js.map +1 -0
- package/dist/host-lists/sources/nytimes.source.d.ts +9 -0
- package/dist/host-lists/sources/nytimes.source.js +77 -0
- package/dist/host-lists/sources/nytimes.source.js.map +1 -0
- package/dist/host-lists/sources/producthunt.source.d.ts +9 -0
- package/dist/host-lists/sources/producthunt.source.js +75 -0
- package/dist/host-lists/sources/producthunt.source.js.map +1 -0
- package/dist/host-lists/sources/qq-news.source.d.ts +9 -0
- package/dist/host-lists/sources/qq-news.source.js +53 -0
- package/dist/host-lists/sources/qq-news.source.js.map +1 -0
- package/dist/host-lists/sources/sina-news.source.d.ts +9 -0
- package/dist/host-lists/sources/sina-news.source.js +98 -0
- package/dist/host-lists/sources/sina-news.source.js.map +1 -0
- package/dist/host-lists/sources/sina.source.d.ts +9 -0
- package/dist/host-lists/sources/sina.source.js +78 -0
- package/dist/host-lists/sources/sina.source.js.map +1 -0
- package/dist/host-lists/sources/smzdm.source.d.ts +9 -0
- package/dist/host-lists/sources/smzdm.source.js +71 -0
- package/dist/host-lists/sources/smzdm.source.js.map +1 -0
- package/dist/host-lists/sources/sspai.source.d.ts +9 -0
- package/dist/host-lists/sources/sspai.source.js +69 -0
- package/dist/host-lists/sources/sspai.source.js.map +1 -0
- package/dist/host-lists/sources/starrail.source.d.ts +9 -0
- package/dist/host-lists/sources/starrail.source.js +72 -0
- package/dist/host-lists/sources/starrail.source.js.map +1 -0
- package/dist/host-lists/sources/taobao.source.d.ts +10 -0
- package/dist/host-lists/sources/taobao.source.js +169 -0
- package/dist/host-lists/sources/taobao.source.js.map +1 -0
- package/dist/host-lists/sources/thepaper.source.d.ts +9 -0
- package/dist/host-lists/sources/thepaper.source.js +56 -0
- package/dist/host-lists/sources/thepaper.source.js.map +1 -0
- package/dist/host-lists/sources/tieba.source.d.ts +9 -0
- package/dist/host-lists/sources/tieba.source.js +58 -0
- package/dist/host-lists/sources/tieba.source.js.map +1 -0
- package/dist/host-lists/sources/tonghuashun.source.d.ts +9 -0
- package/dist/host-lists/sources/tonghuashun.source.js +112 -0
- package/dist/host-lists/sources/tonghuashun.source.js.map +1 -0
- package/dist/host-lists/sources/toutiao.source.d.ts +9 -0
- package/dist/host-lists/sources/toutiao.source.js +56 -0
- package/dist/host-lists/sources/toutiao.source.js.map +1 -0
- package/dist/host-lists/sources/v2ex.source.d.ts +9 -0
- package/dist/host-lists/sources/v2ex.source.js +67 -0
- package/dist/host-lists/sources/v2ex.source.js.map +1 -0
- package/dist/host-lists/sources/wallstreet.source.d.ts +9 -0
- package/dist/host-lists/sources/wallstreet.source.js +59 -0
- package/dist/host-lists/sources/wallstreet.source.js.map +1 -0
- package/dist/host-lists/sources/weatheralarm.source.d.ts +9 -0
- package/dist/host-lists/sources/weatheralarm.source.js +68 -0
- package/dist/host-lists/sources/weatheralarm.source.js.map +1 -0
- package/dist/host-lists/sources/weibo.source.d.ts +15 -0
- package/dist/host-lists/sources/weibo.source.js +180 -0
- package/dist/host-lists/sources/weibo.source.js.map +1 -0
- package/dist/host-lists/sources/weread.source.d.ts +9 -0
- package/dist/host-lists/sources/weread.source.js +82 -0
- package/dist/host-lists/sources/weread.source.js.map +1 -0
- package/dist/host-lists/sources/xinyu.source.d.ts +9 -0
- package/dist/host-lists/sources/xinyu.source.js +151 -0
- package/dist/host-lists/sources/xinyu.source.js.map +1 -0
- package/dist/host-lists/sources/yicai.source.d.ts +9 -0
- package/dist/host-lists/sources/yicai.source.js +113 -0
- package/dist/host-lists/sources/yicai.source.js.map +1 -0
- package/dist/host-lists/sources/yystv.source.d.ts +9 -0
- package/dist/host-lists/sources/yystv.source.js +57 -0
- package/dist/host-lists/sources/yystv.source.js.map +1 -0
- package/dist/host-lists/sources/zhihu-daily.source.d.ts +9 -0
- package/dist/host-lists/sources/zhihu-daily.source.js +60 -0
- package/dist/host-lists/sources/zhihu-daily.source.js.map +1 -0
- package/dist/host-lists/sources/zhihu.source.d.ts +12 -0
- package/dist/host-lists/sources/zhihu.source.js +195 -0
- package/dist/host-lists/sources/zhihu.source.js.map +1 -0
- package/dist/http/http.module.d.ts +2 -0
- package/dist/http/http.module.js +30 -0
- package/dist/http/http.module.js.map +1 -0
- package/dist/http/http.service.d.ts +53 -0
- package/dist/http/http.service.js +277 -0
- package/dist/http/http.service.js.map +1 -0
- package/dist/main.d.ts +3 -0
- package/dist/main.js +70 -0
- package/dist/main.js.map +1 -0
- package/dist/rss/rss.module.d.ts +2 -0
- package/dist/rss/rss.module.js +21 -0
- package/dist/rss/rss.module.js.map +1 -0
- package/dist/rss/rss.service.d.ts +5 -0
- package/dist/rss/rss.service.js +55 -0
- package/dist/rss/rss.service.js.map +1 -0
- package/dist/scheduler/dto/trigger-fetch.dto.d.ts +3 -0
- package/dist/scheduler/dto/trigger-fetch.dto.js +22 -0
- package/dist/scheduler/dto/trigger-fetch.dto.js.map +1 -0
- package/dist/scheduler/dto/update-source-config.dto.d.ts +4 -0
- package/dist/scheduler/dto/update-source-config.dto.js +29 -0
- package/dist/scheduler/dto/update-source-config.dto.js.map +1 -0
- package/dist/scheduler/scheduler.controller.d.ts +52 -0
- package/dist/scheduler/scheduler.controller.js +132 -0
- package/dist/scheduler/scheduler.controller.js.map +1 -0
- package/dist/scheduler/scheduler.module.d.ts +2 -0
- package/dist/scheduler/scheduler.module.js +34 -0
- package/dist/scheduler/scheduler.module.js.map +1 -0
- package/dist/scheduler/scheduler.service.d.ts +54 -0
- package/dist/scheduler/scheduler.service.js +238 -0
- package/dist/scheduler/scheduler.service.js.map +1 -0
- package/dist/scheduler/tasks/fetch-hot-data.task.d.ts +34 -0
- package/dist/scheduler/tasks/fetch-hot-data.task.js +175 -0
- package/dist/scheduler/tasks/fetch-hot-data.task.js.map +1 -0
- package/dist/token/coolapk.d.ts +11 -0
- package/dist/token/coolapk.js +40 -0
- package/dist/token/coolapk.js.map +1 -0
- package/dist/token/token.module.d.ts +2 -0
- package/dist/token/token.module.js +23 -0
- package/dist/token/token.module.js.map +1 -0
- package/dist/token/token.service.d.ts +19 -0
- package/dist/token/token.service.js +115 -0
- package/dist/token/token.service.js.map +1 -0
- package/dist/token/tools.d.ts +1 -0
- package/dist/token/tools.js +15 -0
- package/dist/token/tools.js.map +1 -0
- package/dist/token/weread.d.ts +2 -0
- package/dist/token/weread.js +55 -0
- package/dist/token/weread.js.map +1 -0
- package/dist/utils/getNum.d.ts +1 -0
- package/dist/utils/getNum.js +20 -0
- package/dist/utils/getNum.js.map +1 -0
- package/dist/utils/getTime.d.ts +11 -0
- package/dist/utils/getTime.js +134 -0
- package/dist/utils/getTime.js.map +1 -0
- package/dist/utils/headers.d.ts +16 -0
- package/dist/utils/headers.js +20 -0
- package/dist/utils/headers.js.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +12 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/parseRSS.d.ts +11 -0
- package/dist/utils/parseRSS.js +47 -0
- package/dist/utils/parseRSS.js.map +1 -0
- package/package.json +148 -4
- package/views/home.hbs +65 -0
|
@@ -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,gCAAS,EAAC;QACT,IAAI,EAAE,OAAO;QACb,KAAK,EAAE,KAAK;QACZ,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,2BAA2B;QACjC,WAAW,EACT,iEAAiE;KACpE,CAAC;qCAE0C,gCAAiB;GADhD,WAAW,CA6BvB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { HotListSource } from '../interfaces/hot-list-source.interface';
|
|
2
|
+
import { HotListGetListResponse } from '../interfaces/hot-list.interface';
|
|
3
|
+
import { HttpClientService } from '../../http/http.service';
|
|
4
|
+
import { GetListOptions } from './source.types';
|
|
5
|
+
export declare class ZhihuDailySource implements HotListSource {
|
|
6
|
+
private readonly httpService;
|
|
7
|
+
constructor(httpService: HttpClientService);
|
|
8
|
+
getList(options?: GetListOptions, noCache?: boolean): Promise<HotListGetListResponse>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ZhihuDailySource = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const hot_source_decorator_1 = require("../decorators/hot-source.decorator");
|
|
15
|
+
const http_service_1 = require("../../http/http.service");
|
|
16
|
+
let ZhihuDailySource = class ZhihuDailySource {
|
|
17
|
+
constructor(httpService) {
|
|
18
|
+
this.httpService = httpService;
|
|
19
|
+
}
|
|
20
|
+
async getList(options = {}, noCache) {
|
|
21
|
+
const url = 'https://daily.zhihu.com/api/4/news/latest';
|
|
22
|
+
const result = await this.httpService.get({
|
|
23
|
+
url,
|
|
24
|
+
noCache: noCache ?? options.noCache,
|
|
25
|
+
headers: {
|
|
26
|
+
Referer: 'https://daily.zhihu.com/api/4/news/latest',
|
|
27
|
+
Host: 'daily.zhihu.com',
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
const list = (result?.data?.stories || []).filter((el) => el.type === 0);
|
|
31
|
+
const data = list.map((v) => ({
|
|
32
|
+
id: v.id,
|
|
33
|
+
title: v.title,
|
|
34
|
+
cover: v.images?.[0] ?? undefined,
|
|
35
|
+
author: v.hint,
|
|
36
|
+
hot: undefined,
|
|
37
|
+
timestamp: undefined,
|
|
38
|
+
url: v.url,
|
|
39
|
+
mobileUrl: v.url,
|
|
40
|
+
}));
|
|
41
|
+
return {
|
|
42
|
+
data,
|
|
43
|
+
fromCache: result.fromCache,
|
|
44
|
+
updateTime: result.updateTime,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
exports.ZhihuDailySource = ZhihuDailySource;
|
|
49
|
+
exports.ZhihuDailySource = ZhihuDailySource = __decorate([
|
|
50
|
+
(0, common_1.Injectable)(),
|
|
51
|
+
(0, hot_source_decorator_1.HotSource)({
|
|
52
|
+
name: 'zhihu-daily',
|
|
53
|
+
title: '知乎日报',
|
|
54
|
+
type: '推荐榜',
|
|
55
|
+
link: 'https://daily.zhihu.com/',
|
|
56
|
+
description: '每天三次,每次七分钟',
|
|
57
|
+
}),
|
|
58
|
+
__metadata("design:paramtypes", [http_service_1.HttpClientService])
|
|
59
|
+
], ZhihuDailySource);
|
|
60
|
+
//# sourceMappingURL=zhihu-daily.source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zhihu-daily.source.js","sourceRoot":"","sources":["../../../src/host-lists/sources/zhihu-daily.source.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,6EAA+D;AAM/D,0DAA4D;AAWrD,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAC3B,YAA6B,WAA8B;QAA9B,gBAAW,GAAX,WAAW,CAAmB;IAAG,CAAC;IAE/D,KAAK,CAAC,OAAO,CACX,UAA0B,EAAE,EAC5B,OAAiB;QAEjB,MAAM,GAAG,GAAG,2CAA2C,CAAC;QACxD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,GAAG,CAEtC;YACD,GAAG;YACH,OAAO,EAAE,OAAO,IAAI,OAAO,CAAC,OAAO;YACnC,OAAO,EAAE;gBACP,OAAO,EAAE,2CAA2C;gBACpD,IAAI,EAAE,iBAAiB;aACxB;SACF,CAAC,CAAC;QACH,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC;QACzE,MAAM,IAAI,GAAkB,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YAC3C,EAAE,EAAE,CAAC,CAAC,EAAE;YACR,KAAK,EAAE,CAAC,CAAC,KAAK;YACd,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,IAAI,SAAS;YACjC,MAAM,EAAE,CAAC,CAAC,IAAI;YACd,GAAG,EAAE,SAAS;YACd,SAAS,EAAE,SAAS;YACpB,GAAG,EAAE,CAAC,CAAC,GAAG;YACV,SAAS,EAAE,CAAC,CAAC,GAAG;SACjB,CAAC,CAAC,CAAC;QACJ,OAAO;YACL,IAAI;YACJ,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,UAAU,EAAE,MAAM,CAAC,UAAU;SAC9B,CAAC;IACJ,CAAC;CACF,CAAA;AAnCY,4CAAgB;2BAAhB,gBAAgB;IAR5B,IAAA,mBAAU,GAAE;IACZ,IAAA,gCAAS,EAAC;QACT,IAAI,EAAE,aAAa;QACnB,KAAK,EAAE,MAAM;QACb,IAAI,EAAE,KAAK;QACX,IAAI,EAAE,0BAA0B;QAChC,WAAW,EAAE,YAAY;KAC1B,CAAC;qCAE0C,gCAAiB;GADhD,gBAAgB,CAmC5B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { HotListSource } from '../interfaces/hot-list-source.interface';
|
|
2
|
+
import { HotListGetListResponse } from '../interfaces/hot-list.interface';
|
|
3
|
+
import { HttpClientService } from '../../http/http.service';
|
|
4
|
+
import { GetListOptions } from './source.types';
|
|
5
|
+
export declare class ZhihuSource implements HotListSource {
|
|
6
|
+
private readonly httpService;
|
|
7
|
+
private readonly logger;
|
|
8
|
+
constructor(httpService: HttpClientService);
|
|
9
|
+
getList(options: GetListOptions, noCache?: boolean): Promise<HotListGetListResponse>;
|
|
10
|
+
private fetchFromAPI;
|
|
11
|
+
private fetchFromFallbackAPI;
|
|
12
|
+
}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var ZhihuSource_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.ZhihuSource = void 0;
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const hot_source_decorator_1 = require("../decorators/hot-source.decorator");
|
|
16
|
+
const http_service_1 = require("../../http/http.service");
|
|
17
|
+
const utils_1 = require("../../utils");
|
|
18
|
+
let ZhihuSource = ZhihuSource_1 = class ZhihuSource {
|
|
19
|
+
constructor(httpService) {
|
|
20
|
+
this.httpService = httpService;
|
|
21
|
+
this.logger = new common_1.Logger(ZhihuSource_1.name);
|
|
22
|
+
}
|
|
23
|
+
async getList(options, noCache) {
|
|
24
|
+
try {
|
|
25
|
+
const result = await this.fetchFromAPI(noCache ?? false);
|
|
26
|
+
return {
|
|
27
|
+
data: result.data,
|
|
28
|
+
params: {
|
|
29
|
+
type: {
|
|
30
|
+
name: '热搜类别',
|
|
31
|
+
type: {},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
fromCache: result.fromCache,
|
|
35
|
+
updateTime: result.updateTime,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
40
|
+
this.logger.error(`Failed to get list from API: ${errorMessage}`);
|
|
41
|
+
try {
|
|
42
|
+
const result = await this.fetchFromFallbackAPI(noCache ?? false);
|
|
43
|
+
return {
|
|
44
|
+
data: result.data,
|
|
45
|
+
params: {
|
|
46
|
+
type: {
|
|
47
|
+
name: '热搜类别',
|
|
48
|
+
type: {},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
fromCache: result.fromCache,
|
|
52
|
+
updateTime: result.updateTime,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
catch (fallbackError) {
|
|
56
|
+
const fallbackErrorMessage = fallbackError instanceof Error
|
|
57
|
+
? fallbackError.message
|
|
58
|
+
: 'Unknown error';
|
|
59
|
+
this.logger.error(`Failed to get list from fallback API: ${fallbackErrorMessage}`);
|
|
60
|
+
return {
|
|
61
|
+
data: [],
|
|
62
|
+
params: {
|
|
63
|
+
type: {
|
|
64
|
+
name: '热搜类别',
|
|
65
|
+
type: {},
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
fromCache: false,
|
|
69
|
+
updateTime: 0,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async fetchFromAPI(noCache) {
|
|
75
|
+
const url = 'https://api.zhihu.com/topstory/hot-list';
|
|
76
|
+
const headers = {
|
|
77
|
+
Accept: 'application/json, text/plain, */*',
|
|
78
|
+
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
|
|
79
|
+
Connection: 'keep-alive',
|
|
80
|
+
Referer: 'https://www.zhihu.com/hot',
|
|
81
|
+
Origin: 'https://www.zhihu.com',
|
|
82
|
+
'Sec-Fetch-Dest': 'empty',
|
|
83
|
+
'Sec-Fetch-Mode': 'cors',
|
|
84
|
+
'Sec-Fetch-Site': 'same-site',
|
|
85
|
+
'Sec-Ch-Ua': '"Google Chrome";v="119", "Chromium";v="119", "Not?A_Brand";v="24"',
|
|
86
|
+
'Sec-Ch-Ua-Mobile': '?0',
|
|
87
|
+
'Sec-Ch-Ua-Platform': '"macOS"',
|
|
88
|
+
'X-Requested-With': 'XMLHttpRequest',
|
|
89
|
+
'X-UDID': (0, utils_1.generateRandomId)(32),
|
|
90
|
+
'X-API-VERSION': '3.0.53',
|
|
91
|
+
};
|
|
92
|
+
const response = await this.httpService.get({
|
|
93
|
+
url,
|
|
94
|
+
headers,
|
|
95
|
+
params: {
|
|
96
|
+
limit: '50',
|
|
97
|
+
reverse_order: '0',
|
|
98
|
+
_t: Date.now().toString(),
|
|
99
|
+
},
|
|
100
|
+
noCache,
|
|
101
|
+
});
|
|
102
|
+
const apiData = response.data?.data || [];
|
|
103
|
+
const list = apiData
|
|
104
|
+
.map((v) => {
|
|
105
|
+
const data = v.target;
|
|
106
|
+
if (!data)
|
|
107
|
+
return null;
|
|
108
|
+
const q_id = v?.card_id?.split('_')?.[1] || data?.id || '';
|
|
109
|
+
return {
|
|
110
|
+
id: data.id || '',
|
|
111
|
+
title: data.title || '',
|
|
112
|
+
desc: data.excerpt || '',
|
|
113
|
+
cover: v.children?.[0]?.thumbnail || '',
|
|
114
|
+
timestamp: Date.now(),
|
|
115
|
+
hot: v.detail_text
|
|
116
|
+
? parseFloat(v.detail_text.split(' ')[0]) * 10000
|
|
117
|
+
: 0,
|
|
118
|
+
url: `https://www.zhihu.com/question/${q_id}`,
|
|
119
|
+
mobileUrl: `https://www.zhihu.com/question/${q_id}`,
|
|
120
|
+
};
|
|
121
|
+
})
|
|
122
|
+
.filter((item) => item !== null);
|
|
123
|
+
return {
|
|
124
|
+
data: list,
|
|
125
|
+
fromCache: response.fromCache,
|
|
126
|
+
updateTime: response.updateTime,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
async fetchFromFallbackAPI(noCache) {
|
|
130
|
+
const url = 'https://www.zhihu.com/api/v3/feed/topstory/hot-lists/total';
|
|
131
|
+
const headers = {
|
|
132
|
+
Accept: 'application/json, text/plain, */*',
|
|
133
|
+
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
|
|
134
|
+
Connection: 'keep-alive',
|
|
135
|
+
Referer: 'https://www.zhihu.com/hot',
|
|
136
|
+
Origin: 'https://www.zhihu.com',
|
|
137
|
+
'Sec-Fetch-Dest': 'empty',
|
|
138
|
+
'Sec-Fetch-Mode': 'cors',
|
|
139
|
+
'Sec-Fetch-Site': 'same-site',
|
|
140
|
+
'Sec-Ch-Ua': '"Google Chrome";v="119", "Chromium";v="119", "Not?A_Brand";v="24"',
|
|
141
|
+
'Sec-Ch-Ua-Mobile': '?0',
|
|
142
|
+
'Sec-Ch-Ua-Platform': '"macOS"',
|
|
143
|
+
'X-Requested-With': 'XMLHttpRequest',
|
|
144
|
+
'X-UDID': (0, utils_1.generateRandomId)(32),
|
|
145
|
+
'X-API-VERSION': '3.0.53',
|
|
146
|
+
};
|
|
147
|
+
const response = await this.httpService.get({
|
|
148
|
+
url,
|
|
149
|
+
headers,
|
|
150
|
+
params: {
|
|
151
|
+
limit: '50',
|
|
152
|
+
desktop: 'true',
|
|
153
|
+
_t: Date.now().toString(),
|
|
154
|
+
},
|
|
155
|
+
noCache,
|
|
156
|
+
});
|
|
157
|
+
const apiData = response.data?.data || [];
|
|
158
|
+
const list = apiData
|
|
159
|
+
.map((v) => {
|
|
160
|
+
const data = v.target;
|
|
161
|
+
if (!data)
|
|
162
|
+
return null;
|
|
163
|
+
const q_id = v?.card_id?.split('_')?.[1] || data?.id || '';
|
|
164
|
+
return {
|
|
165
|
+
id: data.id || '',
|
|
166
|
+
title: data.title || '',
|
|
167
|
+
desc: data.excerpt || '',
|
|
168
|
+
cover: v.children?.[0]?.thumbnail || '',
|
|
169
|
+
timestamp: Date.now(),
|
|
170
|
+
hot: v.detail_text
|
|
171
|
+
? parseFloat(v.detail_text.split(' ')[0]) * 10000
|
|
172
|
+
: 0,
|
|
173
|
+
url: `https://www.zhihu.com/question/${q_id}`,
|
|
174
|
+
mobileUrl: `https://www.zhihu.com/question/${q_id}`,
|
|
175
|
+
};
|
|
176
|
+
})
|
|
177
|
+
.filter((item) => item !== null);
|
|
178
|
+
return {
|
|
179
|
+
data: list,
|
|
180
|
+
fromCache: response.fromCache,
|
|
181
|
+
updateTime: response.updateTime,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
exports.ZhihuSource = ZhihuSource;
|
|
186
|
+
exports.ZhihuSource = ZhihuSource = ZhihuSource_1 = __decorate([
|
|
187
|
+
(0, common_1.Injectable)(),
|
|
188
|
+
(0, hot_source_decorator_1.HotSource)({
|
|
189
|
+
name: 'zhihu',
|
|
190
|
+
title: '知乎',
|
|
191
|
+
link: 'https://www.zhihu.com/hot',
|
|
192
|
+
}),
|
|
193
|
+
__metadata("design:paramtypes", [http_service_1.HttpClientService])
|
|
194
|
+
], ZhihuSource);
|
|
195
|
+
//# sourceMappingURL=zhihu.source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zhihu.source.js","sourceRoot":"","sources":["../../../src/host-lists/sources/zhihu.source.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAoD;AACpD,6EAA+D;AAM/D,0DAA4D;AAE5D,uCAA6C;AA+BtC,IAAM,WAAW,mBAAjB,MAAM,WAAW;IAGtB,YAA6B,WAA8B;QAA9B,gBAAW,GAAX,WAAW,CAAmB;QAF1C,WAAM,GAAG,IAAI,eAAM,CAAC,aAAW,CAAC,IAAI,CAAC,CAAC;IAEO,CAAC;IAE/D,KAAK,CAAC,OAAO,CACX,OAAuB,EACvB,OAAiB;QAEjB,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,IAAI,KAAK,CAAC,CAAC;YACzD,OAAO;gBACL,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,MAAM,EAAE;oBACN,IAAI,EAAE;wBACJ,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,EAAE;qBACT;iBACF;gBACD,SAAS,EAAE,MAAM,CAAC,SAAS;gBAC3B,UAAU,EAAE,MAAM,CAAC,UAAU;aAC9B,CAAC;QACJ,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACxB,MAAM,YAAY,GAChB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC;YAE3D,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,gCAAgC,YAAY,EAAE,CAAC,CAAC;YAElE,IAAI,CAAC;gBAEH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,oBAAoB,CA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, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.HttpClientModule = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const axios_1 = require("@nestjs/axios");
|
|
12
|
+
const http_service_1 = require("./http.service");
|
|
13
|
+
const cache_module_1 = require("../cache/cache.module");
|
|
14
|
+
let HttpClientModule = class HttpClientModule {
|
|
15
|
+
};
|
|
16
|
+
exports.HttpClientModule = HttpClientModule;
|
|
17
|
+
exports.HttpClientModule = HttpClientModule = __decorate([
|
|
18
|
+
(0, common_1.Module)({
|
|
19
|
+
imports: [
|
|
20
|
+
axios_1.HttpModule.register({
|
|
21
|
+
timeout: 6000,
|
|
22
|
+
maxRedirects: 5,
|
|
23
|
+
}),
|
|
24
|
+
cache_module_1.CacheModule,
|
|
25
|
+
],
|
|
26
|
+
providers: [http_service_1.HttpClientService],
|
|
27
|
+
exports: [http_service_1.HttpClientService],
|
|
28
|
+
})
|
|
29
|
+
], HttpClientModule);
|
|
30
|
+
//# sourceMappingURL=http.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.module.js","sourceRoot":"","sources":["../../src/http/http.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,yCAA2C;AAC3C,iDAAmD;AACnD,wDAAoD;AAa7C,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;CAAG,CAAA;AAAnB,4CAAgB;2BAAhB,gBAAgB;IAX5B,IAAA,eAAM,EAAC;QACN,OAAO,EAAE;YACP,kBAAU,CAAC,QAAQ,CAAC;gBAClB,OAAO,EAAE,IAAI;gBACb,YAAY,EAAE,CAAC;aAChB,CAAC;YACF,0BAAW;SACZ;QACD,SAAS,EAAE,CAAC,gCAAiB,CAAC;QAC9B,OAAO,EAAE,CAAC,gCAAiB,CAAC;KAC7B,CAAC;GACW,gBAAgB,CAAG"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { HttpService } from '@nestjs/axios';
|
|
2
|
+
import { CacheData, CacheService } from '../cache/cache.service';
|
|
3
|
+
import { ConfigService } from '@nestjs/config';
|
|
4
|
+
type ResponseData<T> = {
|
|
5
|
+
fromCache: boolean;
|
|
6
|
+
} & CacheData<T>;
|
|
7
|
+
export declare class HttpRequestError extends Error {
|
|
8
|
+
readonly url: string;
|
|
9
|
+
readonly status?: number | undefined;
|
|
10
|
+
constructor(message: string, url: string, status?: number | undefined);
|
|
11
|
+
}
|
|
12
|
+
export declare class HttpTimeoutError extends HttpRequestError {
|
|
13
|
+
constructor(url: string);
|
|
14
|
+
}
|
|
15
|
+
export declare class HttpNetworkError extends HttpRequestError {
|
|
16
|
+
constructor(url: string);
|
|
17
|
+
}
|
|
18
|
+
export interface BaseHttpRequestOptions {
|
|
19
|
+
url: string;
|
|
20
|
+
headers?: Record<string, string>;
|
|
21
|
+
noCache?: boolean;
|
|
22
|
+
ttl?: number;
|
|
23
|
+
timeout?: number;
|
|
24
|
+
retries?: number;
|
|
25
|
+
}
|
|
26
|
+
export interface HttpGetOptions extends BaseHttpRequestOptions {
|
|
27
|
+
params?: Record<string | number, string | number | boolean | undefined>;
|
|
28
|
+
responseType?: 'json' | 'text' | 'arraybuffer' | 'blob' | 'document' | 'stream';
|
|
29
|
+
}
|
|
30
|
+
export interface HttpPostOptions extends BaseHttpRequestOptions {
|
|
31
|
+
data?: Record<string, unknown>;
|
|
32
|
+
}
|
|
33
|
+
export declare class HttpClientService {
|
|
34
|
+
private readonly httpService;
|
|
35
|
+
private readonly cacheService;
|
|
36
|
+
private readonly configService;
|
|
37
|
+
private readonly logger;
|
|
38
|
+
private readonly inFlight;
|
|
39
|
+
constructor(httpService: HttpService, cacheService: CacheService, configService: ConfigService);
|
|
40
|
+
private stableSerialize;
|
|
41
|
+
private isVolatileKey;
|
|
42
|
+
private stableHeaders;
|
|
43
|
+
private stableData;
|
|
44
|
+
private cacheKey;
|
|
45
|
+
private singleFlight;
|
|
46
|
+
private retryDelay;
|
|
47
|
+
invalidateGet(options: HttpGetOptions): Promise<void>;
|
|
48
|
+
private getRandomUserAgent;
|
|
49
|
+
get<T = unknown>(options: HttpGetOptions): Promise<ResponseData<T>>;
|
|
50
|
+
post<T = unknown>(options: HttpPostOptions): Promise<ResponseData<T>>;
|
|
51
|
+
private handleHttpError;
|
|
52
|
+
}
|
|
53
|
+
export {};
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var HttpClientService_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.HttpClientService = exports.HttpNetworkError = exports.HttpTimeoutError = exports.HttpRequestError = void 0;
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const axios_1 = require("@nestjs/axios");
|
|
16
|
+
const cache_service_1 = require("../cache/cache.service");
|
|
17
|
+
const rxjs_1 = require("rxjs");
|
|
18
|
+
const axios_2 = require("axios");
|
|
19
|
+
const crypto_1 = require("crypto");
|
|
20
|
+
const config_1 = require("@nestjs/config");
|
|
21
|
+
const VOLATILE_REQUEST_KEYS = new Set([
|
|
22
|
+
'_',
|
|
23
|
+
'_signature',
|
|
24
|
+
'_t',
|
|
25
|
+
'mstoken',
|
|
26
|
+
'nonce',
|
|
27
|
+
'sign',
|
|
28
|
+
'signature',
|
|
29
|
+
'timestamp',
|
|
30
|
+
'token',
|
|
31
|
+
'w_rid',
|
|
32
|
+
'wts',
|
|
33
|
+
]);
|
|
34
|
+
const VOLATILE_HEADER_KEYS = new Set(['cookie', 'user-agent', 'x-udid']);
|
|
35
|
+
class HttpRequestError extends Error {
|
|
36
|
+
constructor(message, url, status) {
|
|
37
|
+
super(message);
|
|
38
|
+
this.url = url;
|
|
39
|
+
this.status = status;
|
|
40
|
+
this.name = 'HttpRequestError';
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.HttpRequestError = HttpRequestError;
|
|
44
|
+
class HttpTimeoutError extends HttpRequestError {
|
|
45
|
+
constructor(url) {
|
|
46
|
+
super(`Request timeout for ${url}`, url, 408);
|
|
47
|
+
this.name = 'HttpTimeoutError';
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.HttpTimeoutError = HttpTimeoutError;
|
|
51
|
+
class HttpNetworkError extends HttpRequestError {
|
|
52
|
+
constructor(url) {
|
|
53
|
+
super(`Network error for ${url}`, url);
|
|
54
|
+
this.name = 'HttpNetworkError';
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.HttpNetworkError = HttpNetworkError;
|
|
58
|
+
let HttpClientService = HttpClientService_1 = class HttpClientService {
|
|
59
|
+
constructor(httpService, cacheService, configService) {
|
|
60
|
+
this.httpService = httpService;
|
|
61
|
+
this.cacheService = cacheService;
|
|
62
|
+
this.configService = configService;
|
|
63
|
+
this.logger = new common_1.Logger(HttpClientService_1.name);
|
|
64
|
+
this.inFlight = new Map();
|
|
65
|
+
}
|
|
66
|
+
stableSerialize(value) {
|
|
67
|
+
if (Array.isArray(value)) {
|
|
68
|
+
return `[${value.map((item) => this.stableSerialize(item)).join(',')}]`;
|
|
69
|
+
}
|
|
70
|
+
if (value && typeof value === 'object') {
|
|
71
|
+
return `{${Object.entries(value)
|
|
72
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
73
|
+
.map(([key, item]) => `${JSON.stringify(key)}:${this.stableSerialize(item)}`)
|
|
74
|
+
.join(',')}}`;
|
|
75
|
+
}
|
|
76
|
+
return JSON.stringify(value) ?? 'null';
|
|
77
|
+
}
|
|
78
|
+
isVolatileKey(key) {
|
|
79
|
+
return VOLATILE_REQUEST_KEYS.has(key.toLowerCase());
|
|
80
|
+
}
|
|
81
|
+
stableHeaders(headers) {
|
|
82
|
+
return Object.fromEntries(Object.entries(headers ?? {})
|
|
83
|
+
.map(([key, value]) => [key.toLowerCase(), value])
|
|
84
|
+
.filter(([key]) => !VOLATILE_HEADER_KEYS.has(key)));
|
|
85
|
+
}
|
|
86
|
+
stableData(data) {
|
|
87
|
+
if (!data)
|
|
88
|
+
return undefined;
|
|
89
|
+
return Object.fromEntries(Object.entries(data).filter(([key]) => !this.isVolatileKey(key)));
|
|
90
|
+
}
|
|
91
|
+
cacheKey(method, options) {
|
|
92
|
+
const query = [];
|
|
93
|
+
let url = options.url;
|
|
94
|
+
try {
|
|
95
|
+
const parsed = new URL(options.url);
|
|
96
|
+
for (const [key, value] of parsed.searchParams) {
|
|
97
|
+
if (!this.isVolatileKey(key))
|
|
98
|
+
query.push([key, value]);
|
|
99
|
+
}
|
|
100
|
+
url = `${parsed.origin}${parsed.pathname}`;
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
}
|
|
104
|
+
const params = 'params' in options ? options.params : undefined;
|
|
105
|
+
for (const [key, value] of Object.entries(params ?? {})) {
|
|
106
|
+
if (!this.isVolatileKey(key))
|
|
107
|
+
query.push([key, value]);
|
|
108
|
+
}
|
|
109
|
+
const request = {
|
|
110
|
+
method,
|
|
111
|
+
url,
|
|
112
|
+
query: query.sort(([a], [b]) => a.localeCompare(b)),
|
|
113
|
+
headers: this.stableHeaders(options.headers),
|
|
114
|
+
data: 'data' in options ? this.stableData(options.data) : undefined,
|
|
115
|
+
responseType: 'responseType' in options ? options.responseType : undefined,
|
|
116
|
+
};
|
|
117
|
+
return `http:${(0, crypto_1.createHash)('sha256').update(this.stableSerialize(request)).digest('hex')}`;
|
|
118
|
+
}
|
|
119
|
+
async singleFlight(key, fetcher) {
|
|
120
|
+
const current = this.inFlight.get(key);
|
|
121
|
+
if (current !== undefined)
|
|
122
|
+
return current;
|
|
123
|
+
const pending = fetcher();
|
|
124
|
+
this.inFlight.set(key, pending);
|
|
125
|
+
try {
|
|
126
|
+
return await pending;
|
|
127
|
+
}
|
|
128
|
+
finally {
|
|
129
|
+
if (this.inFlight.get(key) === pending)
|
|
130
|
+
this.inFlight.delete(key);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
retryDelay(error, attempt) {
|
|
134
|
+
const status = error instanceof axios_2.AxiosError ? error.response?.status : undefined;
|
|
135
|
+
const retryable = error instanceof axios_2.AxiosError &&
|
|
136
|
+
(error.code === 'ECONNABORTED' ||
|
|
137
|
+
!error.response ||
|
|
138
|
+
status === 429 ||
|
|
139
|
+
(status !== undefined && status >= 500));
|
|
140
|
+
if (!retryable)
|
|
141
|
+
return (0, rxjs_1.throwError)(() => error);
|
|
142
|
+
return (0, rxjs_1.timer)(Math.min(2000, 250 * 2 ** (attempt - 1)) + Math.random() * 100);
|
|
143
|
+
}
|
|
144
|
+
async invalidateGet(options) {
|
|
145
|
+
await this.cacheService.del(this.cacheKey('GET', options));
|
|
146
|
+
}
|
|
147
|
+
getRandomUserAgent() {
|
|
148
|
+
const userAgents = [
|
|
149
|
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36',
|
|
150
|
+
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.1 Safari/605.1.15',
|
|
151
|
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.0',
|
|
152
|
+
'Mozilla/5.0 (iPhone; CPU iPhone OS 15_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/96.0.4664.53 Mobile/15E148 Safari/604.1',
|
|
153
|
+
'Mozilla/5.0 (Linux; Android 12; SM-G991B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Mobile Safari/537.36',
|
|
154
|
+
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36',
|
|
155
|
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Edge/96.0.1054.43 Safari/537.36',
|
|
156
|
+
];
|
|
157
|
+
return userAgents[Math.floor(Math.random() * userAgents.length)];
|
|
158
|
+
}
|
|
159
|
+
async get(options) {
|
|
160
|
+
const { url, headers = {}, params, noCache, ttl, timeout = this.configService.getOrThrow('REQUEST_TIMEOUT'), retries = 2, responseType = 'json', } = options;
|
|
161
|
+
const cacheKey = this.cacheKey('GET', options);
|
|
162
|
+
if (!noCache) {
|
|
163
|
+
const cachedData = await this.cacheService.get(cacheKey);
|
|
164
|
+
if (cachedData) {
|
|
165
|
+
this.logger.log(`📦 [Redis] Using cached data for ${cacheKey}`);
|
|
166
|
+
return {
|
|
167
|
+
...cachedData,
|
|
168
|
+
fromCache: true,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
const requestHeaders = { ...headers };
|
|
173
|
+
if (!requestHeaders['User-Agent']) {
|
|
174
|
+
requestHeaders['User-Agent'] = this.getRandomUserAgent();
|
|
175
|
+
}
|
|
176
|
+
return this.singleFlight(cacheKey, async () => {
|
|
177
|
+
try {
|
|
178
|
+
const response = await (0, rxjs_1.firstValueFrom)(this.httpService
|
|
179
|
+
.get(url, {
|
|
180
|
+
headers: requestHeaders,
|
|
181
|
+
params,
|
|
182
|
+
timeout,
|
|
183
|
+
responseType,
|
|
184
|
+
})
|
|
185
|
+
.pipe((0, rxjs_1.retry)({
|
|
186
|
+
count: retries,
|
|
187
|
+
delay: (error, attempt) => this.retryDelay(error, attempt),
|
|
188
|
+
}), (0, rxjs_1.catchError)((error) => {
|
|
189
|
+
throw this.handleHttpError(error, url);
|
|
190
|
+
})));
|
|
191
|
+
const cacheData = {
|
|
192
|
+
data: response.data,
|
|
193
|
+
updateTime: new Date().toISOString(),
|
|
194
|
+
fromCache: false,
|
|
195
|
+
};
|
|
196
|
+
this.logger.log(`🔄 [API] Fetching fresh data for ${cacheKey}`);
|
|
197
|
+
await this.cacheService.set(cacheKey, cacheData, ttl);
|
|
198
|
+
return cacheData;
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
this.logger.error(`❌ [API] Error fetching data for ${cacheKey}: ${error instanceof Error ? error.message : String(error)}`);
|
|
202
|
+
throw error;
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
async post(options) {
|
|
207
|
+
const { url, headers = {}, data = {}, noCache, ttl, timeout = this.configService.getOrThrow('REQUEST_TIMEOUT'), retries = 2, } = options;
|
|
208
|
+
const cacheKey = this.cacheKey('POST', options);
|
|
209
|
+
if (!noCache) {
|
|
210
|
+
const cachedData = await this.cacheService.get(cacheKey);
|
|
211
|
+
if (cachedData) {
|
|
212
|
+
this.logger.log(`📦 [Redis] Using cached data for ${cacheKey}`);
|
|
213
|
+
return {
|
|
214
|
+
...cachedData,
|
|
215
|
+
fromCache: true,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
const requestHeaders = { ...headers };
|
|
220
|
+
if (!requestHeaders['User-Agent']) {
|
|
221
|
+
requestHeaders['User-Agent'] = this.getRandomUserAgent();
|
|
222
|
+
}
|
|
223
|
+
return this.singleFlight(cacheKey, async () => {
|
|
224
|
+
try {
|
|
225
|
+
const response = await (0, rxjs_1.firstValueFrom)(this.httpService
|
|
226
|
+
.post(url, data, {
|
|
227
|
+
headers: requestHeaders,
|
|
228
|
+
timeout,
|
|
229
|
+
})
|
|
230
|
+
.pipe((0, rxjs_1.retry)({
|
|
231
|
+
count: retries,
|
|
232
|
+
delay: (error, attempt) => this.retryDelay(error, attempt),
|
|
233
|
+
}), (0, rxjs_1.catchError)((error) => {
|
|
234
|
+
throw this.handleHttpError(error, url);
|
|
235
|
+
})));
|
|
236
|
+
const cacheData = {
|
|
237
|
+
data: response.data,
|
|
238
|
+
updateTime: new Date().toISOString(),
|
|
239
|
+
fromCache: false,
|
|
240
|
+
};
|
|
241
|
+
this.logger.log(`🔄 [API] Fetching fresh data for ${cacheKey}`);
|
|
242
|
+
await this.cacheService.set(cacheKey, cacheData, ttl);
|
|
243
|
+
return cacheData;
|
|
244
|
+
}
|
|
245
|
+
catch (error) {
|
|
246
|
+
this.logger.error(`❌ [API] Error posting data for ${cacheKey}: ${error instanceof Error ? error.message : String(error)}`);
|
|
247
|
+
throw error;
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
handleHttpError(error, url) {
|
|
252
|
+
let upstream = 'upstream';
|
|
253
|
+
try {
|
|
254
|
+
upstream = new URL(url).origin;
|
|
255
|
+
}
|
|
256
|
+
catch {
|
|
257
|
+
}
|
|
258
|
+
if (error instanceof axios_2.AxiosError) {
|
|
259
|
+
if (error.code === 'ECONNABORTED') {
|
|
260
|
+
return new HttpTimeoutError(upstream);
|
|
261
|
+
}
|
|
262
|
+
if (error.response) {
|
|
263
|
+
return new HttpRequestError(`HTTP ${error.response.status}: ${error.response.statusText}`, upstream, error.response.status);
|
|
264
|
+
}
|
|
265
|
+
return new HttpNetworkError(upstream);
|
|
266
|
+
}
|
|
267
|
+
return new HttpRequestError(`Unexpected HTTP client error from ${upstream}`, upstream);
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
exports.HttpClientService = HttpClientService;
|
|
271
|
+
exports.HttpClientService = HttpClientService = HttpClientService_1 = __decorate([
|
|
272
|
+
(0, common_1.Injectable)(),
|
|
273
|
+
__metadata("design:paramtypes", [axios_1.HttpService,
|
|
274
|
+
cache_service_1.CacheService,
|
|
275
|
+
config_1.ConfigService])
|
|
276
|
+
], HttpClientService);
|
|
277
|
+
//# sourceMappingURL=http.service.js.map
|