Compare commits

..

No commits in common. "3b8270e9a7fe22ac8478fa691c959e756438062c" and "ace5721457d61a16adc2a5400388c729d0d40138" have entirely different histories.

View File

@ -22,22 +22,23 @@ client.on("messageCreate", async message => {
for (let pixiv_url of pixiv_urls) { for (let pixiv_url of pixiv_urls) {
try { try {
let illust = Object.values(JSON.parse((await (await fetch(pixiv_url)).text()).match(/<meta name="preload-data" id="meta-preload-data" content='(.*)'>/)[1]).illust)[0]; let illust = Object.values(JSON.parse((await (await fetch(pixiv_url)).text()).match(/<meta name="preload-data" id="meta-preload-data" content='(.*)'>/)[1]).illust)[0];
let images = []; let image_urls = [];
for (let i = 0; i < illust.pageCount; i++) images.push({url: illust.urls.original.replace('p0', 'p'+i)}); for (let i = 0; i < illust.pageCount; i++) image_urls.push(illust.urls.original.replace('p0', 'p'+i));
if (images.length <= 10) { if (image_urls.length <= 10) {
try { try {
await message.channel.send({files: images.map(image => ({attachment: image.data = await (await fetch(image_url, {headers: {"Referer": "https://www.pixiv.net/"}})).buffer(), name: image.url.split('/').pop()}))}); let files = [];
for (let image_url of image_urls) {
files.push({attachment: await (await fetch(image_url,{headers:{"Referer":"https://www.pixiv.net/"}})).buffer(), name: image_url.split('/').pop()});
}
await message.channel.send({files});
} catch (error) { } catch (error) {
if (error.message == "Request entity too large") await fallback(); if (error.message == "Request entity too large") await fallback();
else throw error; else throw error;
} }
} else await fallback(); } else await fallback();
function fallback() { function fallback() {
// save the data already downloaded image_urls = image_urls.map(url => url.replace("https://i.pximg.net/", `https://${config.web_hostname}/pixiv-proxy/`));
for (let image of images) { return message.channel.send(image_urls.join("\n"));
fs.writeFileSync(config.data_dir + "pixiv-cache/" + image.url.split('?')[0].replace(/\//g, '\\'), image.data);
}
return message.channel.send(images.map(image => image.url.replace("https://i.pximg.net/", `https://${config.web_hostname}/pixiv-proxy/`)).join('\n'));
} }
} catch (error) { } catch (error) {
console.error("pixiv embed error,", error.stack); console.error("pixiv embed error,", error.stack);