Skip to content

Commit

Permalink
AG-33440: Add downloadUrl to generated filters metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
forcomprehension committed Jun 18, 2024
1 parent 60d8ab9 commit 5fc5381
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
14 changes: 12 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions schemas/filters.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"displayNumber",
"groupId",
"subscriptionUrl",
"downloadUrl",
"version",
"timeUpdated",
"languages",
Expand Down Expand Up @@ -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",
Expand Down
24 changes: 14 additions & 10 deletions src/main/platforms/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -364,30 +366,32 @@ 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 = {};

result.groups = metadata.groups.slice(0);
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);
Expand Down Expand Up @@ -595,7 +599,7 @@ module.exports = (() => {
filters: replacedExpiresFiltersMetadata,
};

metadata = rewriteSubscriptionUrls(metadata, config);
metadata = postprocessUrls(metadata, config);
metadata = removeRedundantFiltersMetadata(metadata, config.platform);

if (platform === 'MAC') {
Expand Down
1 change: 1 addition & 0 deletions src/main/utils/workaround.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ module.exports = (() => {
delete copy.tags;
delete copy.timeAdded;
delete copy.trustLevel;
delete copy.downloadUrl;
result.filters.push(copy);
}

Expand Down

0 comments on commit 5fc5381

Please sign in to comment.