-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhatcheck.js
48 lines (34 loc) · 858 Bytes
/
hatcheck.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
hatcheck
prototype for a CAS over HTTP
*/
var fs = require('fs');
var sha1 = require('sha1');
var path = require('path');
var content = { 'name':'Fedora', 'color':'black' };
var id = sha1(content);
var getDirName = function (id) {
return id.substr(0, 2);
}
var getFileName = function (id) {
return id.slice(2);
}
var mkdirSync = function (path) {
try {
fs.mkdirSync(path);
} catch(e) {
if ( e.code != 'EEXIST' ) throw e;
}
}
/* console.log(id); */
var dirName = getDirName(id);
/* console.log(dirName); */
var fileName = getFileName(id);
/* console.log(fileName); */
mkdirSync( path.join('objects', dirName) );
fs.writeFile(path.join('objects', dirName, fileName), content, function(err) {
if(err) {
return console.log(err);
}
console.log("Thank you for the content. Here's your ticket: " + id);
});