Skip to content

Commit

Permalink
imgur
Browse files Browse the repository at this point in the history
  • Loading branch information
sunwu51 committed Jun 8, 2024
1 parent d5d1262 commit 7617c6a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
**/target
**/.vscode/*
**/期货/*
**/.next
**/.next
/public/imgur/**
24 changes: 24 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"esbuild": "^0.21.4",
"esbuild-plugin-css-modules": "^0.3.0",
"framer-motion": "^11.2.10",
"https-proxy-agent": "^7.0.4",
"mdx-bundler": "^10.0.2",
"next": "14.2.3",
"node-fetch": "^3.3.2",
Expand Down
13 changes: 11 additions & 2 deletions rehypePlugins/rehype-image-src-modifier.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { visit } from 'unist-util-visit';
import fetch from 'node-fetch';
import fs from 'fs'
import path from 'path';
import { HttpsProxyAgent } from 'https-proxy-agent';

// const proxyUrl = 'http://localhost:7890';
// const agent = new HttpsProxyAgent(proxyUrl);

function rehypeImageSrcModifier() {
return (tree) => {
Expand Down Expand Up @@ -35,11 +39,16 @@ function rehypeImageSrcModifier() {
else if (src.startsWith('img')) {
node.properties.src = src.replace('img', '/oriimg/' + month);
}

// 如果本地启动无法翻墙,请注释掉下面imgur这段代码
else if (src.startsWith('https://i.imgur.com/')) {
let picName = src.replace('https://i.imgur.com/', '');
fetch(src).then(response => {
fetch(src, {agent: undefined, headers :{
"user-agent": "curl/7.84.0",
"accept": "*/*"
}}).then(response => {
if (!response.ok) {
console.error(`Failed to fetch ${url}: ${response.statusText}`);
throw new Error(`Failed to fetch ${src}: ${JSON.stringify(response)} ${response.status}`);
}
return response.buffer();
})
Expand Down

0 comments on commit 7617c6a

Please sign in to comment.