| 1415 | base64Response = btoa(combinedContent); // 重新进行 Base64 编码 |
| 1416 | } catch (e) { |
| 1417 | function encodeBase64(data) { |
| 1418 | const binary = new TextEncoder().encode(data); |
| 1419 | let base64 = ''; |
| 1420 | const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; |
| 1421 | |
| 1422 | for (let i = 0; i < binary.length; i += 3) { |
| 1423 | const byte1 = binary[i]; |
| 1424 | const byte2 = binary[i + 1] || 0; |
| 1425 | const byte3 = binary[i + 2] || 0; |
| 1426 | |
| 1427 | base64 += chars[byte1 >> 2]; |
| 1428 | base64 += chars[((byte1 & 3) << 4) | (byte2 >> 4)]; |
| 1429 | base64 += chars[((byte2 & 15) << 2) | (byte3 >> 6)]; |
| 1430 | base64 += chars[byte3 & 63]; |
| 1431 | } |
| 1432 | |
| 1433 | const padding = 3 - (binary.length % 3 || 3); |
| 1434 | return base64.slice(0, base64.length - padding) + '=='.slice(0, padding); |
| 1435 | } |
| 1436 | base64Response = encodeBase64(combinedContent); |
| 1437 | } |
| 1438 | const response = new Response(base64Response, { headers: responseHeaders }); |