(event: Event)
| 163 | } |
| 164 | |
| 165 | private canAcceptEvent(event: Event): boolean { |
| 166 | if (this.getRelayPublicKey() === event.pubkey) { |
| 167 | logger(`event ${event.id} not accepted: pubkey is relay pubkey`) |
| 168 | return false |
| 169 | } |
| 170 | |
| 171 | const now = Math.floor(Date.now() / 1000) |
| 172 | |
| 173 | const eventLimits = this.settings().limits?.event ?? {} |
| 174 | |
| 175 | const eventLimitOverrides = this.config.limits?.event ?? {} |
| 176 | |
| 177 | const limits = mergeDeepRight(eventLimits, eventLimitOverrides) as EventLimits |
| 178 | |
| 179 | if (Array.isArray(limits.content)) { |
| 180 | for (const limit of limits.content) { |
| 181 | if ( |
| 182 | typeof limit.maxLength !== 'undefined' && |
| 183 | limit.maxLength > 0 && |
| 184 | event.content.length > limit.maxLength && |
| 185 | (!Array.isArray(limit.kinds) || limit.kinds.some(isEventKindOrRangeMatch(event))) |
| 186 | ) { |
| 187 | logger(`event ${event.id} not accepted: content is longer than ${limit.maxLength} bytes`) |
| 188 | return false |
| 189 | } |
| 190 | } |
| 191 | } else if ( |
| 192 | typeof limits.content?.maxLength !== 'undefined' && |
| 193 | limits.content?.maxLength > 0 && |
| 194 | event.content.length > limits.content.maxLength && |
| 195 | (!Array.isArray(limits.content.kinds) || limits.content.kinds.some(isEventKindOrRangeMatch(event))) |
| 196 | ) { |
| 197 | logger(`event ${event.id} not accepted: content is longer than ${limits.content.maxLength} bytes`) |
| 198 | return false |
| 199 | } |
| 200 | |
| 201 | if ( |
| 202 | typeof limits.createdAt?.maxPositiveDelta !== 'undefined' && |
| 203 | limits.createdAt.maxPositiveDelta > 0 && |
| 204 | event.created_at > now + limits.createdAt.maxPositiveDelta |
| 205 | ) { |
| 206 | logger( |
| 207 | `event ${event.id} not accepted: created_at is more than ${limits.createdAt.maxPositiveDelta} seconds in the future`, |
| 208 | ) |
| 209 | return false |
| 210 | } |
| 211 | |
| 212 | if ( |
| 213 | typeof limits.createdAt?.maxNegativeDelta !== 'undefined' && |
| 214 | limits.createdAt.maxNegativeDelta > 0 && |
| 215 | event.created_at < now - limits.createdAt.maxNegativeDelta |
| 216 | ) { |
| 217 | logger( |
| 218 | `event ${event.id} not accepted: created_at is more than ${limits.createdAt.maxNegativeDelta} seconds in the past`, |
| 219 | ) |
| 220 | return false |
| 221 | } |
| 222 |
no test coverage detected