forked from NemeSnz/uplink-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
access.js
60 lines (55 loc) · 2.55 KB
/
access.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
49
50
51
52
53
54
55
56
57
58
59
60
var uplink = require("bindings")("uplink");
const ProjectResultStruct = require('./project.js');
const errorhandle = require('./error.js');
//
class AccessResultStruct {
constructor(access){
this.access = access;
}
//function opens Storj(V3) project using access grant.
//Input : None
//Output : Project(Object)
async openProject(){
var project = await uplink.open_project(this.access).catch((error) => {
errorhandle.storjException(error.error.code,error.error.message);
});
var projectResultReturn = new ProjectResultStruct(project.project);
return(projectResultReturn);
}
//function opens Storj(V3) project using access grant and custom configuration.
//Input : None
//Output : Project(Object)
async configOpenProject(){
var project = await uplink.config_open_project(this.access).catch((error) => {
errorhandle.storjException(error.error.code,error.error.message);
});
var projectResultReturn = new ProjectResultStruct(project.project);
return(projectResultReturn);
}
//
//function Share creates a new access grant with specific permissions.
//Access grants can only have their existing permissions restricted, and the resulting
//access grant will only allow for the intersection of all previous Share calls in the
//access grant construction chain.
//Prefixes, if provided, restrict the access grant (and internal encryption information)
//to only contain enough information to allow access to just those prefixes.
//Input : Permission (Object) , sharePrefixListArray (Array) , sharePrefixListArraylength (Int)
//Output : Project(Object)
async share(permission,sharePrefixListArray,sharePrefixListArraylength){
var sharedAccess = await uplink.access_share(this.access,permission,sharePrefixListArray,sharePrefixListArraylength).catch((error) => {
errorhandle.storjException(error.error.code,error.error.message);
});
var sharedAccessResultReturn = new AccessResultStruct(sharedAccess.access);
return(sharedAccessResultReturn);
}
//function serializes an access grant such that it can be used later with ParseAccess or other tools.
//Input : None
//Output : SharedString (String)
async serialize(){
var stringResult = await uplink.access_serialize(this.access).catch((error) => {
errorhandle.storjException(error.error.code,error.error.message);
});
return stringResult;
}
}
module.exports = AccessResultStruct;