-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathServerInterface.js
More file actions
96 lines (78 loc) · 2.97 KB
/
ServerInterface.js
File metadata and controls
96 lines (78 loc) · 2.97 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright (c) 2017 Euan Ong
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the The GNU Affero General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// You should have received a copy of the GNU Affero General Public
// License along with this library; if not, write to the Free Software
// Foundation, 51 Franklin Street, Suite 500 Boston, MA 02110-1335 USA
/*
global
jQuery
*/
/*
exported
ServerInterface
*/
// eslint-disable-next-line no-unused-vars
class ServerInterface {
constructor(Planet) {
this.ServerURL = "https://musicblocks.sugarlabs.org/planet-server/index.php";
this.ConnectionFailureData = {"success": false, "error": "ERROR_CONNECTION_FAILURE"};
this.APIKey = "3f2d3a4c-c7a4-4c3c-892e-ac43784f7381" ;
}
request (data, callback) {
data["api-key"] = this.APIKey;
// eslint-disable-next-line no-unused-vars
const req = jQuery.ajax({
type: "POST",
url: this.ServerURL,
data: data
})
.done(data => {
callback(data);
})
.fail(() => {
callback(this.ConnectionFailureData);
});
};
getTagManifest(callback) {
const obj = {"action": "getTagManifest"};
this.request(obj, callback);
};
addProject (data, callback) {
const obj = {"action": "addProject", "ProjectJSON": data};
this.request(obj, callback);
};
downloadProjectList (ProjectTags, ProjectSort, Start, End, callback) {
const obj = {"action": "downloadProjectList", "ProjectTags": ProjectTags, "ProjectSort": ProjectSort, "Start": Start, "End": End};
this.request(obj, callback);
};
getProjectDetails (ProjectID, callback) {
const obj = {"action": "getProjectDetails", "ProjectID": ProjectID};
this.request(obj, callback);
};
searchProjects (Search, ProjectSort, Start, End, callback) {
const obj = {"action": "searchProjects", "Search": Search, "ProjectSort": ProjectSort, "Start": Start, "End": End};
this.request(obj, callback);
};
downloadProject(ProjectID, callback) {
const obj = {"action": "downloadProject", "ProjectID": ProjectID};
this.request(obj, callback);
};
likeProject (ProjectID, Like, callback) {
const obj = {"action": "likeProject", "ProjectID": ProjectID, "Like": ((Like) ? "true" : "false")};
this.request(obj, callback);
};
reportProject (ProjectID, Description, callback) {
const obj = {"action": "reportProject", "ProjectID": ProjectID, "Description": Description};
this.request(obj, callback);
};
convertFile (From, To, Data, callback) {
const obj = {"action": "convertData", "From": From, "To": To, "Data": Data};
this.request(obj, callback);
};
init() { };
}