From 8ff120b7388923680caf8e1f217d55dce3ca2a83 Mon Sep 17 00:00:00 2001 From: PRO-2684 <54608551+PRO-2684@users.noreply.github.com> Date: Fri, 3 Jan 2025 14:45:59 +0800 Subject: [PATCH] chore: Moving schema to here --- .vscode/settings.json | 5 +- README.md | 4 +- README_zh.md | 3 +- ruleset.schema.json | 217 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 224 insertions(+), 5 deletions(-) create mode 100644 ruleset.schema.json diff --git a/.vscode/settings.json b/.vscode/settings.json index d38dafb..dca9176 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,9 +5,10 @@ "*.json", "!settings.json", "!list.json", - "!list.min.json" + "!list.min.json", + "!ruleset.schema.json" ], - "url": "https://github.com/PRO-2684/pURLfy/raw/refs/heads/main/ruleset.schema.json" + "url": "/ruleset.schema.json" } ] } diff --git a/README.md b/README.md index 4b8520c..165f7ce 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,11 @@ English | [็ฎ€ไฝ“ไธญๆ–‡](README_zh.md) [![jsDelivr hits](https://data.jsdelivr.com/v1/package/gh/PRO-2684/pURLfy-rules/badge?style=rounded)](https://www.jsdelivr.com/package/gh/PRO-2684/pURLfy-rules?tab=stats) -Rulesets for [pURLfy](https://github.com/PRO-2684/pURLfy). Description on structure of rulesets can be found in [pURLfy's README](https://github.com/PRO-2684/pURLfy/#-rulesets), and formal definition of the format can be found at [`ruleset.schema.json`](https://github.com/PRO-2684/pURLfy/blob/main/ruleset.schema.json). - +Rulesets for [pURLfy](https://github.com/PRO-2684/pURLfy). Description on structure of rulesets can be found in [pURLfy's README](https://github.com/PRO-2684/pURLfy/#-rulesets), and formal definition of the format can be found at [`ruleset.schema.json`](ruleset.schema.json). ## ๐Ÿ“ƒ Files +- [ruleset.schema.json](ruleset.schema.json): The formal definition of the format of rulesets. - [list.json](list.json): A list of all rulesets. - [tracking.json](tracking.json): Rules for purifying tracking links. - [outgoing.json](outgoing.json): Rules for purifying outgoing links. diff --git a/README_zh.md b/README_zh.md index 9758e05..b7119c2 100644 --- a/README_zh.md +++ b/README_zh.md @@ -4,10 +4,11 @@ [![jsDelivr hits](https://data.jsdelivr.com/v1/package/gh/PRO-2684/pURLfy-rules/badge?style=rounded)](https://www.jsdelivr.com/package/gh/PRO-2684/pURLfy-rules?tab=stats) -[pURLfy](https://github.com/PRO-2684/pURLfy) ็š„่ง„ๅˆ™้›†ใ€‚ๆœ‰ๅ…ณ่ง„ๅˆ™้›†็ป“ๆž„็š„ๆ่ฟฐ๏ผŒ่ฏทๅ‚้˜… [pURLfy ็š„ README](https://github.com/PRO-2684/pURLfy/blob/main/README_zh.md#-%E8%A7%84%E5%88%99%E9%9B%86)๏ผ›ๆ ผๅผ็š„ๅฝขๅผๅŒ–ๅฎšไน‰ๅฏไปฅๅ‚่€ƒ [`ruleset.schema.json`](https://github.com/PRO-2684/pURLfy/blob/main/ruleset.schema.json)ใ€‚ +[pURLfy](https://github.com/PRO-2684/pURLfy) ็š„่ง„ๅˆ™้›†ใ€‚ๆœ‰ๅ…ณ่ง„ๅˆ™้›†็ป“ๆž„็š„ๆ่ฟฐ๏ผŒ่ฏทๅ‚้˜… [pURLfy ็š„ README](https://github.com/PRO-2684/pURLfy/blob/main/README_zh.md#-%E8%A7%84%E5%88%99%E9%9B%86)๏ผ›ๆ ผๅผ็š„ๅฝขๅผๅŒ–ๅฎšไน‰ๅฏไปฅๅ‚่€ƒ [`ruleset.schema.json`](ruleset.schema.json)ใ€‚ ## ๐Ÿ“ƒ ๆ–‡ไปถ +- [ruleset.schema.json](ruleset.schema.json): ่ง„ๅˆ™้›†ๆ ผๅผ็š„ๅฝขๅผๅŒ–ๅฎšไน‰ใ€‚ - [list.json](list.json): ๆ‰€ๆœ‰่ง„ๅˆ™้›†็š„ๅˆ—่กจใ€‚ - [tracking.json](tracking.json): ๅ‡€ๅŒ–่ทŸ่ธช้“พๆŽฅ็š„่ง„ๅˆ™ใ€‚ - [outgoing.json](outgoing.json): ๅ‡€ๅŒ–ๅค–้“พ็š„่ง„ๅˆ™ใ€‚ diff --git a/ruleset.schema.json b/ruleset.schema.json new file mode 100644 index 0000000..84b3be6 --- /dev/null +++ b/ruleset.schema.json @@ -0,0 +1,217 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Ruleset Schema", + "type": "object", + "$ref": "#/definitions/intermediate", + "definitions": { + "rule": { + "type": "object", + "title": "Rule", + "description": "A single rule.", + "properties": { + "mode": { + "type": "string", + "title": "Mode", + "description": "Mode of the rule.", + "enum": [ + "white", + "black", + "param", + "regex", + "redirect", + "visit", + "lambda" + ] + }, + "description": { + "type": "string", + "title": "Description", + "description": "Description of the rule." + }, + "author": { + "type": "string", + "title": "Author", + "description": "Author of the rule." + }, + "std": { + "type": "boolean", + "title": "Standard", + "description": "Whether the URL search string shall be deemed standard." + }, + "params": { + "type": "array", + "title": "Params", + "description": "List of parameters to be kept, removed or processed.", + "items": { + "type": "string" + } + }, + "acts": { + "type": "array", + "title": "Acts", + "description": "List of actions to be performed.", + "items": { + "type": "string" + } + }, + "regex": { + "type": "array", + "title": "Regex", + "description": "List of regular expressions to be matched.", + "items": { + "type": "string" + } + }, + "replace": { + "type": "array", + "title": "Replace", + "description": "List of strings to replace matched parts.", + "items": { + "type": "string" + } + }, + "headers": { + "type": "object", + "title": "Headers", + "description": "The headers to use for web requests.", + "additionalProperties": { + "type": "string" + } + }, + "lambda": { + "type": "string", + "title": "Lambda", + "description": "The lambda function to use for processing." + }, + "continue": { + "type": "boolean", + "title": "Continue", + "description": "Whether to continue processing the URL." + } + }, + "required": [ + "mode", + "description", + "author" + ], + "allOf": [ + { + "if": { + "properties": { + "mode": { + "const": "white" + } + } + }, + "then": { + "required": [ + "params" + ] + } + }, + { + "if": { + "properties": { + "mode": { + "const": "black" + } + } + }, + "then": { + "required": [ + "params" + ] + } + }, + { + "if": { + "properties": { + "mode": { + "const": "param" + } + } + }, + "then": { + "required": [ + "params" + ] + } + }, + { + "if": { + "properties": { + "mode": { + "const": "regex" + } + } + }, + "then": { + "required": [ + "regex", + "replace" + ] + } + }, + { + "if": { + "properties": { + "mode": { + "const": "redirect" + } + } + }, + "then": { + "required": [] + } + }, + { + "if": { + "properties": { + "mode": { + "const": "visit" + } + } + }, + "then": { + "required": [] + } + }, + { + "if": { + "properties": { + "mode": { + "const": "lambda" + } + } + }, + "then": { + "required": [ + "lambda" + ] + } + } + ], + "additionalProperties": false + }, + "intermediate": { + "type": "object", + "title": "Intermediate", + "description": "An intermediate object. Expects another intermediate if ends with a slash, otherwise a rule.", + "patternProperties": { + "^[^/]+/$": { + "$ref": "#/definitions/intermediate" + }, + "^[^/]*$": { + "$ref": "#/definitions/rule" + }, + "^/.+/$": { + "$ref": "#/definitions/intermediate" + }, + "^/.+[^/]$": { + "$ref": "#/definitions/rule" + } + } + } + }, + "additionalProperties": false +}