-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e37c0b6
commit 11fa611
Showing
6 changed files
with
245 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict' | ||
|
||
// See available emoji at http://emoji.muan.co/ | ||
const emojic = require('emojic') | ||
const { checkErrorResponse } = require('../lib/error-helper') | ||
const BaseService = require('./base') | ||
const trace = require('./trace') | ||
|
||
class BaseHTTPService extends BaseService { | ||
async _requestHTTP({ url, options = {}, errorMessages = {} }) { | ||
const logTrace = (...args) => trace.logTrace('fetch', ...args) | ||
logTrace(emojic.bowAndArrow, 'Request', url, '\n', options) | ||
return this._sendAndCacheRequest(url, options) | ||
.then(({ res, buffer }) => { | ||
logTrace(emojic.dart, 'Response status code', res.statusCode) | ||
return { res, buffer } | ||
}) | ||
.then(checkErrorResponse.asPromise(errorMessages)) | ||
} | ||
} | ||
|
||
module.exports = BaseHTTPService |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
'use strict' | ||
|
||
const BaseHTTPService = require('../base-http') | ||
const { addv: versionText } = require('../../lib/text-formatters') | ||
const { version: versionColor } = require('../../lib/color-formatters') | ||
const { InvalidResponse } = require('../errors') | ||
|
||
module.exports = class FDroid extends BaseHTTPService { | ||
async fetch({ appId }) { | ||
// currently, we only use the txt format. There are few apps using the yml format. | ||
const url = `https://gitlab.com/fdroid/fdroiddata/raw/master/metadata/${appId}.txt` | ||
return this._requestHTTP({ | ||
url, | ||
options: {}, | ||
errorMessages: { | ||
404: 'app not found', | ||
}, | ||
}).then(({ res, buffer }) => { | ||
const metadata = buffer.toString() | ||
// we assume the layout as provided here: | ||
// https://gitlab.com/fdroid/fdroiddata/raw/master/metadata/axp.tool.apkextractor.txt | ||
const positionOfCurrentVersionAtEndOfTheFile = metadata.lastIndexOf( | ||
'Current Version:' | ||
) // credits: https://stackoverflow.com/a/11134049 | ||
const lastVersion = metadata.substring( | ||
positionOfCurrentVersionAtEndOfTheFile | ||
) | ||
const match = lastVersion.match(/^Current Version:\s*(.*?)\s*$/m) | ||
if (!match) { | ||
throw new InvalidResponse({ | ||
prettyMessage: 'invalid response', | ||
underlyingError: new Error('could not find version on website'), | ||
}) | ||
} | ||
return { version: match[1] } | ||
}) | ||
} | ||
|
||
static render({ version }) { | ||
return { | ||
message: versionText(version), | ||
color: versionColor(version), | ||
} | ||
} | ||
|
||
async handle({ appId }) { | ||
const result = await this.fetch({ appId }) | ||
return this.constructor.render(result) | ||
} | ||
|
||
// Metadata | ||
static get defaultBadgeData() { | ||
return { label: 'f-droid' } | ||
} | ||
|
||
static get category() { | ||
return 'version' | ||
} | ||
|
||
static get url() { | ||
return { | ||
base: 'f-droid/v', | ||
format: '(.+)', | ||
capture: ['appId'], | ||
} | ||
} | ||
|
||
static get examples() { | ||
return [ | ||
{ | ||
title: 'F-Droid', | ||
exampleUrl: 'org.thosp.yourlocalweather', | ||
urlPattern: ':appId', | ||
staticExample: this.render({ version: '1.0' }), | ||
keywords: ['fdroid', 'android', 'app'], | ||
}, | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
'use strict' | ||
|
||
const { isVPlusDottedVersionAtLeastOne } = require('../test-validators') | ||
const ServiceTester = require('../service-tester') | ||
const t = new ServiceTester({ id: 'f-droid', title: 'F-Droid' }) | ||
const Joi = require('joi') | ||
module.exports = t | ||
|
||
const testString = | ||
'Categories:System\n' + | ||
'License:MIT\n' + | ||
'Web Site:https:/axxapy/apkExtractor/blob/HEAD/README.md\n' + | ||
'Source Code:https:/axxapy/apkExtractor\n' + | ||
'Issue Tracker:https:/axxapy/apkExtractor/issues\n' + | ||
'\n' + | ||
'Auto Name:Apk Extractor\n' + | ||
'Summary:Get APK files from installed apps\n' + | ||
'Description:\n' + | ||
'Extract APKs from your device, even if installed from the Playstore. Root access\n' + | ||
'is required for paid apps.\n' + | ||
'\n' + | ||
'* Fast and easy to use.\n' + | ||
'* Extracts almost all applications, includes system applications.\n' + | ||
'* ROOT access only required for extracting paid apps.\n' + | ||
"* Apk's will be saved in /sdcard/Download/Eimon/.\n" + | ||
'* Provided Search option to search applications.\n' + | ||
'* Compatible with latest version of Android 6.0\n' + | ||
'* Saved apk format : AppPackageName.apk.\n' + | ||
'Current Version:1.8\n' + | ||
'.\n' + | ||
'\n' + | ||
'Repo Type:git\n' + | ||
'Repo:https:/axxapy/apkExtractor\n' + | ||
'\n' + | ||
'Build:1.0,1\n' + | ||
' commit=9b3b62c3ceda74b17eaa22c9e4f893aac10c4442\n' + | ||
' gradle=yes\n' + | ||
'\n' + | ||
'Build:1.1,2\n' + | ||
' commit=1.1\n' + | ||
' gradle=yes\n' + | ||
'\n' + | ||
'Build:1.2,3\n' + | ||
' disable=lintVitalRelease fails\n' + | ||
' commit=1.2\n' + | ||
' gradle=yes\n' + | ||
'\n' + | ||
'Build:1.3,4\n' + | ||
' commit=1.3\n' + | ||
' gradle=yes\n' + | ||
'\n' + | ||
'Build:1.4,5\n' + | ||
' commit=1.4\n' + | ||
' gradle=yes\n' + | ||
'\n' + | ||
'Auto Update Mode:Version %v\n' + | ||
'Update Check Mode:Tags\n' + | ||
'Current Version:1.4\n' + | ||
'Current Version Code:5\n' | ||
const base = 'https://gitlab.com' | ||
const path = '/fdroid/fdroiddata/raw/master/metadata/axp.tool.apkextractor.txt' | ||
|
||
t.create('Package is found') | ||
.get('/v/axp.tool.apkextractor.json') | ||
.intercept(nock => | ||
nock(base) | ||
.get(path) | ||
.reply(200, testString) | ||
) | ||
.expectJSON({ name: 'f-droid', value: 'v1.4' }) | ||
|
||
t.create('Package is not found') | ||
.get('/v/axp.tool.apkextractor.json') | ||
.intercept(nock => | ||
nock(base) | ||
.get(path) | ||
.reply(404, testString) | ||
) | ||
.expectJSON({ name: 'f-droid', value: 'app not found' }) | ||
|
||
t.create('The api changed') | ||
.get('/v/axp.tool.apkextractor.json') | ||
.intercept(nock => | ||
nock(base) | ||
.get(path) | ||
.reply(200, '') | ||
) | ||
.expectJSON({ name: 'f-droid', value: 'invalid response' }) | ||
|
||
/* If this test fails, either the API has changed or the app was deleted. */ | ||
t.create('The real api did not change') | ||
.get('/v/org.thosp.yourlocalweather.json') | ||
.timeout(10000) | ||
.expectJSONTypes( | ||
Joi.object().keys({ | ||
name: 'f-droid', | ||
value: isVPlusDottedVersionAtLeastOne, | ||
}) | ||
) |