-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): recover route konachan (#16934)
* feat(route): recover route konachan * fix(yande): correct maintainers list format * fix: namespace name ---------
- Loading branch information
Showing
5 changed files
with
93 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { Namespace } from '@/types'; | ||
|
||
export const namespace: Namespace = { | ||
name: 'Konachan.com Anime Wallpapers', | ||
url: 'konachan.com', | ||
description: `konachan post`, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { Route } from '@/types'; | ||
import got from '@/utils/got'; | ||
import queryString from 'query-string'; | ||
|
||
export const route: Route = { | ||
path: '/post/popular_recent/:period?', | ||
categories: ['picture'], | ||
example: '/konachan/post/popular_recent/1d', | ||
parameters: { | ||
period: '展示时间', | ||
}, | ||
radar: [ | ||
{ | ||
source: ['konachan.com/post'], | ||
}, | ||
], | ||
name: 'Popular Recent Posts', | ||
maintainers: ['magic-akari', 'NekoAria'], | ||
description: `| 最近 24 小时 | 最近一周 | 最近一月 | 最近一年 | | ||
| ------- | -------- | ------- | -------- | | ||
| 1d | 1w | 1m | 1y |`, | ||
handler, | ||
}; | ||
|
||
async function handler(ctx) { | ||
const { period = '1d' } = ctx.req.param(); | ||
|
||
const response = await got({ | ||
url: 'https://konachan.com/post/popular_recent.json', | ||
searchParams: queryString.stringify({ | ||
period, | ||
}), | ||
}); | ||
|
||
const posts = response.data; | ||
|
||
const titles = { | ||
'1d': 'Last 24 hours', | ||
'1w': 'Last week', | ||
'1m': 'Last month', | ||
'1y': 'Last year', | ||
}; | ||
|
||
const mime = { | ||
jpg: 'jpeg', | ||
png: 'png', | ||
}; | ||
|
||
const title = titles[period]; | ||
|
||
return { | ||
title: `${title} - konachan.com`, | ||
link: `https://konachan.com/post/popular_recent?period=${period}`, | ||
item: posts.map((post) => ({ | ||
title: post.tags, | ||
id: `${ctx.path}#${post.id}`, | ||
guid: `${ctx.path}#${post.id}`, | ||
link: `https://konachan.com/post/show/${post.id}`, | ||
author: post.author, | ||
pubDate: new Date(post.created_at * 1e3).toUTCString(), | ||
description: (() => { | ||
const result = [`<img src="${post.sample_url}" />`]; | ||
result.push(`<p>Rating:${post.rating}</p> <p>Score:${post.score}</p>`); | ||
if (post.source) { | ||
result.push(`<a href="${post.source}">Source</a>`); | ||
} | ||
if (post.parent_id) { | ||
result.push(`<a href="https://konachan.com/post/show/${post.parent_id}">Parent</a>`); | ||
} | ||
return result.join(''); | ||
})(), | ||
media: { | ||
content: { | ||
url: post.file_url, | ||
type: `image/${mime[post.file_ext]}`, | ||
}, | ||
thumbnail: { | ||
url: post.preview_url, | ||
}, | ||
}, | ||
category: post.tags.split(/\s+/), | ||
})), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters