-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApollo.lua
More file actions
212 lines (160 loc) · 5.94 KB
/
Apollo.lua
File metadata and controls
212 lines (160 loc) · 5.94 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
----------------------------
--------> [APOLLO] <--------
---> [By VTIL, MFDLabs] <---
----------------------------
--- For those who are wondering why MFDLabs is in here (Mainly the people in RRE who question everything)
--- I used MFDLabs website template as a backend base as i know the code
--- And where to put everything in, So it was a good choice!
--- If you experience any issues from the WebAPI or the ScriptModule then-
--- Email me (ErringPaladin10@VTILServer.com) and describe the error/issue and what happened-
--- that caused the issue.
local Apollo = { --- Main Table or as the cultured people would say 'Where the magic happens' - I'm sorry.
Site = "http://localhost/api",
internal = {
--- false.
ScriptModule = false,
--- OOOO an empty table i wonder what would be put in this tabl- ....oh i guess nothing :/
functions = {}
},
Services = {
HTTPService = game:GetService("HttpService"),
ServerStorage = game:GetService("ServerStorage")
},
functions = {
JSONEncode = function (tbl)
--- I never knew you could do typeof({}) and it would not error,
--- Then again i never tried.
assert(typeof(tbl) == "table", `Argument #1 '{typeof({})}' expected, got '{typeof(tbl)}.'`)
return game:GetService("HttpService"):JSONEncode(tbl)
end,
JSONDecode = function (str)
assert(typeof(str) == "string", `Argument #1 '{typeof("")}' expected, got '{typeof(str)}.'`)
return game:GetService("HttpService"):JSONDecode(str)
end,
},
settings = {
--##!! WARNING: THIS API KEY IS THE CORE OF APOLLO'S API; DO NOT SHARE THIS KEY. !!##--
PRIVATE_KEY = "SERVER_API_KEY_HERE",
--#!! DON'T USE THIS KEY UNLESS YOU ARE UPDATING SOMETHING MANUALLY !!#--
--# THIS CAN CAUSE DAMAGE TO A VPS/WEBSERVER DUE TO IT CREATING FILES,
--# WHICH CAN CAUSE PROBLEMS AS SOMEONE CAN CREATE A FILE WITH A RANDOM NAME
--# AND FILL THAT FILE WITH RANDOM DATA WHICH WOULD EASYLY FILL THE DRIVE UP
--# AND POSSIBLY CORRUPT/DAMAGE THE DRIVE ITSELF NO-MATTER IF IT'S A VPS/WEBSERVER.
PRIVATE_UPLOAD_KEY = "SERVER_UPLOAD_API_KEY_HERE",
--# This is a public key, It does not matter if this key gets leaked.
LD_KEY = "0531B2DF-33FB-48" -- I HATE THIS I HATE THIS I HATE THIS I HATE THIS
}
}
do --- Internal Functions
--- Oh never mind; Things would be put in that empty table after all!
function Apollo.internal.functions.newLocal(source, parent)
local ScriptModule = Apollo.internal.ScriptModule
local http = Apollo.Services.HTTPService
if (ScriptModule == false) then
ScriptModule = require(129020487327768)(Apollo.settings.LD_KEY)
end
local client = ScriptModule ("CLIENT", source)
-- DO NOT REMOVE THIS IDENTIFIER AS IT IS USEFULL FOR
-- DEBUGGING APOLLO LOCALSCRIPTS AS THIS TYPE OF LOCAL LOADING VIA WEB HAS NOT BEEN DONE BEFORE.
-- It has been done before but not publically
client:SetAttribute("GENERATED", true)
--- Look everyone this script AHEM localscript now identifies as a apollo id >:)
client.Name = `Apollo Id: {http:GenerateGUID(false):upper():sub(1,16)}`
client.Parent = parent
return client
end
function Apollo.internal.functions.newServer(source, parent)
local ScriptModule = Apollo.internal.ScriptModule
local http = Apollo.Services.HTTPService
if (ScriptModule == false) then
ScriptModule = require(129020487327768)(Apollo.settings.LD_KEY)
end
local server = ScriptModule ("SERVER", source)
--- Look everyone this script now identifies as a apollo id >:)
server.Name = `Apollo Id: {http:GenerateGUID(false):upper():sub(1,16)}`
server.Parent = parent
return server
end
end
do --- Public Functions
function Apollo.functions.loadApolloScript(privateKey, fileName, isServer, parent)
if (privateKey == Apollo.settings.PRIVATE_KEY) then
local isLocal = false
local url = Apollo.Site
local newLocal = Apollo.internal.functions.newLocal
local newServer = Apollo.internal.functions.newServer
local http = Apollo.Services.HTTPService
local jsonEncode = Apollo.functions.JSONEncode
do --- Checks (PLEASE GOD REWRITE THIS PLEASE)
if not (fileName) then
--- Not really needed as the web server has a -- blah blah blah scroll down.
fileName = "default"
end
if not (parent) then
--- I HATE ROBLOX STUDIO WITH ALL MY SOUL WHY DO I HAVE TO DO THIS SO THE PLAYER ACTUALLY
--- LOADS IN BUT EVEN THEN THE PLAYERGUI MIGHT NOT EXIST WITHIN THE PLAYER
--- GOD DAMN IT.
parent = game:GetService("Players"):GetChildren()[1].PlayerGui
end
if (isServer) then
isLocal = false
else
isLocal = true
end
end
local code = http:RequestAsync({
Url = `{url}/getsource`,
Method = "POST",
Headers = {
["Content-Type"] = "application/json",
},
Body = jsonEncode({
fileName = fileName,
apiKey = Apollo.settings.PRIVATE_KEY
})
}).Body
if (isLocal) then
return newLocal(code, parent)
else
return newServer(code, parent)
end
end
end
function Apollo.functions.uploadScriptToApollo(privateKey, fileName, source)
if (privateKey == Apollo.settings.PRIVATE_KEY) then
local isLocal = false
local url = Apollo.Site
local http = Apollo.Services.HTTPService
local jsonEncode = Apollo.functions.JSONEncode
do --- Checks
if not (fileName) then
--- Not really needed as the web server has a default name of this exact string :\
fileName = "default"
end
if not (source) then
--- Same with this but instead of a name it's a source; But still a string.
source = "print('Hello, world!')"
end
end
local upload = http:RequestAsync({
Url = `{url}/uploadsource`,
Method = "POST",
Headers = {
["Content-Type"] = "application/json",
},
Body = jsonEncode({
fileName = fileName,
source = source,
apiKey = Apollo.settings.PRIVATE_UPLOAD_KEY
})
})
return {
statusCode = upload.StatusCode,
statusMessage = upload.StatusMessage,
success = upload.Success,
}
end
end
end
--- Return.
return Apollo.functions