mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-02-06 15:04:58 +00:00
Create apikey.js
This commit is contained in:
parent
7aeb8edfc2
commit
b4ace286e3
39
lib/apikey.js
Normal file
39
lib/apikey.js
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
// apikey.js
|
||||||
|
// https://github.com/gnh1201/welsonjs
|
||||||
|
var FILE = require("lib/file");
|
||||||
|
|
||||||
|
function loadTextFile(filename) {
|
||||||
|
if (FILE.fileExists(filename)) {
|
||||||
|
return FILE.readFile("data/apikey.json", FILE.CdoCharset.CdoUTF_8);
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadKeyData() {
|
||||||
|
var s = loadTextFile("data/apikey.json");
|
||||||
|
return JSON.parse(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getApiKey(serviceName) {
|
||||||
|
var apikey = "";
|
||||||
|
if (serviceName in API_KEY_DATA) {
|
||||||
|
apikey = API_KEY_DATA[serviceName];
|
||||||
|
}
|
||||||
|
|
||||||
|
var prelude = "file:";
|
||||||
|
if (apikey.indexOf(prelude) == 0) {
|
||||||
|
var filename = apikey.substring(prelude.length);
|
||||||
|
apikey = loadTextFile(filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
return apikey;
|
||||||
|
}
|
||||||
|
|
||||||
|
var API_KEY_DATA = loadKeyData();
|
||||||
|
|
||||||
|
exports.getApiKey = getApiKey;
|
||||||
|
|
||||||
|
exports.VERSIONINFO = "API key library (apikey.js) version 0.1";
|
||||||
|
exports.AUTHOR = "abuse@catswords.net";
|
||||||
|
exports.global = global;
|
||||||
|
exports.require = global.require;
|
Loading…
Reference in New Issue
Block a user