size-limit-policy: Exclude replaceable and epheremal kinds, drop default to 8Kb.
This commit is contained in:
parent
b0a253500d
commit
94a3c8455d
@ -2,27 +2,27 @@ import { Policy } from '../types.ts';
|
|||||||
|
|
||||||
/** Policy options for `sizeLimitPolicy`. */
|
/** Policy options for `sizeLimitPolicy`. */
|
||||||
interface SizeLimitOptions {
|
interface SizeLimitOptions {
|
||||||
/** Maximum size of the message content in bytes. Default: 12KB (12288 bytes) */
|
/** Maximum size of the message content in bytes. Default: 8KB (8192 bytes) */
|
||||||
maxContentSize?: number;
|
maxContentSize?: number;
|
||||||
/** List of excluded event kinds */
|
/** List of excluded event kinds */
|
||||||
excludeKinds?: number[];
|
excludeKinds?: number[];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reject events larger than a specified size.
|
* Reject events larger than a specified size. Only applies to regular events (kind is less than 10000), as all other kinds are replaceable or ephemeral anyway.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* ```ts
|
* ```ts
|
||||||
* // Reject events larger than a custom size (15KB) and exclude event kinds [1, 2].
|
* // Reject events larger than a custom size (15KB) and exclude event kinds [1, 2].
|
||||||
* sizeLimitPolicy(msg, { maxContentSize: 15000, excludeKinds: [1, 2] });
|
* sizeLimitPolicy(msg, { maxContentSize: 15360, excludeKinds: [1, 2] });
|
||||||
* // Reject events larger than the default size (12KB) and exclude event kinds [3].
|
* // Reject events larger than the default size (8KB) and exclude event kinds [3].
|
||||||
* sizeLimitPolicy(msg, { excludeKinds: [3] });
|
* sizeLimitPolicy(msg, { excludeKinds: [3] });
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
const sizeLimitPolicy: Policy<SizeLimitOptions> = ({ event: { id, content, kind } }, opts = {}) => {
|
const sizeLimitPolicy: Policy<SizeLimitOptions> = ({ event: { id, content, kind } }, opts = {}) => {
|
||||||
const {
|
const {
|
||||||
excludeKinds = [3, 30078], // Exclude large events such as contact lists and app data
|
excludeKinds = [3], // Follows aka Contact Lists (NIP-02)
|
||||||
maxContentSize = 12 * 1024 // Default size limit is 12KB
|
maxContentSize = 8 * 1024 // Default size limit
|
||||||
} = opts;
|
} = opts;
|
||||||
|
|
||||||
// Convert the content into bytes and check its size
|
// Convert the content into bytes and check its size
|
||||||
|
Loading…
Reference in New Issue
Block a user