diff --git a/docs/other.md b/docs/other.md
index 1899035ea5..48621f0929 100644
--- a/docs/other.md
+++ b/docs/other.md
@@ -438,7 +438,13 @@ type 为 all 时,category 参数不支持 cost 和 free
### 单读
-
+
+
+| 首页 | 文字 | 影像 | 声音 | 单向历 | 谈论 |
+| ---- | ---- | ---- | ---- | ------ | ---- |
+| 0 | 1 | 2 | 3 | 4 | 6 |
+
+
## 电商在线
diff --git a/lib/router.js b/lib/router.js
index c96bec2262..84d83bd112 100644
--- a/lib/router.js
+++ b/lib/router.js
@@ -1633,6 +1633,6 @@ router.get('/gouhuo/news/:category', require('./routes/gouhuo'));
router.get('/gouhuo/strategy', require('./routes/gouhuo/strategy'));
// 单向空间
-router.get('/owspace/read', require('./routes/owspace/read'));
+router.get('/owspace/read/:type?', require('./routes/owspace/read'));
module.exports = router;
diff --git a/lib/routes/owspace/read.js b/lib/routes/owspace/read.js
index cfe406a60d..2aad03be07 100644
--- a/lib/routes/owspace/read.js
+++ b/lib/routes/owspace/read.js
@@ -4,11 +4,21 @@ const qs = require('querystring');
const cheerio = require('cheerio');
const secret = 'fk4iy@98(*Y98fh-^o)re+wg=';
+
+const typeMap = {
+ 1: '文字',
+ 2: '影像',
+ 3: '声音',
+ 4: '单向历',
+ 6: '谈论',
+};
+
const signQuery = (query) => {
query.sign = md5(['apiname=', query.a, 'device_id=', query.device_id, 'time=', query.time, secret].join(''));
};
const generateFullText = async (item) => {
+ const model = parseInt(item.model);
const fullTextResponse = await got.get(item.html5);
const $ = cheerio.load(fullTextResponse.data);
@@ -17,29 +27,88 @@ const generateFullText = async (item) => {
let intro = '';
+ if (item.excerpt) {
+ intro += '
' + item.excerpt + '
';
+ }
+
if (item.thumbnail) {
intro += `
`;
}
- if (item.excerpt) {
- intro += '' + item.excerpt + '
';
- }
-
if (describe.length > 0) {
- intro += '' + describe.html() + '
';
+ intro += '' + describe.html() + '
';
}
+ if (intro) {
+ intro += '
';
+ }
+
+ // hide redundant meta
content.find('.articleTit').remove();
+ if (model === 2) {
+ // make video visible
+ content.find('.vBox').removeAttr('style');
+
+ content.find('.vBox video').attr('preload', 'metadata');
+ }
+
+ if (model === 3) {
+ // make audio visible
+ const audioContainer = content.find('.fmCon').removeAttr('style');
+
+ // generate audio player
+ $('')
+ .attr('src', item.fm)
+ .attr('preload', 'metadata')
+ .prependTo(audioContainer);
+
+ content.find('.fmCon>.graphic').remove();
+ content.find('.fmCon>.fmDetail').remove();
+ }
+
return intro + content.html();
};
+const handleItem = (ctx) => async (item) => {
+ if (parseInt(item.model) === 4) {
+ const result = {
+ title: item.title.substring(0, 4) + '年' + parseInt(item.title.substring(4, 6)) + '月' + parseInt(item.title.substring(6, 8)) + '日',
+ link: item.html5,
+ description: `
`,
+ pubDate: new Date(Number(item.create_time) * 1000).toUTCString(),
+ author: item.author,
+ };
+
+ return Promise.resolve(result);
+ } else {
+ const url = item.html5;
+ const cache = await ctx.cache.get(url);
+ if (cache) {
+ return Promise.resolve(JSON.parse(cache));
+ }
+
+ const result = {
+ title: item.title.replace('\r\n', ''),
+ link: item.html5,
+ description: await generateFullText(item),
+ pubDate: new Date(Number(item.create_time) * 1000).toUTCString(),
+ author: item.author,
+ };
+
+ ctx.cache.set(url, JSON.stringify(result));
+ return Promise.resolve(result);
+ }
+};
+
module.exports = async (ctx) => {
+ const selectedType = ctx.params.type !== undefined ? parseInt(ctx.params.type) : 0;
+
const queryData = {
c: 'api2',
a: 'getList',
p: '1',
- model: '0',
+ model: selectedType,
client: 'android',
version: '1.6.3',
time: Math.round(Date.now() / 1000),
@@ -61,32 +130,15 @@ module.exports = async (ctx) => {
throw response.data.msg ? 'api error: ' + response.data.msg : 'api error';
}
- const itemArray = await Promise.all(
- response.data.datas
- .filter((item) => item.model !== 5)
- .map(async (item) => {
- const url = item.html5;
- const cache = await ctx.cache.get(url);
- if (cache) {
- return Promise.resolve(JSON.parse(cache));
- }
+ const responseItemArray = response.data.datas.filter((item) => parseInt(item.model) !== 5);
- const result = {
- title: item.title.replace('\r\n', ''),
- link: item.html5,
- description: await generateFullText(item),
- pubDate: new Date(Number(item.create_time) * 1000).toUTCString(),
- author: item.author,
- };
+ const feedItemArray = await Promise.all(responseItemArray.map(handleItem(ctx)));
- ctx.cache.set(url, JSON.stringify(result));
- return Promise.resolve(result);
- })
- );
+ const selectedTypeName = typeMap[selectedType];
ctx.state.data = {
- title: '单读',
+ title: selectedTypeName ? `${selectedTypeName} - 单读` : '单读',
link: 'http://www.owspace.com/read.html',
- item: itemArray,
+ item: feedItemArray,
};
};