first commit

This commit is contained in:
Gianmarco Pettinato 2021-09-23 15:45:12 +02:00
parent b2cd5d7c5c
commit 0edd12ebad
10 changed files with 15624 additions and 170 deletions

View File

@ -18,7 +18,7 @@
"rules": {
"indent": [
"error",
4
2
],
"linebreak-style": [
"error",

15753
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -10,10 +10,12 @@
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"dcc-utils": "^0.2.0",
"express": "^4.17.1",
"typescript": "^4.4.3"
},
"devDependencies": {
"@types/express": "^4.17.13",
"@types/node": "^16.9.6",
"@typescript-eslint/eslint-plugin": "^4.31.2",
"@typescript-eslint/parser": "^4.31.2",

View File

@ -1,5 +1,5 @@
import { Request, Response } from 'express';
export const get = (req: Request, res: Response):void => {
res.status(200).send({});
res.status(200).send({});
};

View File

@ -7,10 +7,10 @@ export default class GreenApi implements API {
private router: Router;
constructor(router: Router) {
this.router = router;
this.router = router;
}
setupApi():void {
this.router.get('/example',exampleMW.canGet,exampleCtrl.get);
this.router.get('/example',exampleMW.canGet,exampleCtrl.get);
}
}

View File

@ -2,12 +2,12 @@ import GreenApi from './green';
import { Router, Express } from 'express';
export const setupApis = (application: Express):void => {
const router = Router();
const exampleApi = new GreenApi(router);
const router = Router();
const exampleApi = new GreenApi(router);
exampleApi.setupApi();
exampleApi.setupApi();
application.use('/api', router);
application.use('/api', router);
};
export interface API {

View File

@ -1,13 +1,13 @@
import app from './app';
const server = app.listen(app.get('port'), () => {
console.log(
'App is running at http://localhost:%d in %s mode',
app.get('port'),
app.get('env')
);
console.log(
'App is running at http://localhost:%d in %s mode',
app.get('port'),
app.get('env')
);
console.log('Press CTRL-C to stop\n');
console.log('Press CTRL-C to stop\n');
});
export default server;

View File

@ -13,7 +13,7 @@ export class CertificateDownloader{
const savedData = JSON.parse(localStorage.getItem(this.keyStorage) || '{}');
if(savedData.lastupdateDate == null || Date.now() - savedData?.lastupdateDate > this.timeSpan){
this.getAllCertificate()
.then(() => { console.log('could not read the certificates from the local file'); return this.cerficateCollection })
.then(() => { console.log('could not read the certificates from the local file'); return this.cerficateCollection; })
.catch(console.error);
}
console.log('cerficates collection is valid loading from local source');
@ -36,7 +36,7 @@ export class CertificateDownloader{
this.cerficateCollection = await response.json();
console.log(response);
const lastupdateDate = Date.now();
localStorage.setItem(this.keyStorage, JSON.stringify({'certificates':this.cerficateCollection, lastupdateDate}))
localStorage.setItem(this.keyStorage, JSON.stringify({'certificates':this.cerficateCollection, lastupdateDate}));
// fs.writeFile('./cerificate_collection.json', JSON.stringify({'certificates':this.cerficateCollection, lastupdateDate}),'utf8',console.error);
}else{
throw new Error(response.statusText);

View File

@ -14,7 +14,7 @@ export class RuleDownloader {
const savedData = JSON.parse(localStorage.getItem(this.keyStorage) || '{}');
if(savedData.lastupdateDate == null || Date.now() - savedData?.lastupdateDate > this.timeSpan){
this.getSettings()
.then(() => { console.log('could not read the certificates from the local file'); return this.rules })
.then(() => { console.log('could not read the certificates from the local file'); return this.rules; })
.catch(console.error);
}
console.log('cerficates collection is valid loading from local source');

View File

@ -1,17 +1,16 @@
import { CertificateDownloader } from './CertificateDownloader';
import { RuleDownloader } from './RuleDownloader';
import {DCC} from 'dcc-utils';
import fs from 'fs';
export default class Verifier {
static certDownloader: CertificateDownloader;
static ruleDownloader: RuleDownloader;
static certificateList: any;
static certificateList: unknown;
static async setup():Promise<void> {
Verifier.certDownloader = CertificateDownloader.getCertificateDownloader();
Verifier.ruleDownloader = RuleDownloader.getRuleDownloader();
Verifier.certificateList = await Verifier.certDownloader.getCertificates()
Verifier.certificateList = await Verifier.certDownloader.getCertificates();
}
static async checkCertificate(certificate:string): Promise<unknown>{