perf: narrow msteams attachment imports · openclaw/openclaw@55389f4
steipete
·
2026-04-24
·
via Recent Commits to openclaw:main
File tree
extensions/msteams/src/attachments
| Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | import { Buffer } from "node:buffer"; |
2 | 2 | import { lookup } from "node:dns/promises"; |
3 | | -export { estimateBase64DecodedBytes } from "openclaw/plugin-sdk/media-runtime"; |
4 | | -import { estimateBase64DecodedBytes } from "openclaw/plugin-sdk/media-runtime"; |
5 | 3 | import { |
6 | 4 | buildHostnameAllowlistPolicyFromSuffixAllowlist, |
7 | 5 | isHttpsUrlAllowedByHostnameSuffixAllowlist, |
@@ -84,6 +82,42 @@ export const DEFAULT_MEDIA_AUTH_HOST_ALLOWLIST = [
|
84 | 82 | export const GRAPH_ROOT = "https://graph.microsoft.com/v1.0"; |
85 | 83 | export { isRecord }; |
86 | 84 | |
| 85 | +// Keep this local; importing the broad media-runtime SDK barrel pulls image/audio runtimes into |
| 86 | +// hot MSTeams attachment tests for one tiny estimator. |
| 87 | +export function estimateBase64DecodedBytes(base64: string): number { |
| 88 | +let effectiveLen = 0; |
| 89 | +for (let i = 0; i < base64.length; i += 1) { |
| 90 | +const code = base64.charCodeAt(i); |
| 91 | +if (code <= 0x20) { |
| 92 | +continue; |
| 93 | +} |
| 94 | +effectiveLen += 1; |
| 95 | +} |
| 96 | + |
| 97 | +if (effectiveLen === 0) { |
| 98 | +return 0; |
| 99 | +} |
| 100 | + |
| 101 | +let padding = 0; |
| 102 | +let end = base64.length - 1; |
| 103 | +while (end >= 0 && base64.charCodeAt(end) <= 0x20) { |
| 104 | +end -= 1; |
| 105 | +} |
| 106 | +if (end >= 0 && base64[end] === "=") { |
| 107 | +padding = 1; |
| 108 | +end -= 1; |
| 109 | +while (end >= 0 && base64.charCodeAt(end) <= 0x20) { |
| 110 | +end -= 1; |
| 111 | +} |
| 112 | +if (end >= 0 && base64[end] === "=") { |
| 113 | +padding = 2; |
| 114 | +} |
| 115 | +} |
| 116 | + |
| 117 | +const estimated = Math.floor((effectiveLen * 3) / 4) - padding; |
| 118 | +return Math.max(0, estimated); |
| 119 | +} |
| 120 | + |
87 | 121 | /** |
88 | 122 | * Host suffixes for SharePoint/OneDrive shared links that must be fetched via |
89 | 123 | * the Graph `/shares/{shareId}/driveItem/content` endpoint instead of directly. |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。