This commit is contained in:
2020-05-25 16:07:30 +03:00
parent 0753359f07
commit 13971100cf
55 changed files with 32279 additions and 6964 deletions

34
api/src/util/Cache.js Normal file
View File

@@ -0,0 +1,34 @@
import Cacheman from 'cacheman';
import { CACHE } from './Constants';
const formatKey = (name) => {
if (!name) {
throw Error('No number plate specified');
}
return `${CACHE.PREFIX.plate}${name}`;
};
class Cache {
manager;
constructor() {
this.manager = new Cacheman({
ttl: CACHE.ttl,
engine: CACHE.engine,
tmpDir: CACHE.directory,
});
}
async get(name) {
return this.manager.get(formatKey(name));
}
save(name, data) {
if (!data) {
throw Error(`No data for caching car ${name}`);
}
this.manager.set(formatKey(name), data);
}
}
export default Cache;

23
api/src/util/Constants.js Normal file
View File

@@ -0,0 +1,23 @@
export const BASE_URL = 'https://eteenindus.mnt.ee/public/soidukDetailvaadeAvalik.jsf';
export const SEARCH_URL = 'https://eteenindus.mnt.ee/public/soidukTaustakontroll.jsf';
export const SITE_COOKIES = [{
name: 'eteenindus_lang',
value: 'en',
}];
export const NAVIGATION_TIMEOUT = 3500;
const TMP_DIR = 'tmp';
export const CACHE = {
ttl: 600,
engine: 'file',
directory: `${TMP_DIR}/cache`,
PREFIX: {
plate: 'car-',
},
};
export const TEMP_DIR = {
screenshots: `${TMP_DIR}/screenshots`,
};

20
api/src/util/Selectors.js Normal file
View File

@@ -0,0 +1,20 @@
export default {
form: {
plate: '#j_idt104\\:regMark',
},
container: {
main: '#content',
form: '#j_idt104',
},
properties: {
plate: '.content-title h1',
name: '.content-title p:first-of-type',
vin: '.content-title p:nth-of-type(2)',
main: {
container: '.asset',
rows: '.asset-details table tbody tr',
cell: 'td',
irregularText: 'span:first-child', // to get past spans, superscripts and such
},
},
};