一元网络论坛

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 105|回复: 0

利用该项目,将访客注册为独立账号,并使用Cloudflare Worker部署Fuclaude号池。

[复制链接]

3万

主题

3万

帖子

9万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
96169
发表于 2024-11-16 00:02:45 | 显示全部楼层 |阅读模式
基于开源项目修改的 Cloudflare Workers 部署的 Fuclaude 号池代码:
```javascript
const CONFIG = {
    ORIGINAL_WEBSITE: "https://demo.fuclaude.com",
    SESSION_KEYS: ["sk-ant", "sk-ant", "sk-ant", "sk-ant", "sk-ant", "sk-ant"],
    KEY_NAMES: ["c1", "c2", "c3", "c4", "c5", "c6"],
    SITE_PASSWORD: "password",
    GUEST_ACCOUNTS: {}
};
export default {
    async fetch(req, env, ctx) {
        return handleRequest(req);
    }
};
async function handleRequest(req) {
    const url = new URL(req.url);
    if (url.pathname === '/login') return handleRootPath(req, url, true);
    if (url.pathname === '/') return handleRootPath(req, url);
    return proxyRequest(req);
}
async function handleRootPath(req, url, forceLogin = false) {
    const cookie = req.headers.get('Cookie') || '';
    if (!forceLogin && cookie.includes('_Secure-next-auth.session-data')) return Response.redirect(`${url.origin}/new`, 302);
    if (req.method === 'POST') return handleLogin(req, url);
    return new Response(formHtml, { headers: { 'Content-Type': 'text/html; charset=utf-8' } });
}
async function handleLogin(req, url) {
    try {
        const formData = await req.formData();
        const loginType = formData.get('login_type');
        const selectedKeyIndex = formData.get('session_key_index');
        let body = { 'session_key': CONFIG.SESSION_KEYS[selectedKeyIndex] };
        if (loginType === 'site') {
            const sitePassword = formData.get('site_password');
            if (sitePassword !== CONFIG.SITE_PASSWORD) return new Response('站点密码错误', { status: 403, headers: { 'Content-Type': 'text/plain; charset=utf-8' } });
        } else if (loginType === 'guest') {
            const username = formData.get('username');
            const guestPassword = formData.get('guest_password');
            if (CONFIG.GUEST_ACCOUNTS[username.trim()] === undefined) return new Response('不存在该用户', { status: 400, headers: { 'Content-Type': 'text/plain; charset=utf-8' } });
            if (CONFIG.GUEST_ACCOUNTS[username] !== guestPassword) return new Response('密码错误', { status: 403, headers: { 'Content-Type': 'text/plain; charset=utf-8' } });
            body.unique_name = username;
        } else return new Response('无效的登录类型', { status: 400, headers: { 'Content-Type': 'text/plain; charset=utf-8' } });
        const authUrl = `${CONFIG.ORIGINAL_WEBSITE}/manage-api/auth/oauth_token`;
        const apiResponse = await fetch(authUrl, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) });
        if (!apiResponse.ok) throw new Error(`API request failed with status ${apiResponse.status}`);
        const respJson = await apiResponse.json();
        return Response.redirect(`https://${url.host}${respJson.login_url || '/'}`, 302);
    } catch (error) {
        console.error('Login error:', error);
        return new Response('登录错误', { status: 500, headers: { 'Content-Type': 'text/plain; charset=utf-8' } });
    }
}
async function proxyRequest(req) {
    const url = new URL(req.url);
    const newUrl = `${CONFIG.ORIGINAL_WEBSITE}${url.pathname}${url.search}`;
    const modifiedRequest = new Request(newUrl, req);
    const response = await fetch(modifiedRequest);
    const contentType = response.headers.get('content-type');
    if (contentType && contentType.includes('text/html') && url.pathname !== '/login_oauth') {
        let html = await response.text();
        html = html.replace(/]*>(?=[\s\S]*?)(?=[\s\S]*?)(?=[\s\S]*?)[\s\S]*?/gi, '');
        return new Response(html, { headers: response.headers });
    }
    return response;
}
// ... (formHtml remains the same) ...
```
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|一元网络论坛

GMT+8, 2024-12-28 02:49 , Processed in 0.055471 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表