-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathrhHelper.js
More file actions
44 lines (42 loc) · 1.81 KB
/
Copy pathrhHelper.js
File metadata and controls
44 lines (42 loc) · 1.81 KB
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
import { RammerheadAPI, StrShuffler } from './rhAPI.js';
let rhFunc = {}
rhFunc = {
rhInteract:
async function(origin, url){
let api = new RammerheadAPI(origin);
await fetch(origin);
if ( localStorage.getItem('rammerhead_session') && (await api.sessionExists(localStorage.getItem('rammerhead_session'))) ) {
const test = await fetch( new URL(localStorage.getItem('rammerhead_session'), origin) );
//await api.deleteSession(localStorage.getItem('rammerhead_session'));
// 404 = good, 403 = Sessions must come from the same IP
if (test.status === 403) localStorage.removeItem('rammerhead_session');
} else {
localStorage.removeItem('rammerhead_session');
}
let session;
switch (localStorage.getItem('rammerhead_session')) {
case null:
case undefined:
case 'null':
case 'undefined':
session = (await api.newSession());
break;
default:
session = localStorage.getItem('rammerhead_session')
}
localStorage.setItem('rammerhead_session', session)
await api.editSession(session, false, true);
const dict = await api.shuffleDict(session);
const shuffler = new StrShuffler(dict);
return new URL(`${session}/${shuffler.shuffle(url)}`, origin);
},
rhDecrypt:
async function(origin, value){
let api = new RammerheadAPI(origin);
let session = localStorage.getItem('rammerhead_session')
const dict = await api.shuffleDict(session);
const shuffler = new StrShuffler(dict);
return shuffler.unshuffle(value)
}
}
export {rhFunc}