add-unit-image

This commit is contained in:
user
2020-04-26 22:27:32 +08:00
parent 3047a31331
commit 7a56974e39

View File

@@ -12,7 +12,10 @@ module.exports = async (ctx) => {
const articledata = await Promise.all( const articledata = await Promise.all(
list.map(async (item) => { list.map(async (item) => {
const url = `https://www.unit-image.fr/data/en/wp-json/unitimage/v1${item.href}`; // 获取所有文章URL const url = `https://www.unit-image.fr/data/en/wp-json/unitimage/v1${item.href}`; // 获取所有文章URL
const cache = await ctx.cache.get(url); // 这里是不是单单缓存 URL
if (cache) {
return Promise.resolve(JSON.parse(cache)); // 如果有 URL 的缓存,则返回 JSON.phrase 的数据
}
const response2 = await got({ const response2 = await got({
method: 'get', method: 'get',
url, url,
@@ -63,6 +66,7 @@ module.exports = async (ctx) => {
compare, compare,
bhts, bhts,
}; };
ctx.cache.set(url, JSON.stringify(single)); // 设定缓存为序列化文章数据
return Promise.resolve(single); // 返回 articledata 为序列化文章数据。 return Promise.resolve(single); // 返回 articledata 为序列化文章数据。
}) })
); );