Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON adblock resources support #74

Merged
merged 2 commits into from Nov 12, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -0,0 +1,3 @@
[submodule "submodules/uBlock"]
path = submodules/uBlock
url = https://github.com/brave/uBlock

Some generated files are not rendered by default. Learn more.

@@ -4,7 +4,7 @@
"description": "Packages component and theme extensions used in the Brave browser",
"dependencies": {
"ad-block": "brave/ad-block",
"adblock-rs": "^0.1.28",
"adblock-rs": "^0.1.36",
"ajv": "^6.10.0",
"autoplay-whitelist": "github:brave/autoplay-whitelist",
"aws-sdk": "^2.449.0",
@@ -2,11 +2,34 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

const { Engine, lists } = require('adblock-rs')
const { Engine, lists, uBlockResources } = require('adblock-rs')
const path = require('path')
const fs = require('fs')
const request = require('request')

const uBlockRevision = '978f04219a1f41f3fab7ad5c38ec2a1a021920fe'
const uBlockGitArchiveURL = `https://github.com/gorhill/uBlock/archive/${uBlockRevision}.zip`
This conversation was marked as resolved by antonok-edm

This comment has been minimized.

Copy link
@bbondy

bbondy Nov 7, 2019

Member

Can we remove these 2 lines now because of the submodule?


const uBlockLocalRoot = 'submodules/uBlock'
const uBlockWebAccessibleResources = path.join(uBlockLocalRoot, 'src/web_accessible_resources')
const uBlockRedirectEngine = path.join(uBlockLocalRoot, 'src/js/redirect-engine.js')
const uBlockScriptlets = path.join(uBlockLocalRoot, 'assets/resources/scriptlets.js')

/**
* Returns a promise that generates a resources file from the uBlock Origin
* repo hosted on GitHub
*/
const generateResourcesFile = (uBlockArchiveZip) => {
return new Promise((resolve, reject) => {
const jsonData = JSON.stringify(uBlockResources(
uBlockWebAccessibleResources,
uBlockRedirectEngine,
uBlockScriptlets
))
fs.writeFileSync(getOutPath('resources.json', 'default'), jsonData, 'utf8')
})
}

/**
* Returns a promise that which resolves with the list data
*
@@ -47,6 +70,25 @@ const getListFilterFunction = (uuid) => {
return undefined
}

/**
* Obtains the output path to store a file given the specied name and subdir
*/
const getOutPath = (outputFilename, outSubdir) => {
let outPath = path.join('build')
if (!fs.existsSync(outPath)) {
fs.mkdirSync(outPath)
}
outPath = path.join(outPath, 'ad-block-updater')
if (!fs.existsSync(outPath)) {
fs.mkdirSync(outPath)
}
outPath = path.join(outPath, outSubdir)
if (!fs.existsSync(outPath)) {
fs.mkdirSync(outPath)
}
return path.join(outPath, outputFilename)
}

/**
* Parses the passed in filter rule data and serializes a data file to disk.
*
@@ -62,19 +104,8 @@ const generateDataFileFromString = (filterRuleData, outputDATFilename, outSubdir
}
const client = new Engine(rules.split('\n'))
const arrayBuffer = client.serialize()
let outPath = path.join('build')
if (!fs.existsSync(outPath)) {
fs.mkdirSync(outPath)
}
outPath = path.join(outPath, 'ad-block-updater')
if (!fs.existsSync(outPath)) {
fs.mkdirSync(outPath)
}
outPath = path.join(outPath, outSubdir)
if (!fs.existsSync(outPath)) {
fs.mkdirSync(outPath)
}
fs.writeFileSync(path.join(outPath, outputDATFilename), Buffer.from(arrayBuffer))
const outPath = getOutPath(outputDATFilename, outSubdir)
fs.writeFileSync(outPath, Buffer.from(arrayBuffer))
}

/**
@@ -121,7 +152,7 @@ const generateDataFilesForAllRegions = () => {
}

/**
* Convenience function that generates a DAT file for the default list
* Convenience function that generates a DAT file and resources file for the default list
*/
const generateDataFilesForList = (lists, filename) => {
let promises = []
@@ -134,6 +165,7 @@ const generateDataFilesForList = (lists, filename) => {
p = p.then((listBuffers) => {
generateDataFileFromString(listBuffers, filename, 'default')
})
p = p.then(generateResourcesFile)
return p
}

Submodule uBlock added at fcfa83
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.