1
0
mirror of https://github.com/schollz/cowyo.git synced 2023-08-10 21:13:00 +03:00

Create keystore.js

Former-commit-id: 6e57c4fa824b56c208f0910bd462b7145b3a201d [formerly 6750759dea61eb28bc5cca842d5fb3659fd9795b] [formerly 69062d21361147bfc05d329f26e4ba5167a59565 [formerly 83dfac9923a9ce6869b5b62f34d5282927480cdf [formerly 169e4b41c9]]]
Former-commit-id: fed116cda64134c4b76f2665f283d08176697b1c [formerly 8654e5a8f910d7f5135572eab42c48511e62f38f]
Former-commit-id: 136a617fe456bdea15c6d4173f6abd9bc4bba819
Former-commit-id: ad4ed37898
This commit is contained in:
Zack 2016-12-13 06:59:04 -08:00 committed by GitHub
parent 4ac089780e
commit 074b776984

42
keystore/keystore.js Normal file
View File

@ -0,0 +1,42 @@
function save(key, value) {
c = new WebSocket('wss://cowyo.com/ws');
return new Promise(function (resolve, reject) {
try {
c.onopen = function (_) {
c.send(JSON.stringify({
TextData: JSON.stringify(value),
Title: `${key}`,
UpdateServer: true,
UpdateClient: false,
}));
return resolve(true);
}
} catch(e) {
return reject(e);
}
});
}
// save('hello2', 'world');
function get(key) {
c = new WebSocket('wss://cowyo.com/ws');
return new Promise(function (resolve, reject) {
try {
c.onmessage = function(evt) {
return resolve(JSON.parse(JSON.parse(evt.data).TextData));
}
c.onopen = function (_) {
c.send(JSON.stringify({
Title: `${key}`,
UpdateClient: true,
}));
};
} catch(e) {
return reject(e);
}
});
}