Skip to content

Commit

Permalink
feat: rsshub err retry
Browse files Browse the repository at this point in the history
  • Loading branch information
nexmoe committed Jan 20, 2024
1 parent ac08032 commit df1ec30
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 85 deletions.
17 changes: 11 additions & 6 deletions components/module/Image.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,27 @@ const props = defineProps<Props>()
const image = computed(() => getFirstImageSrc(props.module.content))
const text = computed(() => extractTextFromHTML(props.module.content))
function getOrigin(url: string) {
const urlx = new URL(url)
return urlx.origin.toString()
}
</script>

<template>
<div
class="module shu-card"
>
<div v-if="!section.noTitle" class="mx-7 mt-5 mb-3 font-bold tracking-tight text-black">
<div v-if="!section.noTitle" class="mx-6 mt-5 mb-3 font-bold tracking-tight text-black">
{{ props.module.title }}
</div>
<div v-if="props.module.platform && props.module.platform.length > 1" class="mx-7 mb-5 flex flex-row">
<div v-if="props.module.platform && props.module.platform.length > 1" class="mx-6 mb-5 flex flex-row">
<div
v-for="platform in props.module.platform" :key="platform" class="w-5 h-5 mr-1 block"
@click="navigateTo(platform, { open: { target: '_blank' }, external: true })"
>
<img
class="rounded-md outline-2 hover:outline" :src="`https://lib.xiaoshuapp.com/icon/x?url=${platform}`"
class="rounded-md outline-2 hover:outline" :src="`https://lib.xiaoshuapp.com/icon/x?url=${getOrigin(platform)}`"
:alt="module.title" referrerpolicy="no-referrer" loading="lazy"
>
</div>
Expand All @@ -33,16 +38,16 @@ const text = computed(() => extractTextFromHTML(props.module.content))
class="w-full" format="webp" :src="image" :alt="module.title" referrerpolicy="no-referrer" loading="lazy"
width="320px" height="200px"
/>
<div class="absolute pb-5 px-7 w-full bottom-0 left-0">
<div class="absolute pb-5 px-6 w-full bottom-0 left-0">
<UBadge color="white" variant="solid">
{{ formatDateTime(module.date) }}
</UBadge>
</div>
</div>
<div v-if="!section.noContent && text !== ' '" class="mx-7 my-5 max-h-16">
<div v-if="!section.noContent && text !== ' '" class="mx-6 my-5 max-h-16">
<div v-html="text" />
</div>
<div class="absolute bg-gradient-to-t from-white pt-7 pb-5 px-7 w-full bottom-0 left-0">
<div class="absolute bg-gradient-to-t from-white pt-7 pb-5 px-6 w-full bottom-0 left-0">
<UBadge v-if="!image" color="gray" variant="solid">
{{ formatDateTime(module.date) }}
</UBadge>
Expand Down
7 changes: 6 additions & 1 deletion composables/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,13 @@ export interface Project {
url: string
}


export interface Rsshub {
origin: string[]
}

export interface Configuration {
rsshub: string[]
rsshub: Rsshub
}

