forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
392 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -150,6 +150,7 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇 | |
- 最热/最新主题 | ||
- Telegram | ||
- 频道 | ||
- 贴纸包 | ||
- Readhub | ||
- 分类 | ||
- GitHub | ||
|
Empty file.
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 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 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 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 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,76 @@ | ||
const axios = require('../../utils/axios'); | ||
const config = require('../../config'); | ||
const logger = require('../../utils/logger'); | ||
const sharp = require('sharp'); | ||
const imgur = require('imgur'); | ||
const fs = require('fs'); | ||
|
||
if (config.imgur && config.imgur.clientId) { | ||
imgur.setClientId(config.imgur.clientId); | ||
} | ||
|
||
module.exports = async (ctx) => { | ||
const name = ctx.params.name; | ||
const cacheDays = 30; | ||
|
||
const response = await axios({ | ||
method: 'get', | ||
url: `https://api.telegram.org/bot${config.telegram.token}/getStickerSet?name=${name}`, | ||
}); | ||
|
||
const data = response.data.result; | ||
|
||
const links = await Promise.all( | ||
data.stickers.map(async (item) => { | ||
const key = `telegramstickerpack${item.file_id}`; | ||
const cache = await ctx.cache.get(key); | ||
if (cache) { | ||
return Promise.resolve(cache); | ||
} else { | ||
const pathResponse = await axios({ | ||
method: 'get', | ||
url: `https://api.telegram.org/bot${config.telegram.token}/getFile?file_id=${item.file_id}`, | ||
}); | ||
const path = pathResponse.data.result.file_path; | ||
|
||
const fileResponse = await axios({ | ||
method: 'get', | ||
url: `https://api.telegram.org/file/bot${config.telegram.token}/${path}`, | ||
responseType: 'arraybuffer', | ||
}); | ||
|
||
const filePath = `cache/${item.file_id}.png`; | ||
|
||
await sharp(fileResponse.data) | ||
.png() | ||
.toFile(filePath); | ||
|
||
let imgurResponse; | ||
try { | ||
imgurResponse = await imgur.uploadFile(filePath); | ||
} catch (e) { | ||
logger.error(`Error in imgur upload ${filePath}`, e); | ||
} | ||
const link = imgurResponse.data.link; | ||
|
||
fs.unlink(filePath, (e) => { | ||
logger.error(`Error in remove ${filePath}`, e); | ||
}); | ||
|
||
ctx.cache.set(key, link, cacheDays * 24 * 60 * 60); | ||
return Promise.resolve(link); | ||
} | ||
}) | ||
); | ||
|
||
ctx.state.data = { | ||
title: `${data.title} - Telegram Sticker Pack`, | ||
link: `https://t.me/addstickers/${name}`, | ||
item: data.stickers.map((item, index) => ({ | ||
title: item.emoji, | ||
description: `<img referrerpolicy="no-referrer" src="${links[index]}">`, | ||
guid: item.file_id, | ||
link: links[index], | ||
})), | ||
}; | ||
}; |
Oops, something went wrong.