refactor(zalo): dedupe hosted route cleanup · openclaw/openclaw@77a877e
vincentkoc
·
2026-06-18
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -98,6 +98,21 @@ function loadZaloWebhookModule(): Promise<ZaloWebhookModule> {
|
98 | 98 | return zaloWebhookModulePromise; |
99 | 99 | } |
100 | 100 | |
| 101 | +function releaseSharedHostedMediaRouteRef(routePath: string): void { |
| 102 | +const current = hostedMediaRouteRefs.get(routePath); |
| 103 | +if (!current) { |
| 104 | +return; |
| 105 | +} |
| 106 | +if (current.count > 1) { |
| 107 | +current.count -= 1; |
| 108 | +return; |
| 109 | +} |
| 110 | +hostedMediaRouteRefs.delete(routePath); |
| 111 | +for (const unregisterHandle of current.unregisters) { |
| 112 | +unregisterHandle(); |
| 113 | +} |
| 114 | +} |
| 115 | + |
101 | 116 | function registerSharedHostedMediaRoute(params: { |
102 | 117 | path: string; |
103 | 118 | accountId: string; |
@@ -125,37 +140,11 @@ function registerSharedHostedMediaRoute(params: {
|
125 | 140 | if (existing) { |
126 | 141 | existing.count += 1; |
127 | 142 | existing.unregisters.push(unregister); |
128 | | -return () => { |
129 | | -const current = hostedMediaRouteRefs.get(params.path); |
130 | | -if (!current) { |
131 | | -return; |
132 | | -} |
133 | | -if (current.count > 1) { |
134 | | -current.count -= 1; |
135 | | -return; |
136 | | -} |
137 | | -hostedMediaRouteRefs.delete(params.path); |
138 | | -for (const unregisterHandle of current.unregisters) { |
139 | | -unregisterHandle(); |
140 | | -} |
141 | | -}; |
| 143 | +return () => releaseSharedHostedMediaRouteRef(params.path); |
142 | 144 | } |
143 | 145 | |
144 | 146 | hostedMediaRouteRefs.set(params.path, { count: 1, unregisters: [unregister] }); |
145 | | -return () => { |
146 | | -const current = hostedMediaRouteRefs.get(params.path); |
147 | | -if (!current) { |
148 | | -return; |
149 | | -} |
150 | | -if (current.count > 1) { |
151 | | -current.count -= 1; |
152 | | -return; |
153 | | -} |
154 | | -hostedMediaRouteRefs.delete(params.path); |
155 | | -for (const unregisterHandle of current.unregisters) { |
156 | | -unregisterHandle(); |
157 | | -} |
158 | | -}; |
| 147 | +return () => releaseSharedHostedMediaRouteRef(params.path); |
159 | 148 | } |
160 | 149 | |
161 | 150 | type ZaloMessagePipelineParams = ZaloProcessingContext & { |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。