1 Star 1 Fork 2

李东平/rubick-ui-plugin-saladic

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
preload.js 1.87 KB
一键复制 编辑 原始数据 按行查看 历史
const shell = require("electron").shell;
const url = require('url').URL
//打开外部链接
window.openExternal = function (url) {
shell.openExternal(url);
};
//处理请求自定义cookie问题
const adapter = require("axios/lib/adapters/http");
const axiosCookieJarSupport = require("axios-cookiejar-support").default;
const tough = require("tough-cookie");
const CookieJar = new tough.CookieJar();
const axios = require("axios").create({
adapter,
headers:{
'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'
},
jar: CookieJar,
// proxy: {
// host: "localhost",
// port: 8888,
// },
withCredentials:true
});
tough._CookieJar = CookieJar;
// function setCookie(cookieStr, url){
// return new Promise((res, rej)=>{
// CookieJar.setCookie(cookieStr, url)
// })
// }
axiosCookieJarSupport(axios);
axios.interceptors.request.use(
(config) => {
//处理腾讯翻译君bug
let targetURl = new url(config.url)
let urlOrigin = targetURl.origin
config.headers.referer = urlOrigin;
// config.headers.origin = urlOrigin;
return config;
},
(error) => {
return Promise.reject(error);
}
);
axios.interceptors.response.use(
async (response) => {
// console.log("🚀 ~ file: preload.js ~ line 36 ~ response", response)
//处理有道翻译bug
let {headers, config} = response
let resSetCookie = headers['set-cookie']
if(resSetCookie && resSetCookie.length){
cookies = resSetCookie.map(tough.Cookie.parse);
for (let i of cookies){
await CookieJar.setCookie(i, config.url)
}
}
return response;
},
(error) => {
// console.log("🚀 ~ file: preload.js ~ line 40 ~ error", error)
return Promise.reject(error);
}
);
window.axios = axios;
window.tough = tough;
window.navigator.product === "NativeScript";
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ibm317/rubick-ui-plugin-saladic.git
git@gitee.com:ibm317/rubick-ui-plugin-saladic.git
ibm317
rubick-ui-plugin-saladic
rubick-ui-plugin-saladic
master

搜索帮助