@openinc/parse-server-opendash
Version:
Parse Server Cloud Code for open.INC Stack.
29 lines (28 loc) • 976 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getGoogleApiKey = getGoogleApiKey;
exports.get = get;
const url_1 = require("url");
const config_1 = require("../features/config");
function getGoogleApiKey() {
const API_KEY = config_1.ConfigInstance.getInstance().get("GEO_GOOGLE_API_KEY");
if (!API_KEY) {
throw new Parse.Error(Parse.Error.INTERNAL_SERVER_ERROR, `Feature not enabled [GEO_GOOGLE_API_KEY-1]`);
}
return API_KEY;
}
async function get(path, params) {
const key = getGoogleApiKey();
const qs = new url_1.URLSearchParams();
qs.set("key", key);
qs.set("language", "de");
for (const [key, value] of Object.entries(params)) {
qs.set(key, value);
}
const url = "https://maps.googleapis.com" + path + "?" + qs.toString();
const response = await fetch(url);
if (!response.ok) {
throw new Error("Bad Statuscode");
}
return (await response.json());
}