Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ab896dfe authored by Guillaume Jacquart's avatar Guillaume Jacquart
Browse files

5080-Add list format validator.

parent 4b3f377a
Loading
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -7,4 +7,5 @@ build-list:
  stage: deploy
  script: 
    - node build_list.js
    - node validate_json.js
    - node upload_list.js
+1 −47
Original line number Diff line number Diff line
const outputFile = "list/e_trackers.json"


const ciJobToken = process.env.CI_JOB_TOKEN
const ciApiV4Url = process.env.CI_API_V4_URL
const giltabProjectId = "1183"

const adawayUri = "https://adaway.org/hosts.txt"
const exodusUri = "https://reports.exodus-privacy.eu.org/api/trackers"

@@ -12,7 +7,6 @@ const exodusUri = "https://reports.exodus-privacy.eu.org/api/trackers"
const https = require('https')
const fs = require('fs')
const url = require('url')
//const process = require('process')

function fetch(url) {
    return new Promise((resolve, reject) => {
@@ -58,22 +52,13 @@ fetch(adawayUri)
    hostnames = enrichExodusWithAdaway(trackers, hostnames)
    console.log("enrich exodus OK")  
    hostnames = createdLevel2Trackers(trackers, hostnames)

    if (trackers.length < 400) {
        throw Exception(`Not enough trackers (${trackers.length}), abort`)
    }
    console.log("Trackers list finished")
})
.then(toto => {
    return printTrackers()
})
.then(trackersJson => {
    //saveTrackersFile(trackersJson)
    return uploadTrackers(trackersJson)

})
.then(res => {
    console.log(`upload response: ${res}`)
    return saveTrackersFile(trackersJson)
})
.then(toto => {
    console.log("DONE")
@@ -173,34 +158,3 @@ function saveTrackersFile(trackersJson) {
    fs.writeFileSync(outputFile, trackersJson)
}
function uploadTrackers(trackersJson) { return new Promise((resolve, reject) => {
    const body = JSON.stringify({
        content: trackersJson,
        branch: 'main',
        commit_message: `Update trackers list ; ${trackers.length} trackers`
    })

    const urlComponents = url.parse(`${ciApiV4Url}/projects/${encodeURIComponent(giltabProjectId)}/repository/files/${encodeURIComponent(outputFile)}`)

    const options = {
        method: 'PUT',
        port: 443,
        hostname: urlComponents.hostname,
        path: urlComponents.path,
        headers: {
            'PRIVATE-TOKEN': ciJobToken,
            'Content-Type': 'application/json',
            'Content-Length': body.length,
        }
    }

    const req = https.request(options, response => {
        let data = ""
        response.on('data', (chunk) => { data += chunk })
        response.on('end', () => resolve(data))
    })
    req.on('error', reject)

    req.write(body)
    req.end()
})}
+15 −0
Original line number Diff line number Diff line
{
  "name": "tracker-list",
  "lockfileVersion": 2,
  "requires": true,
  "packages": {
    "node_modules/jsonschema": {
      "version": "1.4.1",
      "resolved": "https://registry.npmjs.org/jsonschema/-/jsonschema-1.4.1.tgz",
      "integrity": "sha512-S6cATIPVv1z0IlxdN+zUk5EPjkGCdnhN4wVSBlvoUO1tOLJootbo9CquNJmbIh4yikWHiUedhRYrNPn1arpEmQ==",
      "engines": {
        "node": "*"
      }
    }
  }
}
+10 −0
Original line number Diff line number Diff line
# editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
+21 −0
Original line number Diff line number Diff line
jsonschema is licensed under MIT license.

Copyright (C) 2012-2015 Tom de Grunt <tom@degrunt.nl>

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading