diff --git a/CHANGELOG.md b/CHANGELOG.md index 93799ee..54df36c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,13 +5,23 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased] +## [v1.1.138] - 2024-06-18 + + +### Added + +- Added `downloadUrl` to generated filters metadata + +[v1.1.138]: https://github.com/AdguardTeam/FiltersCompiler/compare/v1.1.137...v1.1.138 + +## [v1.1.137] - 2024-05-30 + ### Fixed - Return the rules in their original order after applying the `@include` directive option `/optimiseDomainBlockingRules` [#217] -[Unreleased]: https://github.com/AdguardTeam/FiltersCompiler/compare/v1.1.136...HEAD +[v1.1.137]: https://github.com/AdguardTeam/FiltersCompiler/compare/v1.1.136...v1.1.137 ## [v1.1.136] - 2024-05-22 diff --git a/schemas/filters.schema.json b/schemas/filters.schema.json index e279d79..a81b786 100644 --- a/schemas/filters.schema.json +++ b/schemas/filters.schema.json @@ -108,6 +108,7 @@ "displayNumber", "groupId", "subscriptionUrl", + "downloadUrl", "version", "timeUpdated", "languages", @@ -200,6 +201,16 @@ ], "pattern": "^(.*)$" }, + "downloadUrl": { + "$id": "#/properties/filters/items/properties/downloadUrl", + "type": "string", + "title": "The download URL Schema", + "default": "", + "examples": [ + "https://filters.adtidy.org/extension/safari/filters/1.txt" + ], + "pattern": "^(.*)$" + }, "version": { "$id": "#/properties/filters/items/properties/version", "type": "string", diff --git a/src/main/platforms/generator.js b/src/main/platforms/generator.js index c9430cb..cdde96c 100644 --- a/src/main/platforms/generator.js +++ b/src/main/platforms/generator.js @@ -20,6 +20,8 @@ module.exports = (() => { const filterIdsPool = []; const metadataFilterIdsPool = []; + const OPTIMIZED_PLATFORMS_LIST = ['ext_safari', 'android', 'ios']; + const PLATFORM_FILTERS_DIR = 'filters'; const FILTERS_METADATA_FILE_JSON = 'filters.json'; const FILTERS_I18N_METADATA_FILE_JSON = 'filters_i18n.json'; @@ -364,15 +366,15 @@ module.exports = (() => { }; /** - * Rewrites subscription urls for specified platform config + * Does several things with filters URLs: + * 1. Rewrites subscription urls for specified platform config + * 2. Adds downloadUrl field to the filter * * @param metadata * @param config */ - const rewriteSubscriptionUrls = (metadata, config) => { - const OPTIMIZED_PLATFORMS = ['ext_safari', 'android', 'ios']; - - const useOptimized = OPTIMIZED_PLATFORMS.indexOf(config.platform) >= 0; + const postprocessUrls = (metadata, config) => { + const useOptimized = OPTIMIZED_PLATFORMS_LIST.indexOf(config.platform) >= 0; const result = {}; @@ -380,14 +382,16 @@ module.exports = (() => { result.tags = metadata.tags.slice(0); result.filters = []; + const platformPath = config.path; // eslint-disable-next-line no-restricted-syntax for (const f of metadata.filters) { - const copy = { ...f }; + const fileName = `${f.filterId}${useOptimized ? '_optimized' : ''}.txt`; + const downloadUrl = `${adguardFiltersServerUrl}${platformPath}/filters/${fileName}`; + + const copy = { ...f, downloadUrl }; if (copy.subscriptionUrl && copy.subscriptionUrl.startsWith(adguardFiltersServerUrl)) { - const fileName = `${copy.filterId}${useOptimized ? '_optimized' : ''}.txt`; - const platformPath = config.path; - copy.subscriptionUrl = `${adguardFiltersServerUrl}${platformPath}/filters/${fileName}`; + copy.subscriptionUrl = downloadUrl; } result.filters.push(copy); @@ -595,7 +599,7 @@ module.exports = (() => { filters: replacedExpiresFiltersMetadata, }; - metadata = rewriteSubscriptionUrls(metadata, config); + metadata = postprocessUrls(metadata, config); metadata = removeRedundantFiltersMetadata(metadata, config.platform); if (platform === 'MAC') { diff --git a/src/main/utils/workaround.js b/src/main/utils/workaround.js index e7ab7d4..610602f 100644 --- a/src/main/utils/workaround.js +++ b/src/main/utils/workaround.js @@ -146,6 +146,7 @@ module.exports = (() => { delete copy.tags; delete copy.timeAdded; delete copy.trustLevel; + delete copy.downloadUrl; result.filters.push(copy); }