56 lines
1.6 KiB
JavaScript
56 lines
1.6 KiB
JavaScript
import { createHash } from 'crypto';
|
|
import Utils from '../utils/utils.js';
|
|
import DebugInfo from '../models/DebugInfo.js';
|
|
|
|
const baseUrl = 'https://www.nomerogram.ru/api/v1.1';
|
|
|
|
const secretSuffix = 'queivoo1ieNgae2e';
|
|
const appId = 'p15';
|
|
const deviceId = '01b854631cb28e175ffbcccf6114acc3';
|
|
const from = 'search';
|
|
const userAgent = 'Nomerogram/2.18 (iPhone; iOS 13.7; Scale/2.00)';
|
|
|
|
class NomerogramProvider {
|
|
static async getGroups(number) {
|
|
try {
|
|
let timestamp = Math.floor(Date.now() / 1000);
|
|
let secretSource =
|
|
appId + number + deviceId + from + timestamp + secretSuffix;
|
|
|
|
let hash = createHash('sha256');
|
|
hash.update(secretSource);
|
|
let secret = hash.digest('hex');
|
|
|
|
let url = `${baseUrl}/group/list?from=${from}&carplate=${number}×tamp=${timestamp}&secret=${secret}&app_id=${appId}&device_id=${deviceId}`;
|
|
let result = await fetch(url, {
|
|
signal: AbortSignal.timeout(5000),
|
|
headers: { 'User-Agent': userAgent },
|
|
});
|
|
let json = await result.json();
|
|
|
|
if (!json.success) {
|
|
console.log('Nomerogram error: ', json.message);
|
|
throw Error(json.message);
|
|
//return [];
|
|
}
|
|
|
|
console.log('Nomerogram found ads: ', json.data.groups.length);
|
|
return json.data.groups.flatMap((g) => {
|
|
return g.photos.map((p) => {
|
|
return {
|
|
url: p.src.default,
|
|
thumbnail: p.src.thumbnail,
|
|
date: Utils.parseDate(g.date),
|
|
};
|
|
});
|
|
});
|
|
} catch (ex) {
|
|
console.log('Nomerogram error: ', ex.message);
|
|
ex.debugInfo = { nomerogram: DebugInfo.fromError(ex.message) };
|
|
throw ex;
|
|
}
|
|
}
|
|
}
|
|
|
|
export default NomerogramProvider;
|