├── .gitignore ├── wrangler.toml ├── node-functions ├── [[...path]]..js └── index.js ├── edgeone.json ├── Dockerfile ├── package.json ├── vercel.json ├── .github └── workflows │ ├── docker-image.yml │ └── sync_fork.yml ├── danmu_api ├── server.js ├── esm-shim.js └── worker.test.js ├── README.md └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | package-lock.json 3 | node_modules 4 | .env 5 | -------------------------------------------------------------------------------- /wrangler.toml: -------------------------------------------------------------------------------- 1 | name = "danmu-api" 2 | main = "danmu_api/worker.js" 3 | compatibility_date = "2025-09-13" 4 | keep_vars = true -------------------------------------------------------------------------------- /node-functions/[[...path]]..js: -------------------------------------------------------------------------------- 1 | import { onRequest } from './index.js'; // 改为 onRequest,支持所有方法 2 | 3 | export { onRequest }; // 复用 index.js 的 onRequest -------------------------------------------------------------------------------- /edgeone.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "danmu-api", 3 | "outputDirectory": "./", 4 | "rewrites": [ 5 | { 6 | "source": "/", 7 | "destination": "/node-functions/index.js" 8 | }, 9 | { 10 | "source": "/*", 11 | "destination": "/node-functions/[[...path]].js" 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # 使用官方 Node.js 22 轻量版镜像作为基础镜像 2 | FROM node:22-alpine 3 | 4 | # 设置工作目录 5 | WORKDIR /app/danmu_api 6 | 7 | # 复制 package.json 和 package-lock.json(如果存在) 8 | COPY package*.json ./ 9 | 10 | # 安装项目依赖 11 | RUN npm install 12 | 13 | # 复制所有源代码 14 | COPY danmu_api/ . 15 | 16 | # 设置环境变量 TOKEN 默认值 17 | ENV TOKEN=87654321 18 | 19 | # 暴露端口 20 | EXPOSE 9321 21 | 22 | # 启动命令 23 | CMD ["node", "server.js"] -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "danmu-api-server", 3 | "version": "1.0.0", 4 | "description": "A danmu Node.js Express API server", 5 | "main": "danmu_api/server.js", 6 | "scripts": { 7 | "start": "node danmu_api/server.js" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "esbuild": "^0.25.10", 13 | "https-proxy-agent": "^7.0.6", 14 | "node-fetch": "^3.3.2" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /vercel.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 2, 3 | "builds": [ 4 | { 5 | "src": "danmu_api/worker.js", 6 | "use": "@vercel/node" 7 | } 8 | ], 9 | "routes": [ 10 | { 11 | "src": "/", 12 | "dest": "/danmu_api/worker.js" 13 | }, 14 | { 15 | "src": "/api/(.*)", 16 | "dest": "/danmu_api/worker.js" 17 | }, 18 | { 19 | "src": "/([^/]+)/api/(.*)", 20 | "dest": "/danmu_api/worker.js" 21 | }, 22 | { 23 | "src": "/(.*)", 24 | "dest": "/danmu_api/worker.js" 25 | } 26 | ] 27 | } -------------------------------------------------------------------------------- /.github/workflows/docker-image.yml: -------------------------------------------------------------------------------- 1 | name: Build and Push Docker Image to Docker Hub 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | pull_request: 8 | branches: 9 | - main 10 | 11 | jobs: 12 | build: 13 | runs-on: ubuntu-latest 14 | 15 | steps: 16 | # 检出代码 17 | - name: Checkout code 18 | uses: actions/checkout@v3 19 | 20 | # 从 worker.js 中读取版本号 21 | - name: Read version from worker.js 22 | id: version 23 | run: | 24 | VERSION=$(grep 'const VERSION' danmu_api/worker.js | sed -E 's/.*const VERSION = "(.*)".*/\1/') 25 | echo "VERSION=$VERSION" >> $GITHUB_ENV 26 | 27 | # 设置 Docker 镜像缓存(可选,加速构建) 28 | - name: Set up Docker Buildx 29 | uses: docker/setup-buildx-action@v2 30 | 31 | # 登录 Docker Hub 32 | - name: Login to Docker Hub 33 | uses: docker/login-action@v2 34 | with: 35 | username: ${{ secrets.DOCKER_USERNAME }} 36 | password: ${{ secrets.DOCKER_PASSWORD }} 37 | 38 | # 构建 Docker 镜像,并指定平台为 amd64 和 arm64,推送到 Docker Hub 39 | - name: Build and Push Docker image with version and latest tag 40 | run: | 41 | # 构建带版本号的镜像并推送 42 | docker buildx build --platform linux/amd64,linux/arm64 -t ${{ secrets.DOCKER_USERNAME }}/danmu-api:${{ env.VERSION }} --push . 43 | 44 | # 构建带 latest 标签的镜像并推送 45 | docker buildx build --platform linux/amd64,linux/arm64 -t ${{ secrets.DOCKER_USERNAME }}/danmu-api:latest --push . 46 | -------------------------------------------------------------------------------- /.github/workflows/sync_fork.yml: -------------------------------------------------------------------------------- 1 | name: Fork Sync 2 | 3 | permissions: 4 | contents: write 5 | 6 | on: 7 | schedule: 8 | - cron: "0 0 * * *" # 每天午夜执行 9 | workflow_dispatch: # 允许手动触发 10 | 11 | jobs: 12 | sync_with_upstream: 13 | name: Sync with Upstream 14 | runs-on: ubuntu-latest 15 | if: ${{ github.event.repository.fork }} 16 | 17 | steps: 18 | - name: Checkout target repo 19 | uses: actions/checkout@v4 20 | with: 21 | token: ${{ secrets.GITHUB_TOKEN }} 22 | 23 | - name: Sync Upstream 24 | uses: aormsby/Fork-Sync-With-Upstream-action@v3.4 25 | with: 26 | target_repo_token: ${{ secrets.GITHUB_TOKEN }} 27 | upstream_sync_repo: huangxd-/danmu_api 28 | upstream_sync_branch: main 29 | target_sync_branch: main 30 | test_mode: false 31 | 32 | - name: Check for new commits 33 | if: success() 34 | run: echo "Sync completed successfully" 35 | 36 | - name: Check for Failure 37 | if: failure() 38 | run: | 39 | echo "[Error] Sync failed. This might be due to:" 40 | echo "1. Changes in the upstream workflow file" 41 | echo "2. Merge conflicts that need manual resolution" 42 | echo "3. Network issues" 43 | echo "Please check the logs and consider manual sync if needed." 44 | exit 1 45 | -------------------------------------------------------------------------------- /node-functions/index.js: -------------------------------------------------------------------------------- 1 | import { handleRequest } from '../danmu_api/worker.js'; 2 | 3 | export const onRequest = async (context) => { 4 | const { request, env } = context; 5 | 6 | // 获取协议和主机名,使用属性访问而非 get 方法 7 | const baseUrl = `https://localhost`; 8 | 9 | // 调试:打印 headers 和原始 URL 10 | console.log('Request URL:', request.url); 11 | console.log('Request Headers:', request.headers); 12 | 13 | // 构造完整的 URL 14 | let fullUrl; 15 | try { 16 | let targetUrl = request.url; 17 | 18 | // 判断是否包含 node-functions/index.js,如果是则用 / 代替 19 | if (request.url.includes('node-functions/index.js')) { 20 | targetUrl = '/'; 21 | } 22 | 23 | fullUrl = new URL(targetUrl, baseUrl).toString(); 24 | console.log('Request fullUrl:', fullUrl); 25 | } catch (error) { 26 | console.error('URL Construction Error:', error); 27 | return new Response('Invalid URL', { status: 400 }); 28 | } 29 | 30 | // 创建新的 request 对象,替换 url 31 | const modifiedRequest = new Request(fullUrl, { 32 | method: request.method, 33 | headers: request.headers, 34 | body: JSON.stringify(request.body), 35 | redirect: request.redirect, 36 | credentials: request.credentials, 37 | cache: request.cache, 38 | mode: request.mode 39 | }); 40 | 41 | // 获取客户端 IP 地址 42 | let clientIp = 'unknown'; 43 | 44 | // 尝试从 EO-Connecting-IP 获取客户端 IP 45 | clientIp = request.headers['eo-connecting-ip']; 46 | if (!clientIp) { 47 | // 如果 EO-Connecting-IP 不存在,尝试从 X-Forwarded-For 获取 48 | const forwardedFor = request.headers['x-forwarded-for']; 49 | if (forwardedFor) { 50 | // X-Forwarded-For 可能包含多个 IP 地址,选择第一个(最原始客户端 IP) 51 | clientIp = forwardedFor.split(',')[0].trim(); 52 | } 53 | } 54 | 55 | // 传递修改后的 request 和 env 给 handleRequest 56 | return await handleRequest(modifiedRequest, env, "edgeone", clientIp); 57 | }; -------------------------------------------------------------------------------- /danmu_api/server.js: -------------------------------------------------------------------------------- 1 | // server.js - 智能服务器启动器:根据 Node.js 环境自动选择最优启动模式 2 | // 导入 ES module 兼容层(始终加载,但内部会根据需要启用) 3 | require('./esm-shim'); 4 | 5 | const http = require('http'); 6 | const https = require('https'); 7 | const url = require('url'); 8 | const { HttpsProxyAgent } = require('https-proxy-agent'); 9 | 10 | // --- 版本兼容性检测工具 --- 11 | // 辅助函数:比较两个版本号字符串 12 | function compareVersion(version1, version2) { 13 | const v1Parts = version1.split('.').map(Number); 14 | const v2Parts = version2.split('.').map(Number); 15 | 16 | for (let i = 0; i < Math.max(v1Parts.length, v2Parts.length); i++) { 17 | const v1Part = v1Parts[i] || 0; 18 | const v2Part = v2Parts[i] || 0; 19 | 20 | if (v1Part > v2Part) return 1; 21 | if (v1Part < v2Part) return -1; 22 | } 23 | 24 | return 0; 25 | } 26 | 27 | // 检测是否需要异步启动(兼容层模式) 28 | function needsAsyncStartup() { 29 | try { 30 | const nodeVersion = process.versions.node; 31 | // 检查 Node.js 版本是否 >= v20.19.0 (此版本及更高版本内置了 fetch API,对 node-fetch v3 的兼容性更好) 32 | const isNodeCompatible = compareVersion(nodeVersion, '20.19.0') >= 0; 33 | 34 | // 尝试检测已安装的 node-fetch 版本 35 | const packagePath = require.resolve('node-fetch/package.json'); 36 | const pkg = require(packagePath); 37 | // 检查 node-fetch 是否是 v3.x 版本 (v3.x 在旧版 Node.js 中可能存在一些加载问题) 38 | const isNodeFetchV3 = pkg.version.startsWith('3.'); 39 | 40 | // 核心逻辑:只有在 Node.js < v20.19.0 且同时使用 node-fetch v3 时,才需要特殊的异步启动(兼容层模式) 41 | const needsAsync = !isNodeCompatible && isNodeFetchV3; 42 | 43 | console.log(`[server] Environment check: Node ${nodeVersion}, node-fetch ${pkg.version}`); 44 | console.log(`[server] Node.js compatible (>=20.19.0): ${isNodeCompatible}`); 45 | console.log(`[server] node-fetch v3: ${isNodeFetchV3}`); 46 | console.log(`[server] Needs async startup: ${needsAsync}`); 47 | 48 | return needsAsync; 49 | 50 | } catch (e) { 51 | // 无法检测或者 node-fetch 不存在,使用同步启动 52 | console.log('[server] Cannot detect node-fetch, using sync startup'); 53 | return false; 54 | } 55 | } 56 | 57 | // --- 核心 HTTP 服务器(端口 9321)逻辑 --- 58 | // 创建主业务服务器实例(将 Node.js 请求转换为 Web API Request,并调用 worker.js 处理) 59 | function createServer() { 60 | // 导入所需的 fetch 兼容对象 61 | const fetch = require('node-fetch'); 62 | const { Request, Response } = fetch; 63 | // 导入核心请求处理逻辑 64 | const { handleRequest } = require('./worker.js'); // 直接导入 handleRequest 函数 65 | 66 | return http.createServer(async (req, res) => { 67 | try { 68 | // 构造完整的请求 URL 69 | const fullUrl = `http://${req.headers.host}${req.url}`; 70 | 71 | // 获取请求客户端的ip 72 | const clientIp = req.connection.remoteAddress || 'unknown'; 73 | 74 | // 异步读取 POST/PUT 请求的请求体 75 | let body; 76 | if (req.method === 'POST' || req.method === 'PUT') { 77 | body = await new Promise((resolve) => { 78 | let data = ''; 79 | req.on('data', chunk => data += chunk); 80 | req.on('end', () => resolve(data)); 81 | }); 82 | } 83 | 84 | // 创建一个 Web API 兼容的 Request 对象 85 | const webRequest = new Request(fullUrl, { 86 | method: req.method, 87 | headers: req.headers, 88 | body: body || undefined, // 对于 GET/HEAD 等请求,body 为 undefined 89 | }); 90 | 91 | // 调用核心处理函数,并标识平台为 "node" 92 | const webResponse = await handleRequest(webRequest, process.env, "node", clientIp); 93 | 94 | // 将 Web API Response 对象转换为 Node.js 响应 95 | res.statusCode = webResponse.status; 96 | // 设置响应头 97 | webResponse.headers.forEach((value, key) => { 98 | res.setHeader(key, value); 99 | }); 100 | // 发送响应体 101 | const responseText = await webResponse.text(); 102 | res.end(responseText); 103 | } catch (error) { 104 | console.error('Server error:', error); 105 | res.statusCode = 500; 106 | res.end('Internal Server Error'); 107 | } 108 | }); 109 | } 110 | 111 | // 代理服务器逻辑(用于5321端口) 112 | function createProxyServer() { 113 | return http.createServer((req, res) => { 114 | const queryObject = url.parse(req.url, true).query; 115 | 116 | if (queryObject.url) { 117 | const targetUrl = queryObject.url; 118 | console.log('Target URL:', targetUrl); 119 | 120 | // 从环境变量获取代理地址 121 | const proxyUrl = process.env.PROXY_URL; 122 | 123 | const urlObj = new URL(targetUrl); 124 | const options = { 125 | hostname: urlObj.hostname, 126 | port: urlObj.port || (urlObj.protocol === 'https:' ? 443 : 80), 127 | path: urlObj.pathname + urlObj.search, 128 | method: 'GET' 129 | }; 130 | 131 | // 如果设置了代理,则使用代理 132 | if (proxyUrl) { 133 | options.agent = new HttpsProxyAgent(proxyUrl); 134 | console.log('Using proxy:', proxyUrl); 135 | } else { 136 | console.log('No proxy configured, direct connection'); 137 | } 138 | 139 | const protocol = urlObj.protocol === 'https:' ? https : http; 140 | 141 | const proxyReq = protocol.request(options, (proxyRes) => { 142 | res.writeHead(proxyRes.statusCode, proxyRes.headers); 143 | proxyRes.pipe(res, { end: true }); 144 | }); 145 | 146 | proxyReq.on('error', (err) => { 147 | console.error('Proxy request error:', err); 148 | res.statusCode = 500; 149 | res.end('Proxy Error: ' + err.message); 150 | }); 151 | 152 | proxyReq.end(); 153 | } else { 154 | res.statusCode = 400; 155 | res.end('Bad Request: Missing URL parameter'); 156 | } 157 | }); 158 | } 159 | 160 | // --- 启动函数 --- 161 | // 同步启动(最优/默认路径,适用于常规已兼容环境) 162 | function startServerSync() { 163 | console.log('[server] Starting server synchronously (optimal path)'); 164 | 165 | // 启动主业务服务器 (9321) 166 | const server = createServer(); 167 | server.listen(9321, '0.0.0.0', () => { 168 | console.log('Server running on http://0.0.0.0:9321'); 169 | }); 170 | 171 | // 启动5321端口的代理服务 172 | const proxyServer = createProxyServer(); 173 | 174 | proxyServer.listen(5321, '0.0.0.0', () => { 175 | console.log('Proxy server running on http://0.0.0.0:5321'); 176 | }); 177 | } 178 | 179 | // 异步启动(兼容层模式路径,适用于 Node.js < v20.19.0 + node-fetch v3) 180 | async function startServerAsync() { 181 | try { 182 | console.log('[server] Starting server asynchronously (compatibility mode for Node.js <20.19.0 + node-fetch v3)'); 183 | 184 | // 预加载 node-fetch v3(解决特定环境下 node-fetch v3 的加载问题) 185 | if (typeof global.loadNodeFetch === 'function') { 186 | console.log('[server] Pre-loading node-fetch v3...'); 187 | await global.loadNodeFetch(); 188 | console.log('[server] node-fetch v3 loaded successfully'); 189 | } 190 | 191 | // 启动主业务服务器 (9321) 192 | const server = createServer(); 193 | server.listen(9321, '0.0.0.0', () => { 194 | console.log('Server running on http://0.0.0.0:9321 (compatibility mode)'); 195 | }); 196 | 197 | // 启动5321端口的代理服务 198 | const proxyServer = createProxyServer(); 199 | 200 | proxyServer.listen(5321, '0.0.0.0', () => { 201 | console.log('Proxy server running on http://0.0.0.0:5321 (compatibility mode)'); 202 | }); 203 | 204 | } catch (error) { 205 | console.error('[server] Failed to start server:', error); 206 | process.exit(1); 207 | } 208 | } 209 | 210 | // --- 启动决策逻辑 --- 211 | // 智能选择启动方式:如果环境需要兼容,则异步启动;否则同步启动。 212 | if (needsAsyncStartup()) { 213 | startServerAsync(); 214 | } else { 215 | startServerSync(); 216 | } 217 | -------------------------------------------------------------------------------- /danmu_api/esm-shim.js: -------------------------------------------------------------------------------- 1 | // danmu_api/esm-shim.js 2 | // 智能兼容 shim - 只在需要时才启用 3 | // 兼容 Node.js < v20.19.0 + node-fetch v3 的情况 4 | 5 | const Module = require('module'); 6 | const path = require('path'); 7 | const projectRoot = path.resolve(__dirname); 8 | 9 | // 比较版本号的辅助函数 10 | function compareVersion(version1, version2) { 11 | const v1Parts = version1.split('.').map(Number); 12 | const v2Parts = version2.split('.').map(Number); 13 | 14 | for (let i = 0; i < Math.max(v1Parts.length, v2Parts.length); i++) { 15 | const v1Part = v1Parts[i] || 0; 16 | const v2Part = v2Parts[i] || 0; 17 | 18 | if (v1Part > v2Part) return 1; 19 | if (v1Part < v2Part) return -1; 20 | } 21 | 22 | return 0; 23 | } 24 | 25 | // 环境检测函数 26 | function detectEnvironment() { 27 | const nodeVersion = process.versions.node; 28 | const isNodeCompatible = compareVersion(nodeVersion, '20.19.0') >= 0; 29 | 30 | let nodeFetchVersion = '2'; 31 | let isNodeFetchV3 = false; 32 | let needsShim = false; 33 | 34 | try { 35 | // 尝试检测 node-fetch 版本 36 | const packagePath = require.resolve('node-fetch/package.json'); 37 | const pkg = require(packagePath); 38 | nodeFetchVersion = pkg.version; 39 | isNodeFetchV3 = pkg.version.startsWith('3.'); 40 | 41 | // 核心逻辑:只有在 Node.js < v20.19.0 且使用 node-fetch v3 时才需要 shim 42 | needsShim = !isNodeCompatible && isNodeFetchV3; 43 | 44 | } catch (e) { 45 | // node-fetch 未安装或无法检测,假设不需要 shim 46 | needsShim = false; 47 | nodeFetchVersion = 'not found'; 48 | } 49 | 50 | return { 51 | nodeVersion, 52 | nodeFetchVersion, 53 | isNodeCompatible, 54 | isNodeFetchV3, 55 | needsShim 56 | }; 57 | } 58 | 59 | // 检测环境 60 | const env = detectEnvironment(); 61 | 62 | console.log(`[esm-shim] Environment: Node ${env.nodeVersion}, node-fetch ${env.nodeFetchVersion}`); 63 | console.log(`[esm-shim] Node.js compatible (>=20.19.0): ${env.isNodeCompatible}`); 64 | console.log(`[esm-shim] node-fetch v3: ${env.isNodeFetchV3}`); 65 | console.log(`[esm-shim] Needs shim: ${env.needsShim}`); 66 | 67 | // 只在需要时才启用 shim 68 | if (!env.needsShim) { 69 | if (env.isNodeCompatible && env.isNodeFetchV3) { 70 | console.log('[esm-shim] Node.js >=20.19.0 + node-fetch v3: optimal compatibility, shim disabled'); 71 | } else if (env.isNodeCompatible && !env.isNodeFetchV3) { 72 | console.log('[esm-shim] Node.js >=20.19.0 + node-fetch v2: native compatibility, shim disabled'); 73 | } else if (!env.isNodeCompatible && !env.isNodeFetchV3) { 74 | console.log('[esm-shim] Node.js <20.19.0 + node-fetch v2: no ESM issues, shim disabled'); 75 | } else { 76 | console.log('[esm-shim] Shim disabled for optimal performance'); 77 | } 78 | 79 | // 导出空的加载函数,保持接口一致性 80 | global.loadNodeFetch = async () => { 81 | console.log('[esm-shim] loadNodeFetch called but not needed in this environment'); 82 | return Promise.resolve(); 83 | }; 84 | 85 | // 直接返回,不安装任何 hook 86 | return; 87 | } 88 | 89 | console.log('[esm-shim] Compatibility shim enabled for Node.js <20.19.0 + node-fetch v3'); 90 | 91 | // 以下是 shim 逻辑,只在 Node.js < v20.19.0 + node-fetch v3 时执行 92 | let esbuild; 93 | try { 94 | esbuild = require('esbuild'); 95 | } catch (err) { 96 | console.error('[esm-shim] missing dependency: run `npm install esbuild`'); 97 | throw err; 98 | } 99 | 100 | // ------------------- _compile hook ------------------- 101 | const origCompile = Module.prototype._compile; 102 | Module.prototype._compile = function (content, filename) { 103 | try { 104 | if ( 105 | typeof filename === 'string' && 106 | filename.startsWith(projectRoot) && 107 | !filename.includes('node_modules') && 108 | /\b(?:import|export)\b/.test(content) 109 | ) { 110 | console.log(`[esm-shim] Transforming ESM syntax in: ${path.relative(projectRoot, filename)}`); 111 | const out = esbuild.transformSync(content, { 112 | loader: 'js', 113 | format: 'cjs', 114 | target: 'es2018', 115 | sourcemap: 'inline', 116 | }); 117 | return origCompile.call(this, out.code, filename); 118 | } 119 | } catch (e) { 120 | console.error('[esm-shim] esbuild transform failed:', filename, e.message || e); 121 | } 122 | return origCompile.call(this, content, filename); 123 | }; 124 | 125 | // ------------------- _load hook for node-fetch v3 ------------------- 126 | let fetchCache = null; 127 | let fetchPromise = null; 128 | 129 | // 异步加载 node-fetch v3 130 | async function loadNodeFetchV3() { 131 | if (fetchCache) return fetchCache; 132 | if (fetchPromise) return fetchPromise; 133 | 134 | fetchPromise = (async () => { 135 | try { 136 | console.log('[esm-shim] Loading node-fetch v3 ESM module...'); 137 | const fetchModule = await import('node-fetch'); 138 | 139 | fetchCache = { 140 | default: fetchModule.default, 141 | fetch: fetchModule.default, 142 | Request: fetchModule.Request, 143 | Response: fetchModule.Response, 144 | Headers: fetchModule.Headers, 145 | FormData: fetchModule.FormData, 146 | AbortError: fetchModule.AbortError, 147 | FetchError: fetchModule.FetchError 148 | }; 149 | 150 | console.log('[esm-shim] node-fetch v3 loaded successfully'); 151 | return fetchCache; 152 | } catch (error) { 153 | console.error('[esm-shim] Failed to load node-fetch v3:', error.message); 154 | throw error; 155 | } 156 | })(); 157 | 158 | return fetchPromise; 159 | } 160 | 161 | // 创建 node-fetch v3 兼容层 162 | function createFetchCompat() { 163 | const syncFetch = function(...args) { 164 | if (!fetchCache) { 165 | throw new Error( 166 | '[esm-shim] node-fetch v3 must be loaded asynchronously first. ' + 167 | 'Call await global.loadNodeFetch() in your startup code.' 168 | ); 169 | } 170 | return fetchCache.fetch(...args); 171 | }; 172 | 173 | // 为兼容层添加所有 node-fetch v3 的属性 174 | const properties = ['Request', 'Response', 'Headers', 'FormData', 'AbortError', 'FetchError']; 175 | 176 | properties.forEach(prop => { 177 | Object.defineProperty(syncFetch, prop, { 178 | get() { 179 | if (!fetchCache) { 180 | throw new Error( 181 | `[esm-shim] node-fetch v3.${prop} must be loaded asynchronously first. ` + 182 | 'Call await global.loadNodeFetch() in your startup code.' 183 | ); 184 | } 185 | return fetchCache[prop]; 186 | }, 187 | enumerable: true, 188 | configurable: true 189 | }); 190 | }); 191 | 192 | // 添加 default 属性以保持兼容性 193 | Object.defineProperty(syncFetch, 'default', { 194 | get() { return syncFetch; }, 195 | enumerable: true, 196 | configurable: true 197 | }); 198 | 199 | return syncFetch; 200 | } 201 | 202 | // 拦截 node-fetch 的 require 调用 203 | const origLoad = Module._load; 204 | Module._load = function (request, parent, isMain) { 205 | if (request === 'node-fetch') { 206 | console.log('[esm-shim] Intercepting node-fetch require'); 207 | 208 | // 在这个环境下,我们知道是 node-fetch v3,直接返回兼容层 209 | return createFetchCompat(); 210 | } 211 | 212 | return origLoad.call(this, request, parent, isMain); 213 | }; 214 | 215 | // 导出加载函数 216 | global.loadNodeFetch = loadNodeFetchV3; 217 | 218 | console.log('[esm-shim] ESM compatibility shim active with hooks installed'); -------------------------------------------------------------------------------- /danmu_api/worker.test.js: -------------------------------------------------------------------------------- 1 | const test = require('node:test'); 2 | const assert = require('node:assert').strict; 3 | const { handleRequest, searchAnime, matchAnime, searchEpisode, getBangumi, getComment, fetchTencentVideo, fetchIqiyi, 4 | fetchMangoTV, fetchBilibili, fetchYouku, fetchOtherServer, httpGet, httpPost, 5 | hanjutvSearch, getHanjutvEpisodes, getHanjutvComments, getHanjutvDetail, 6 | bahamutSearch, getBahamutEpisodes, getBahamutComments} = require('./worker'); 7 | 8 | // Mock Request class for testing 9 | class MockRequest { 10 | constructor(url, options = {}) { 11 | this.url = url; 12 | this.method = options.method || 'GET'; 13 | this.headers = new Map(Object.entries(options.headers || {})); 14 | this.json = options.body ? async () => options.body : undefined; // 模拟 POST 请求的 body 15 | } 16 | } 17 | 18 | // Helper to parse JSON response 19 | async function parseResponse(response) { 20 | const text = await response.text(); 21 | try { 22 | return JSON.parse(text); 23 | } catch { 24 | return text; 25 | } 26 | } 27 | 28 | const urlPrefix = "http://localhost:9321"; 29 | const token = "87654321"; 30 | 31 | test('worker.js API endpoints', async (t) => { 32 | await t.test('GET / should return welcome message', async () => { 33 | const req = new MockRequest(urlPrefix, { method: 'GET' }); 34 | const res = await handleRequest(req); 35 | const body = await parseResponse(res); 36 | 37 | assert.equal(res.status, 200); 38 | assert.equal(res.headers.get('Content-Type'), 'application/json'); 39 | assert.deepEqual(body.message, 'Welcome to the LogVar Danmu API server'); 40 | }); 41 | 42 | // await t.test('GET tencent danmu', async () => { 43 | // const res = await fetchTencentVideo("http://v.qq.com/x/cover/rjae621myqca41h/j0032ubhl9s.html"); 44 | // assert(res.length > 2, `Expected res.length > 2, but got ${res.length}`); 45 | // }); 46 | 47 | // await t.test('GET iqiyi danmu', async () => { 48 | // const res = await fetchIqiyi("https://www.iqiyi.com/v_1ftv9n1m3bg.html"); 49 | // assert(res.length > 2, `Expected res.length > 2, but got ${res.length}`); 50 | // }); 51 | 52 | // await t.test('GET mango danmu', async () => { 53 | // const res = await fetchMangoTV("https://www.mgtv.com/b/771610/23300622.html"); 54 | // assert(res.length > 2, `Expected res.length > 2, but got ${res.length}`); 55 | // }); 56 | 57 | // await t.test('GET bilibili danmu', async () => { 58 | // const res = await fetchBilibili("https://www.bilibili.com/bangumi/play/ep1231564"); 59 | // assert(res.length > 2, `Expected res.length > 2, but got ${res.length}`); 60 | // }); 61 | 62 | // await t.test('GET youku danmu', async () => { 63 | // const res = await fetchYouku("https://v.youku.com/v_show/id_XNjQ3ODMyNjU3Mg==.html"); 64 | // assert(res.length > 2, `Expected res.length > 2, but got ${res.length}`); 65 | // }); 66 | 67 | // await t.test('GET other_server danmu', async () => { 68 | // const res = await fetchOtherServer("https://www.bilibili.com/bangumi/play/ep1231564"); 69 | // assert(res.length > 2, `Expected res.length > 2, but got ${res.length}`); 70 | // }); 71 | 72 | // await t.test('GET hanjutv search', async () => { 73 | // const res = await hanjutvSearch("犯罪现场Zero"); 74 | // assert(res.length > 0, `Expected res.length > 0, but got ${res.length}`); 75 | // }); 76 | 77 | // await t.test('GET hanjutv detail', async () => { 78 | // const res = await gethanjutvDetail("Tc9lkfijFSDQ8SiUCB6T"); 79 | // // assert(res.length > 0, `Expected res.length > 0, but got ${res.length}`); 80 | // }); 81 | 82 | // await t.test('GET hanjutv episodes', async () => { 83 | // const res = await getHanjutvEpisodes("4EuRcD6T6y8XEQePtDsf"); 84 | // assert(res.length > 0, `Expected res.length > 0, but got ${res.length}`); 85 | // }); 86 | 87 | // await t.test('GET hanjutv danmu', async () => { 88 | // const res = await getHanjutvComments("12tY0Ktjzu5TCBrfTolNO"); 89 | // assert(res.length > 0, `Expected res.length > 0, but got ${res.length}`); 90 | // }); 91 | 92 | // await t.test('GET bahamut search', async () => { 93 | // const res = await bahamutSearch("膽大黨"); 94 | // assert(res.length > 0, `Expected res.length > 0, but got ${res.length}`); 95 | // }); 96 | 97 | // await t.test('GET bahamut episodes', async () => { 98 | // const res = await getBahamutEpisodes("44243"); 99 | // assert(res.anime.episodes[0].length > 0, `Expected res.length > 0, but got ${res.length}`); 100 | // }); 101 | 102 | // await t.test('GET bahamut danmu', async () => { 103 | // const res = await getBahamutComments("44453"); 104 | // assert(res.length > 0, `Expected res.length > 0, but got ${res.length}`); 105 | // }); 106 | 107 | await t.test('GET realistic danmu', async () => { 108 | // tencent 109 | // const keyword = "子夜归"; 110 | // iqiyi 111 | // const keyword = "赴山海"; 112 | // mango 113 | // const keyword = "锦月如歌"; 114 | // bilibili 115 | // const keyword = "国王排名"; 116 | // youku 117 | // const keyword = "黑白局"; 118 | // renren 119 | // const keyword = "瑞克和莫蒂"; 120 | // hanjutv 121 | // const keyword = "请回答1988"; 122 | // bahamut 123 | const keyword = "胆大党"; 124 | 125 | const searchUrl = new URL(`${urlPrefix}/${token}/api/v2/search/anime?keyword=${keyword}`); 126 | const searchRes = await searchAnime(searchUrl); 127 | const searchData = await searchRes.json(); 128 | assert(searchData.animes.length > 0, `Expected searchData.animes.length > 0, but got ${searchData.animes.length}`); 129 | 130 | const bangumiUrl = new URL(`${urlPrefix}/${token}/api/v2/bangumi/${searchData.animes[0].animeId}`); 131 | const bangumiRes = await getBangumi(bangumiUrl.pathname); 132 | const bangumiData = await bangumiRes.json(); 133 | assert(bangumiData.bangumi.episodes.length > 0, `Expected bangumiData.bangumi.episodes.length > 0, but got ${bangumiData.bangumi.episodes.length}`); 134 | 135 | const commentUrl = new URL(`${urlPrefix}/${token}/api/v2/comment/${bangumiData.bangumi.episodes[0].episodeId}?withRelated=true&chConvert=1`); 136 | const commentRes = await getComment(commentUrl.pathname); 137 | const commentData = await commentRes.json(); 138 | assert(commentData.count > 0, `Expected commentData.count > 0, but got ${commentData.count}`); 139 | }); 140 | 141 | // // 测试 POST /api/v2/match 接口 142 | // await t.test('POST /api/v2/match for matching anime', async () => { 143 | // // 构造请求体 144 | // const requestBody = { 145 | // "fileName": "生万物 S01E28", 146 | // "fileHash": "1234567890", 147 | // "fileSize": 0, 148 | // "videoDuration": 0, 149 | // "matchMode": "fileNameOnly" 150 | // }; 151 | // 152 | // // 模拟 POST 请求 153 | // const matchUrl = `${urlPrefix}/${token}/api/v2/match`; // 注意路径与 handleRequest 中匹配 154 | // const req = new MockRequest(matchUrl, { method: 'POST', body: requestBody }); 155 | // 156 | // // 调用 handleRequest 来处理 POST 请求 157 | // const res = await handleRequest(req); 158 | // 159 | // // 解析响应 160 | // const responseBody = await parseResponse(res); 161 | // console.log(responseBody); 162 | // 163 | // // 验证响应状态 164 | // assert.equal(res.status, 200); 165 | // assert.deepEqual(responseBody.success, true); 166 | // }); 167 | 168 | // // 测试 GET /api/v2/search/episodes 接口 169 | // await t.test('GET /api/v2/search/episodes for search episodes', async () => { 170 | // // 构造请求体 171 | // const requestBody = { 172 | // "fileName": "生万物 S01E28", 173 | // "fileHash": "1234567890", 174 | // "fileSize": 0, 175 | // "videoDuration": 0, 176 | // "matchMode": "fileNameOnly" 177 | // }; 178 | // 179 | // const matchUrl = `${urlPrefix}/${token}/api/v2/search/episodes?anime=子夜归`; 180 | // const req = new MockRequest(matchUrl, { method: 'GET' }); 181 | // 182 | // const res = await handleRequest(req); 183 | // 184 | // // 解析响应 185 | // const responseBody = await parseResponse(res); 186 | // console.log(responseBody); 187 | // 188 | // // 验证响应状态 189 | // assert.equal(res.status, 200); 190 | // assert.deepEqual(responseBody.success, true); 191 | // }); 192 | }); -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 | Clash 3 |
4 | 5 |