export interface Config {
Expand Down
8 changes: 5 additions & 3 deletions config/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"rsshub": [
"https: //lib.xiaoshuapp.com/rss"
]
"rsshub": {
"origin": [
"https://rss.nexmoe.com"
]
}
}
21 changes: 5 additions & 16 deletions config/flow.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@
"api": [
{
"adapter": "rsshubJson",
"url": "https://rss.nexmoe.com/juejin/column/7287429638019121208.json?limit=9&key=ZBu6acweLRwkKpycCmBK"
"url": "{rsshub}/juejin/column/7287429638019121208.json"
},
{
"adapter": "rsshubJson",
"url": "https://rss.nexmoe.com/zhihu/posts/people/nexmoe.json?&limit=9&key=ZBu6acweLRwkKpycCmBK"
"url": "{rsshub}/zhihu/posts/people/nexmoe.json"
},
{
"adapter": "rsshubJson",
Expand All @@ -60,29 +60,18 @@
"homepage": "https://juejin.cn/column/7287241187447308345",
"api": [
{
"url": "https://rss.nexmoe.com/juejin/column/7287241187447308345.json?limit=6&key=ZBu6acweLRwkKpycCmBK",
"url": "{rsshub}/juejin/column/7287241187447308345.json?limit=6&key=ZBu6acweLRwkKpycCmBK",
"adapter": "rsshubJson"
}
],
"title": "笔记"
},
{
"homepage": "https://m.okjike.com/users/7a751a1a-d2d1-492d-88fb-ed153c49105b",
"api": [
{
"adapter": "rsshubJson",
"url": "https://rss.nexmoe.com/jike/user/7a751a1a-d2d1-492d-88fb-ed153c49105b.json?limit=6&key=ZBu6acweLRwkKpycCmBK"
}
],
"title": "即刻",
"noTitle": true
},
{
"homepage": "https://x.com/nexmoe",
"api": [
{
"adapter": "rsshubJson",
"url": "https://rsshub.app/twitter/user/nexmoe.json?limit=6"
"url": "https://rsshub.app/twitter/user/nexmoe.json?limit=9"
}
],
"title": "Twitter",
Expand All @@ -93,7 +82,7 @@
"api": [
{
"adapter": "rsshubJson",
"url": "https://rss.nexmoe.com/163/music/user/playrecords/129387613/0.json?limit=9&key=ZBu6acweLRwkKpycCmBK"
"url": "{rsshub}/163/music/user/playrecords/129387613/0.json?limit=9&key=ZBu6acweLRwkKpycCmBK"
}
],
"title": "听歌总榜",
Expand Down
110 changes: 61 additions & 49 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,61 +1,73 @@
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
modules: [
'@nuxt/ui',
'@nuxt/image',
'nuxt-gtag',
'@pinia/nuxt',
'@model-w/sentry',
// '@nuxtjs/supabase',
modules: [
'@nuxt/ui',
'@nuxt/image',
'nuxt-gtag',
'@pinia/nuxt',
'@model-w/sentry',
// '@nuxtjs/supabase',
],
// supabase: {

// supabase: {
// redirect: false,
// },
sentry: {
dsn: 'https://8895d416e86e4f56fc7e32c78bfbf901@sentry.mixcm.com//4',
dsn: 'https://8895d416e86e4f56fc7e32c78bfbf901@sentry.mixcm.com//4',
},
gtag: {
id: 'G-JF2ZGKT7MM',

gtag: {
id: 'G-JF2ZGKT7MM',
},
experimental: {
inlineSSRStyles: false,

experimental: {
inlineSSRStyles: false,
},
ui: {
icons: 'all',

ui: {
icons: 'all',
},
image: {
screens: {
'xs': 48,
'sm': 128,
'md': 320,
'lg': 1024,
'xl': 1280,
'xxl': 1536,
'2xl': 1536,
},
domains: [
'i.dawnlab.me',
'xiaoshuapp.com',
'lib.xiaoshuapp.com',
'ipfs.xlog.app',
'cdn.dribbble.com',
'cdnv2.ruguoapp.com',
'p3.music.126.net',
'p4.music.126.net',
'picx.zhimg.com',
'nexmoe.com',
'pbs.twimg.com',
],
quality: 90,

image: {
screens: {
'xs': 48,
'sm': 128,
'md': 320,
'lg': 1024,
'xl': 1280,
'xxl': 1536,
'2xl': 1536,
},
domains: [
'i.dawnlab.me',
'xiaoshuapp.com',
'lib.xiaoshuapp.com',
'ipfs.xlog.app',
'cdn.dribbble.com',
'cdnv2.ruguoapp.com',
'p3.music.126.net',
'p4.music.126.net',
'picx.zhimg.com',
'nexmoe.com',
'pbs.twimg.com',
],
quality: 90,
},

imports: {
dirs: [
// Scan top-level modules
'composables',
// ... or scan modules nested one level deep with a specific name and file extension
'composables/*/index.{ts,js,mjs,mts}',
// ... or scan all modules within given directory
'composables/**',
],
},
imports: {
dirs: [
// Scan top-level modules
'composables',
// ... or scan modules nested one level deep with a specific name and file extension
'composables/*/index.{ts,js,mjs,mts}',
// ... or scan all modules within given directory
'composables/**',
],

devtools: {
timeline: {
enabled: true,
},
},
})
})
13 changes: 12 additions & 1 deletion pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ useHead({
<Head>
<Title>{{ config.hero.title }}</Title>
<Meta name="description" :content="config.hero.description" />
<Link
rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Noto+Serif+SC&display=swap"
media="all"
/>
</Head>
<div class="bg-[#fefefe]">
<!-- <div
Expand All @@ -29,13 +34,19 @@ useHead({
<Flow v-else :section="item" />
</section>
</UContainer>
<IndexFooter />
</div>
</div>
</div>
<IndexTool />
<IndexFooter />
</template>

<style>
body * {
font-family: Noto Serif SC;
}
</style>

<style scoped>
.sidebar {
@apply fixed w-0 lg:w-64 bg-white h-full;
Expand Down
Binary file modified public/favicon.ico
Binary file not shown.
60 changes: 51 additions & 9 deletions server/api/flow/[name].get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,41 @@ import useAdapter from '~/composables/filter/useAdapter'

// import { serverSupabaseClient } from '#supabase/server'

function levenshteinDistance(a: string, b: string) {
if (a.length === 0)
return b.length
if (b.length === 0)
return a.length

const matrix = Array.from(Array(a.length + 1), () =>
Array(b.length + 1).fill(0))

for (let i = 0; i <= a.length; i++)
matrix[i][0] = i

for (let j = 0; j <= b.length; j++)
matrix[0][j] = j

for (let i = 1; i <= a.length; i++) {
for (let j = 1; j <= b.length; j++) {
const cost = a[i - 1] === b[j - 1] ? 0 : 1
matrix[i][j] = Math.min(
matrix[i - 1][j] + 1,
matrix[i][j - 1] + 1,
matrix[i - 1][j - 1] + cost,
)
}
}

return matrix[a.length][b.length]
}

function mergeArrays(a: Module[], b: Module[]) {
for (const ele of b) {
const item = a.find(v => v.title === ele.title)

const item = a.find((v) => {
const similarity = 1 - levenshteinDistance(v.title, ele.title) / Math.max(v.title.length, ele.title.length)
return similarity >= 0.9 // 设置相似度阈值为90%
})
if (!item) {
a.push(ele)
}
Expand Down Expand Up @@ -48,17 +79,28 @@ export default defineEventHandler(async (event) => {

const tasks = flow.api.map((api) => {
return (async () => {
const apiUrl = api.url.replace('{rsshub}', config.rsshub[0])
const data = await $fetch<Record<string, any>>(apiUrl, {
method: 'GET',
parseResponse: JSON.parse,
})
return useAdapter(api.adapter, data).slice(0, 8)
let apiUrlRetry = api.url
let originIndex = 0
while (originIndex < config.rsshub.origin.length) {
apiUrlRetry = apiUrlRetry.replace('{rsshub}', config.rsshub.origin[originIndex])
try {
const dataRetry = await $fetch<Record<string, any>>(apiUrlRetry, {
method: 'GET',
parseResponse: JSON.parse,
})
return useAdapter(api.adapter, dataRetry).slice(0, 8)
}
catch (error) {
originIndex++
}
}
throw new Error('All retry attempts failed')
})()
})

const res = await Promise.allSettled(tasks)

const response = res.flatMap(r => r.status === 'fulfilled' ? [r.value] : [])
const response = res.flatMap(r => (r.status === 'fulfilled' ? [r.value] : []))
const final = response.reduce(mergeArrays, [])

// // store to supabase
Expand Down

0 comments on commit df1ec30

Please sign in to comment.