-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
使twikoo支持Cloudflare worker的兼容性改动 (#695)
* Patch to allow Cloudflare workers to read environment variables * Move getDomPurify out of lib.js * Remove the env-var workaround that doesn't work * Complete all changes for Cloudflare compatibility * refactor: only require lib when needed 仅在需要时导入第三方依赖,避免某一个依赖出现兼容性问题而无法导入其他依赖。 --------- Co-authored-by: Tao Xin <alexander.xin@gmail.com> Co-authored-by: iMaeGoo <mail1st@qq.com>
- Loading branch information
1 parent
9dbf00c
commit fe59c26
Showing
11 changed files
with
143 additions
and
63 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
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 |
---|---|---|
@@ -1,39 +1,62 @@ | ||
const $ = require('cheerio') // jQuery 服务器版 | ||
const { AkismetClient } = require('akismet-api') // 反垃圾 API | ||
const CryptoJS = require('crypto-js') // 编解码 | ||
const FormData = require('form-data') // 图片上传 | ||
const { JSDOM } = require('jsdom') // document.window 服务器版 | ||
const axios = require('axios') // 发送 REST 请求 | ||
const bowser = require('bowser') // UserAgent 格式化 | ||
const createDOMPurify = require('dompurify') // 反 XSS | ||
const ipToRegion = require('@imaegoo/node-ip2region') // IP 属地查询 | ||
const marked = require('marked') // Markdown 解析 | ||
const md5 = require('blueimp-md5') // MD5 加解密 | ||
const nodemailer = require('nodemailer') // 发送邮件 | ||
const pushoo = require('pushoo').default // 即时消息通知 | ||
const tencentcloud = require('tencentcloud-sdk-nodejs') // 腾讯云 API NODEJS SDK | ||
const xml2js = require('xml2js') // XML 解析 | ||
|
||
function getDomPurify () { | ||
// 初始化反 XSS | ||
const window = new JSDOM('').window | ||
const DOMPurify = createDOMPurify(window) | ||
return DOMPurify | ||
} | ||
|
||
module.exports = { | ||
$, | ||
AkismetClient, | ||
CryptoJS, | ||
FormData, | ||
axios, | ||
bowser, | ||
getDomPurify, | ||
ipToRegion, | ||
marked, | ||
md5, | ||
nodemailer, | ||
pushoo, | ||
tencentcloud, | ||
xml2js | ||
getCheerio () { | ||
const $ = require('cheerio') // jQuery 服务器版 | ||
return $ | ||
}, | ||
getAkismetClient () { | ||
const { AkismetClient } = require('akismet-api') // 反垃圾 API | ||
return AkismetClient | ||
}, | ||
getCryptoJS () { | ||
const CryptoJS = require('crypto-js') // 编解码 | ||
return CryptoJS | ||
}, | ||
getFormData () { | ||
const FormData = require('form-data') // 图片上传 | ||
return FormData | ||
}, | ||
getAxios () { | ||
const axios = require('axios') // 发送 REST 请求 | ||
return axios | ||
}, | ||
getBowser () { | ||
const bowser = require('bowser') // UserAgent 格式化 | ||
return bowser | ||
}, | ||
getDomPurify () { | ||
// 初始化反 XSS | ||
const { JSDOM } = require('jsdom') // document.window 服务器版 | ||
const createDOMPurify = require('dompurify') // 反 XSS | ||
const window = new JSDOM('').window | ||
const DOMPurify = createDOMPurify(window) | ||
return DOMPurify | ||
}, | ||
getIpToRegion () { | ||
const ipToRegion = require('@imaegoo/node-ip2region') // IP 属地查询 | ||
return ipToRegion | ||
}, | ||
getMarked () { | ||
const marked = require('marked') // Markdown 解析 | ||
return marked | ||
}, | ||
getMd5 () { | ||
const md5 = require('blueimp-md5') // MD5 加解密 | ||
return md5 | ||
}, | ||
getNodemailer () { | ||
const nodemailer = require('nodemailer') // 发送邮件 | ||
return nodemailer | ||
}, | ||
getPushoo () { | ||
const pushoo = require('pushoo').default // 即时消息通知 | ||
return pushoo | ||
}, | ||
getTencentcloud () { | ||
const tencentcloud = require('tencentcloud-sdk-nodejs') // 腾讯云 API NODEJS SDK | ||
return tencentcloud | ||
}, | ||
getXml2js () { | ||
const xml2js = require('xml2js') // XML 解析 | ||
return xml2js | ||
} | ||
} |
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