-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create GLM2对接教程.md * 添加GLM2接入教程 * Delete GLM2对接教程.md * Delete image.png * Delete openai_api.py * Delete openai_api_int4.py * Delete openai_api_int8.py * Create GLM2对接教程.md * 添加ChatGLM2接口 * Delete openai_api_int4.py * Delete openai_api_int8.py * Update openai_api.py * Update GLM2对接教程.md * 页面抓取接口 * Update package.json * Update fetchContent.ts * Delete GLM2对接教程.md * Delete openai_api.py --------- Co-authored-by: Archer <[email protected]>
- Loading branch information
Showing
3 changed files
with
54 additions
and
0 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
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,51 @@ | ||
// pages/api/fetchContent.ts | ||
import { NextApiRequest, NextApiResponse } from 'next'; | ||
import axios from 'axios'; | ||
import { JSDOM } from 'jsdom'; | ||
import { Readability } from '@mozilla/readability'; | ||
import { jsonRes } from '@/service/response'; | ||
|
||
const fetchContent = async (req: NextApiRequest, res: NextApiResponse) => { | ||
const { url } = req.body; | ||
if (!url) { | ||
return res.status(400).json({ error: 'URL is required' }); | ||
} | ||
|
||
try { | ||
const response = await axios.get(url, { | ||
httpsAgent: new (require('https').Agent)({ | ||
rejectUnauthorized: false, | ||
}), | ||
}); | ||
|
||
const dom = new JSDOM(response.data, { | ||
url, | ||
contentType: 'text/html', | ||
}); | ||
|
||
const reader = new Readability(dom.window.document); | ||
const article = reader.parse(); | ||
|
||
if (!article) { | ||
jsonRes(res, { | ||
code: 500, | ||
error: '页面获取失败或页面为空' | ||
}); | ||
return; | ||
} | ||
|
||
jsonRes(res, { | ||
code: 200, | ||
data: article.content | ||
}); | ||
|
||
} catch (error:any) { | ||
jsonRes(res, { | ||
code: 500, | ||
error: error | ||
}); | ||
} | ||
|
||
}; | ||
|
||
export default fetchContent; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.