6 | LogVar 弹幕 API 服务器 7 |

8 | 9 | [![GitHub](https://img.shields.io/badge/-GitHub-181717?logo=github)](https://github.com/huangxd-/damnu_api) 10 | ![GitHub forks](https://img.shields.io/github/forks/huangxd-/danmu_api) 11 | ![GitHub Repo stars](https://img.shields.io/github/stars/huangxd-/danmu_api) 12 | ![GitHub License](https://img.shields.io/github/license/huangxd-/danmu_api) 13 | ![Docker Image Version](https://img.shields.io/docker/v/logvar/danmu-api?sort=semver) 14 | ![Docker Pulls](https://img.shields.io/docker/pulls/logvar/danmu-api) 15 | [![telegram](https://img.shields.io/static/v1?label=telegram&message=telegram_channel&color=blue)](https://t.me/logvar_danmu_channel) 16 | [![telegram](https://img.shields.io/static/v1?label=telegram&message=telegram_group&color=blue)](https://t.me/logvar_danmu_group) 17 | 18 | --- 19 | 20 | 一个人人都能部署的基于 js 的弹幕 API 服务器,支持爱优腾芒哔人韩巴弹幕直接获取,兼容弹弹play的搜索、详情查询和弹幕获取接口,并提供日志记录,支持vercel/cloudflare/docker/claw等部署方式,不用提前下载弹幕,没有nas或小鸡也能一键部署。 21 | 22 | 本项目仅为个人爱好开发,代码开源。如有任何侵权行为,请联系本人删除。 23 | 24 | 有问题提issue或 [私信机器人](https://t.me/ddjdd_bot) 都ok。 25 | 26 | 新加了 [tg频道](https://t.me/logvar_danmu_channel) ,方便发送更新通知,以及群组,太多人私信咨询了,索性增加一个 [互助群](https://t.me/logvar_danmu_group) ,大家有问题可以在群里求助。 27 | 28 | > 请不要在国内媒体平台宣传本项目! 29 | 30 | ## 功能 31 | - **API 接口**: 32 | - `GET /api/v2/search/anime?keyword=${queryTitle}`:根据关键字搜索动漫。 33 | - `POST /api/v2/match`:根据关键字匹配动漫,用于自动匹配。(目前已支持在match接口中通过@语法动态指定平台优先级,如`赴山海 S01E28 @qiyi`) 34 | - `GET /api/v2/search/episodes`:根据关键词搜索所有匹配的剧集信息。 35 | - `GET /api/v2/bangumi/:animeId`:获取指定动漫的详细信息。 36 | - `GET /api/v2/comment/:commentId?withRelated=true&chConvert=1`:获取指定弹幕评论,支持返回相关评论和字符转换。 37 | - `GET /api/logs`:获取最近的日志(最多 500 行,格式为 `[时间戳] 级别: 消息`)。 38 | - **日志记录**:捕获 `console.log`(info 级别)和 `console.error`(error 级别),JSON 内容格式化输出。 39 | - **部署支持**:支持本地运行、Docker 容器化、Vercel 一键部署、Cloudflare 一键部署和 Docker 一键启动。 40 | 41 | ## 前置条件 42 | - Node.js(v18.0.0 或更高版本;理论兼容更低版本,请自行测试) 43 | - npm 44 | - Docker(可选,用于容器化部署) 45 | 46 | ## 本地运行 47 | 1. **克隆仓库**: 48 | ```bash 49 | git clone <仓库地址> 50 | cd <项目目录> 51 | ``` 52 | 53 | 2. **安装依赖**: 54 | ```bash 55 | npm install 56 | ``` 57 | 58 | 3. **启动服务器**: 59 | ```bash 60 | npm start 61 | ``` 62 | 服务器将在 `http://{ip}:9321` 运行,默认token是`87654321`。 63 | 或者使用下面的命令 64 | ```bash 65 | # 启动 66 | node ./danmu_api/server.js 67 | # 测试 68 | node --test ./danmu_api/worker.test.js 69 | ``` 70 | 71 | 4. **测试 API**: 72 | 使用 Postman 或 curl 测试: 73 | - `GET http://{ip}:9321/87654321` 74 | - `GET http://{ip}:9321/87654321/api/v2/search/anime?keyword=生万物` 75 | - `POST http://{ip}:9321/87654321/api/v2/api/v2/match` 76 | - `GET http://{ip}:9321/87654321/api/v2/search/episodes?anime=生万物` 77 | - `GET http://{ip}:9321/87654321/api/v2/bangumi/1` 78 | - `GET http://{ip}:9321/87654321/api/v2/comment/1?withRelated=true&chConvert=1` 79 | - `GET http://{ip}:9321/87654321/api/logs` 80 | 81 | ## 使用 Docker 运行 82 | 1. **构建 Docker 镜像**: 83 | ```bash 84 | docker build -t danmu-api . 85 | ``` 86 | 87 | 2. **运行容器**: 88 | ```bash 89 | docker run -d -p 9321:9321 --name danmu-api -e TOKEN=87654321 danmu-api 90 | ``` 91 | - 使用`-e TOKEN=87654321`设置`TOKEN`环境变量,覆盖Dockerfile中的默认值。 92 | 93 | 3. **测试 API**: 94 | 使用 `http://{ip}:9321/{TOKEN}` 访问上述 API 接口。 95 | 96 | ## Docker 一键启动 【推荐】 97 | 1. **拉取镜像**: 98 | ```bash 99 | docker pull logvar/danmu-api:latest 100 | ``` 101 | 102 | 2. **运行容器**: 103 | ```bash 104 | docker run -d -p 9321:9321 --name danmu-api -e TOKEN=87654321 logvar/danmu-api:latest 105 | ``` 106 | - 使用`-e TOKEN=87654321`设置`TOKEN`环境变量。 107 | 108 | ```yaml 109 | services: 110 | danmu-api: 111 | image: logvar/danmu-api:latest 112 | container_name: danmu-api 113 | ports: 114 | - "9321:9321" 115 | environment: 116 | - TOKEN=87654321 # 请将 87654321 替换为你想自定义的 Token 值 117 | restart: unless-stopped # 可选配置,容器退出时自动重启(非必需,可根据需求删除) 118 | ``` 119 | - 或使用docker compose部署。 120 | ```yaml 121 | services: 122 | watchtower: 123 | image: containrrr/watchtower 124 | container_name: watchtower-gx 125 | restart: always 126 | volumes: 127 | - /var/run/docker.sock:/var/run/docker.sock 128 | environment: 129 | - TZ=Asia/Shanghai # 保持时区正确 130 | command: 131 | - --cleanup # 更新后清理旧镜像 132 | - --interval # 间隔参数 133 | - "12600" # 30分钟(1800秒),适合测试 134 | - danmu-api # 监控的目标容器名 135 | ``` 136 | - 可以使用watchtower监控有新版本自动更新。 137 | 138 | 3. **测试 API**: 139 | 使用 `http://{ip}:9321/{TOKEN}` 访问上述 API 接口。 140 | 141 | ## 部署到 Vercel 【推荐】 142 | 143 | ### 一键部署 144 | 点击以下按钮即可将项目快速部署到 Vercel: 145 | 146 | [![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/coko8023/danmu_api&project-name=danmu_api&repository-name=danmu_api) 147 | 148 | **注意**:请将按钮链接中的 `https://github.com/huangxd-/danmu_api` 替换为你的实际 Git 仓库地址。编辑 `README.md` 并更新链接后,推送到仓库,点击按钮即可自动克隆和部署。 149 | - **设置环境变量**:部署后,在 Vercel 仪表板中: 150 | 1. 转到你的项目设置。 151 | 2. 在“Environment Variables”部分添加 `TOKEN` 变量,输入你的 API 令牌值。 152 | 3. 保存更改并重新部署。 153 | - 示例请求:`https://{your_domian}.vercel.app/87654321/api/v2/search/anime?keyword=子夜归` 154 | 155 | ### 优化点 156 | - Settings > Functions > Advanced Setting > Function Region 切换为 Hong Kong,能提高访问速度,体验更优 157 | > hk有可能访问不了360或其他源,可以尝试切其他region,如新加坡等 158 | - vercel在国内被墙,请配合代理使用或绑定自定义域名 159 | 160 | ## 部署到 腾讯云 edgeone pages 161 | 162 | ### 一键部署 163 | [![使用 EdgeOne Pages 部署](https://cdnstatic.tencentcs.com/edgeone/pages/deploy.svg)](https://console.cloud.tencent.com/edgeone/pages/new?template=https://github.com/huangxd-/danmu_api&project-name=danmu-api&root-directory=.%2F&env=TOKEN) 164 | 165 | > 注意:部署时请在环境变量配置区域填写你的TOKEN值,该变量将用于API服务的身份验证相关功能 166 | > 167 | > 示例请求:`https://{your_domian}/{TOKEN}/api/v2/search/anime?keyword=子夜归`确认是否部署成功 168 | > 169 | > 部署的时候项目加速区域最好设置为"全球可用区(不含中国大陆)",不然不绑定自定义域名貌似只能生成3小时的预览链接?[相关文档](https://edgeone.cloud.tencent.com/pages/document/175191784523485184) 170 | > 171 | > 也可直接用国际站的部署按钮一键部署,默认选择"全球可用区(不含中国大陆)" [![使用 EdgeOne Pages 部署](https://cdnstatic.tencentcs.com/edgeone/pages/deploy.svg)](https://edgeone.ai/pages/new?template=https://github.com/huangxd-/danmu_api&project-name=danmu-api&root-directory=.%2F&env=TOKEN) 172 | > 173 | 174 | 175 | > 如果访问遇到404等问题,可能是edgeone pages修改了访问策略,每次接口请求都转发到了新的环境,没有缓存,导致获取不到对应的弹幕,推荐用vercel部署。 176 | 177 | ## 部署到 Cloudflare 178 | 179 | ### 一键部署 180 | 点击以下按钮即可将项目快速部署到 Cloudflare: 181 | 182 | [![Deploy to Cloudflare Workers](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/huangxd-/danmu_api) 183 | 184 | **注意**:请将按钮链接中的 `https://github.com/huangxd-/danmu_api` 替换为你的实际 Git 仓库地址。编辑 `README.md` 并更新链接后,推送到仓库,点击按钮即可自动克隆和部署。 185 | - **设置环境变量**:部署后,在 Cloudflare 仪表板中: 186 | 1. 转到你的 Workers 项目。 187 | 2. 转到“Settings” > “Variables”。 188 | 3. 添加 `TOKEN` 环境变量,输入你的 API 令牌值。 189 | 4. 保存并部署。 190 | - 示例请求:`https://{your_domian}.workers.dev/87654321/api/v2/search/anime?keyword=子夜归` 191 | 192 | ### 手动部署 193 | 创建一个worker,将`danmu_api/worker.js`里的代码直接拷贝到你创建的`worker.js`里,然后点击部署。 194 | 195 | > cf部署可能不稳定,推荐用vercel部署。 196 | 197 | ## API食用指南 198 | 支持 forward/senplayer/hills/小幻/yamby/eplayerx/afusekt 等支持弹幕API的播放器。 199 | 200 | 以`senplayer`为例: 201 | 1. 获取到部署之后的API地址,如 `http://192.168.1.7:9321/87654321` ,其中`87654321`是默认token,如果有自定义环境变量TOKEN,请替换成相应的token 202 | 2. 将API地址填入自定义弹幕API,在`设置 - 弹幕设置 - 自定义弹幕API` 203 | 3. 播放界面点击`弹幕按钮 - 搜索弹幕`,选择你的弹幕API,会根据标题进行搜索,等待一段时间,选择剧集就行。 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | > 注意: 212 | > 213 | > ~~小幻在填写API的时候需要在API后面加上/api/v2,如http://192.168.1.7:9321/87654321/api/v2~~ 214 | > 215 | > (已对小幻做兼容,`/api/v2`可加可不加都可以正确处理) 216 | > 217 | > 有很多人问FW能不能用,FW推荐直接使用插件,如果非要使用,则可以配合 `https://raw.githubusercontent.com/huangxd-/ForwardWidgets/refs/heads/main/widgets.fwd` 里的`danmu_api`插件使用 218 | 219 | ## 环境变量列表 220 | | 变量名称 | 描述 | 221 | | ----------- | ----------- | 222 | | TOKEN | 【可选】自定义用户token,不填默认为`87654321` | 223 | | OTHER_SERVER | 【可选】兜底第三方弹幕服务器,不填默认为`https://api.danmu.icu` | 224 | | VOD_SERVER | 【可选】vod查询站点,不填默认为`https://www.caiji.cyou` | 225 | | VOD_SERVER2 | 【可选】vod2查询站点,如果想开启vod2源,请先填写VOD_SERVER2源地址,如`https://zy.xmm.hk`,并在SOURCE_ORDER环境变量中增加`vod2` | 226 | | BILIBILI_COOKIE | 【可选】b站cookie(填入后能抓取完整弹幕),如 `buvid3=E2BCA ... eao6; theme-avatar-tip-show=SHOWED`,请自行通过浏览器或抓包工具抓取,热心网友测试后,实际最少只需取 `SESSDATA=xxxx` 字段 | 227 | | YOUKU_CONCURRENCY | 【可选】youku弹幕请求并发数,用于加快youku弹幕请求速度,不填默认为`8`,最高`16` | 228 | | SOURCE_ORDER | 【可选】源排序,用于按源对返回资源的排序(注意:先后顺序会影响自动匹配最终的返回),默认是`vod,360,renren,hanjutv`,表示vod数据排在最前,hanjutv数据排在最后,示例:`360,renren`:只返回360数据和renren数据,且360数据靠前;当前可选择的源字段有 `vod,vod2,360,renren,hanjutv,bahamut` | 229 | | PLATFORM_ORDER | 【可选】自动匹配优选平台,按顺序优先返回指定平台弹幕,默认为空,即返回第一个满足条件的平台,示例:`bilibili1,qq`,表示如果有b站的播放源,则优先返回b站的弹幕,否则就返回腾讯的弹幕,两者都没有,则返回第一个满足条件的平台;当前可选择的平台字段有 `qiyi, bilibili1, imgo, youku, qq, renren, hanjutv, bahamut` | 230 | | EPISODE_TITLE_FILTER | 【可选】剧集标题正则过滤,按正则关键字对剧集或综艺的集标题进行过滤,适用于过滤一些预告或综艺非正式集,默认值如下 | 231 | | BLOCKED_WORDS | 【可选】弹幕屏蔽词列表,默认为空,示例如下 | 232 | | GROUP_MINUTE | 【可选】合并去重分钟数,表示按n分钟分组后对弹幕合并去重,默认为1,最大值为30,0表示不去重 | 233 | | PROXY_URL | 【可选】代理地址,示例: `http://127.0.0.1:7897` ,目前只对巴哈姆特生效(注意:如果巴哈姆特请求不通,会拖慢搜索返回速度,所以除vercel/cloudflare之外默认不开启bahamut源,开启请先在SOURCE_ORDER环境变量中添加`bahamut`)如果你使用docker部署并且访问不了bahamut源,请配置代理地址;vercel/cf中理应都自然能联通,不用填写 | 234 | 235 | ```regex 236 | # EPISODE_TITLE_FILTER 默认值 237 | (特别|惊喜|纳凉)?企划|合伙人手记|超前|速览|vlog|reaction|纯享|加更|抢先|抢鲜|预告|花絮|特辑|彩蛋|专访|幕后|直播|未播|衍生|番外|会员|片花|精华|看点|速看|解读|影评|解说|吐槽|盘点|拍摄花絮|制作花絮|幕后花絮|未播花絮|独家花絮|花絮特辑|先导预告|终极预告|正式预告|官方预告|彩蛋片段|删减片段|未播片段|番外彩蛋|精彩片段|精彩看点|精彩回顾|精彩集锦|看点解析|看点预告|NG镜头|NG花絮|番外篇|番外特辑|制作特辑|拍摄特辑|幕后特辑|导演特辑|演员特辑|片尾曲|插曲|主题曲|背景音乐|OST|音乐MV|歌曲MV|前季回顾|剧情回顾|往期回顾|内容总结|剧情盘点|精选合集|剪辑合集|混剪视频|独家专访|演员访谈|导演访谈|主创访谈|媒体采访|发布会采访|抢先看|抢先版|试看版|短剧|精编|会员版|Plus|独家版|特别版|短片|合唱|陪看|MV|高清正片|发布会|.{2,}篇|观察室|上班那点事儿|周top|赛段|直拍|REACTION|VLOG|全纪录|开播|先导|总宣|展演 238 | 239 | # 如果你想新增过滤词,请自定义EPISODE_TITLE_FILTER,示例如下,每个词用'|'隔开,增加的词都会追加到默认值后面 240 | 测试|test 241 | ``` 242 | 243 | ```regex 244 | # BLOCKED_WORDS 示例值 245 | /.{20,}/,/^\d{2,4}[-/.]\d{1,2}[-/.]\d{1,2}([日号.]*)?$/,/^(?!哈+$)([a-zA-Z\u4e00-\u9fa5])\1{2,}/,/[0-9]+\.*[0-9]*\s*(w|万)+\s*(\+|个|人|在看)+/,/^[a-z]{6,}$/,/^(?:qwertyuiop|asdfghjkl|zxcvbnm)$/,/^\d{5,}$/,/^(\d)\1{2,}$/,/\d{1,4}/,/(20[0-3][0-9])/,/(0?[1-9]|1[0-2])月/,/\d{1,2}[.-]\d{1,2}/,/[@#&$%^*+\|/\-_=<>°◆◇■□●○★☆▼▲♥♦♠♣①②③④⑤⑥⑦⑧⑨⑩]/,/[一二三四五六七八九十百\d]+刷/,/第[一二三四五六七八九十百\d]+/,/(全体成员|报到|报道|来啦|签到|刷|打卡|我在|来了|考古|爱了|挖坟|留念|你好|回来|哦哦|重温|复习|重刷|再看|在看|前排|沙发|有人看|板凳|末排|我老婆|我老公|撅了|后排|周目|重看|包养|DVD|同上|同样|我也是|俺也|算我|爱豆|我家爱豆|我家哥哥|加我|三连|币|新人|入坑|补剧|冲了|硬了|看完|舔屏|万人|牛逼|煞笔|傻逼|卧槽|tm|啊这|哇哦)/ 246 | 247 | # 注释如下: 248 | /.{20,}/ # 屏蔽20字符及以上的弹幕 249 | /^\d{2,4}[-/.]\d{1,2}[-/.]\d{1,2}([日号.])?$/ # 屏蔽日期弹幕 250 | /^(?!哈+$)([a-zA-Z\u4e00-\u9fa5])\1{2,}/ # 屏蔽单个汉字或者字母连续出现3次及以上的弹幕(排除纯“哈”重复) 251 | /[0-9]+.[0-9]\s(w|万)+\s*(\+|个|人|在看)+/ # 屏蔽几点几万在看的弹幕 252 | /^[a-z]{6,}$/ # 屏蔽6个及以上连续小写字母的弹幕 253 | /^(?:qwertyuiop|asdfghjkl|zxcvbnm)$/ # 屏蔽键盘连续行的弹幕 254 | /^\d{5,}$/ # 屏蔽5位及以上纯数字的弹幕 255 | /^(\d)\1{2,}$/ # 屏蔽三个及以上相同数字重复的弹幕 256 | /\d{1,4}/ # 屏蔽1-4位数字的弹幕 257 | /(20[0-3][0-9])/ # 屏蔽2000-2039年份相关的弹幕 258 | /(0?[1-9]|1[0-2])月/ # 屏蔽月份表述的弹幕 259 | /\d{1,2}[.-]\d{1,2}/ # 屏蔽类似时间或日期分隔的数字弹幕 260 | /[@#&$%^*+\|/\-_=<>°◆◇■□●○★☆▼▲♥♦♠♣①②③④⑤⑥⑦⑧⑨⑩]/ # 屏蔽特殊符号或表情符号的弹幕 261 | /[一二三四五六七八九十百\d]+刷/ # 屏蔽数字或汉字数字后跟“刷”的弹幕 262 | /第[一二三四五六七八九十百\d]+/ # 屏蔽“第几”序号相关的弹幕 263 | /(全体成员|报到|报道|来啦|签到|刷|打卡|我在|来了|考古|爱了|挖坟|留念|你好|回来|哦哦|重温|复习|重刷|再看|在看|前排|沙发|有人看|板凳|末排|我老婆|我老公|撅了|后排|周目|重看|包养|DVD|同上|同样|我也是|俺也|算我|爱豆|我家爱豆|我家哥哥|加我|三连|币|新人|入坑|补剧|冲了|硬了|看完|舔屏|万人|牛逼|煞笔|傻逼|卧槽|tm|啊这|哇哦)/ # 屏蔽常见互动、报到或口语化弹幕词汇 264 | ``` 265 | 266 | ## 项目结构 267 | ``` 268 | danmu_api/ 269 | ├── .github/ 270 | │ └── workflows/ 271 | │ ├── docker-image.yml 272 | │ └── sync_fork.yml # vercel自动同步配置文件 273 | ├── danmu_api/ 274 | │ ├── esm-shim.js # Node.js低版本兼容层 275 | │ ├── server.js # 本地node启动脚本 276 | │ ├── worker.js # 主 API 服务器代码 277 | │ ├── worker.test.js # 测试文件 278 | ├── node-functions/ 279 | │ ├── [[...path]]..js # edgeone pages 所有路由跳转指向index 280 | │ └── index.js # edgeone pages 中间处理逻辑 281 | ├── .gitignore 282 | ├── Dockerfile 283 | ├── edgeone.json # edgeone pages 配置文件 284 | ├── LICENSE 285 | ├── package.json 286 | ├── README.md 287 | ├── vercel.json # vercel 配置文件 288 | └── wrangler.toml # cloudflare worker 配置文件 289 | ``` 290 | 291 | ## 注意事项 292 | - 日志存储在内存中,服务器重启后会清空。 293 | - `/api/logs` 中的 JSON 日志会格式化显示,带缩进以提高可读性。 294 | - 确保 `package.json` 中包含 `node-fetch` 依赖。 295 | - 一键部署需要将项目推送到公开的 Git 仓库(如 GitHub),并更新按钮中的仓库地址。 296 | - 运行 Docker 容器时,需通过 `-e TOKEN=87654321` 传递 `TOKEN` 环境变量。 297 | - cloudflare貌似被哔风控了。 298 | - 如果想更换兜底第三方弹幕服务器,请添加环境变量`OTHER_SERVER`,示例`https://api.danmu.icu`。 299 | - 如果想更换vod站点,请添加环境变量`VOD_SERVER`,示例`https://www.caiji.cyou`。 300 | - 推荐vercel和claw部署,cloudflare/edgeone不稳定,当然最稳定还是自己本地docker部署最佳。 301 | - /api/v2/comment接口1分钟内同一IP只能请求三次。 302 | 303 | ### 关联项目 304 | [喂饭教程1:danmu_api vercel 自动同步部署方案 - 永远保持最新版本!实时同步原作者更新](https://github.com/xiaoyao20084321/log-var-danmu-deployment-guide) 305 | 306 | [喂饭教程2:logvar弹幕搭建教程(docker/claw)](https://blog.tencentx.de/p/logvar%E5%BC%B9%E5%B9%95%E6%90%AD%E5%BB%BA%E6%95%99%E7%A8%8B%E5%96%82%E9%A5%AD%E7%89%88/) 307 | 308 | ### 部署完成后在播放器填写后弹幕未生效自主排查步骤 309 | 以API示例 `http://192.168.1.7:9321/87654321` 为例 310 | 1. 首先确认你的api部署成功 访问 `http://192.168.1.7:9321/87654321` 有json输出 311 | 2. 检查你在播放器的填写是否正确,有无多余空格等 312 | 3. 播放器请求后,查看 `http://192.168.1.7:9321/87654321/api/logs` 日志,看请求是否有报错,比如有用户在自己软路由上搭建,但走了全局代理,导致人人等访问不了,请确保走直连 313 | 4. 如果你播放的影片片名不规范,很可能搜不到,请确保片名规范 314 | 315 | ### 贡献者 316 | 317 | contributors 318 | 319 | 320 | ### 📈项目 Star 数增长趋势 321 | #### Star History 322 | [![Star History Chart](https://api.star-history.com/svg?repos=huangxd-/danmu_api&type=Date)](https://www.star-history.com/#huangxd-/danmu_api&Date) 323 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published 637 | by the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . --------------------------------------------------------------------------------