You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
769 B
30 lines
769 B
import { getJsonDataSync, writeJsonDataSync } from './json'; |
|
import { METRICS_PATH } from '../config'; |
|
|
|
import * as crypto from 'crypto'; |
|
|
|
import * as path from 'path'; |
|
|
|
|
|
function saveTargets(targets) { |
|
let metrics = []; |
|
for (let target of targets) { |
|
metrics.push(saveTarget(target)); |
|
} |
|
return metrics; |
|
} |
|
|
|
function saveTarget(target) { |
|
//const md5 = crypto.createHash('md5') |
|
const targetId = crypto.createHash('md5').update(JSON.stringify(target)).digest('hex'); |
|
let filename = path.join(METRICS_PATH, `${targetId}.json`); |
|
writeJsonDataSync(filename, target); |
|
return targetId; |
|
} |
|
|
|
function getTarget(targetId) { |
|
let filename = path.join(METRICS_PATH, `${targetId}.json`); |
|
return getJsonDataSync(filename); |
|
} |
|
|
|
export { saveTargets, getTarget }
|
|
|