Created
June 23, 2021 18:24
-
-
Save scripting/6a59532e1a2d1d0a8e6120cf07b9af45 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"github": { | |
"username": "scripting", | |
"repo": "instantOutlines", | |
"repoPath": "", | |
"password": "xxx", | |
"committer": { | |
"name": "Bull Mancuso", | |
"email": "[email protected]" | |
}, | |
"message": "reliability test", | |
"userAgent": "testgithubasstorage" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "testgithubasstorage", | |
"version": "0.4.0", | |
"main": "testgithubasstorage.js", | |
"dependencies" : { | |
"request": "*", | |
"daveutils": "*", | |
"davegithub": "*" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const myVersion = "0.4.0", myProductName = "testgithubasstorage"; | |
const fs = require ("fs"); | |
const request = require ("request"); | |
const utils = require ("daveutils"); | |
const davegithub = require ("davegithub"); | |
var config = { | |
}; | |
function uploadToGithub (relpath, data, type, callback) { | |
const options = { | |
username: config.github.username, | |
repo: config.github.repo, | |
repoPath: config.github.repoPath + relpath, | |
password: config.github.password, | |
data: data, | |
type: (type === undefined) ? "text/plain" : type, | |
committer: config.github.committer, | |
message: config.github.message, | |
userAgent: config.github.userAgent | |
}; | |
davegithub.uploadFile (options, function (err, response, body) { | |
if (err) { | |
console.log ("uploadToGithub: err.message == " + err.message); | |
} | |
if (callback !== undefined) { | |
callback (err); | |
} | |
}); | |
} | |
function readConfig (f, config, callback) { | |
fs.readFile (f, function (err, jsontext) { | |
if (err) { | |
console.log ("Error reading " + f); | |
} | |
else { | |
try { | |
var jstruct = JSON.parse (jsontext); | |
for (var x in jstruct) { | |
config [x] = jstruct [x]; | |
} | |
callback (); | |
} | |
catch (err) { | |
console.log (err.message); | |
} | |
} | |
}); | |
} | |
function httpReadUrl (url, callback) { | |
request (url, function (error, response, data) { | |
if (!error && (response.statusCode == 200)) { | |
callback (data) | |
} | |
else { | |
callback (undefined); | |
} | |
}); | |
} | |
function everyMinute () { | |
var nowtext = new Date ().toLocaleTimeString (); | |
uploadToGithub ("misc/now.txt", nowtext, "text/plain", function (err) { | |
setTimeout (function () { //wait ten seconds to check | |
request ("https://raw.githubusercontent.com/scripting/instantOutlines/main/misc/now.txt", function (err, response, data) { | |
var result; | |
if (data.toString () == nowtext) { | |
result = "good"; | |
} | |
else { | |
result = "bad"; | |
} | |
console.log ("everyMinute: " + nowtext + ", status == " + response.statusCode + ", " + result); | |
}); | |
}, 1000 * 10); | |
}); | |
} | |
readConfig ("config.json", config, function () { | |
console.log ("config == " + utils.jsonStringify (config)); | |
everyMinute (); | |
utils.runEveryMinute (everyMinute); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment