I also recommend to check since services heavily use promises
RSC.RECOMMENDED_SERVICE
RSC.RECOMMENDED_SERVICE = "gmod.express"
Constant that have name of recommended service. Used as fallback in if specified service wans't found.
RSC.Service.New(...)
Service RSC.Service.New( name: str )
Creates new Service object
local service = RSC.Service.New("my_service")
-- Change service functions here
function service:Upload(data, quality, preparedata)
-- ...
end
service.Upload = promise.Async(service.Upload)
-- And register service
service:Register() -- After this we can get service by calling RSC.Service.Get("my_service")
RSC.Service.Get(...)
Service/nil RSC.Service.Get( name: str )
Returns registered service by name if it is exists
This function checks if service available at current moment.
-- Example of implementing this function
function service:Ping()
local ok, req = promise.HTTP({ url = "https://yourservice.com", timeout = 5 }):SafeAwait()
return ok and req.code == 200
end
service.Ping = promise.Async(service.Ping)
:Prepare()
Promise<str/nil> Service:Prepare()
This function called on serverside before initiating capture process on victim's side. Must return string that contains prepare data for upload and download functions. If prepare data isn't needed, then just return Promise<nil> or don't overwrite this function.
-- Example of implementing Service:Upload
function service:Upload(imageData, quality, prepareData)
local ok, res = promise.HTTP({
url = "https://myservice.com/upload",
method = "POST",
body = imageData,
}):SafeAwait() -- Safely await our function
-- Check if upload was successful
if not ok or res.code ~= 200 then
return promise.Reject("failed to upload") -- do not use error("...")
end
-- Return service response (like file id)
return res.body
end
service.Upload = promise.Async(service.Upload) -- Make this function async
-- Example of implementing Service:Download
function service:Download(uploadData, quality, prepareData)
local ok, res = promise.HTTP({
-- Our Service:GetDownloadURL(...) must return our download url
-- Like: "https://myservice.com/download/" .. uploadData
url = self:GetDownloadURL(uploadData, prepareData),
method = "GET",
}):SafeAwait() -- Safely await our function
-- Check if download was successful
if not ok or res.code ~= 200 then
return promise.Reject("failed to download") -- do not use error("...")
end
-- Return downloaded image
return res.body
end
service.Download = promise.Async(service.Download) -- Make this function async
:Register()
Service:Register()
You shouldn't overwrite this function
Returns service name specified in .
This functions must return url to download uploaded image. data is given by and prepareData is given by
This function must upload imageData. quality argument can be parsed with . prepareData argument given by
This function must download image. Argument uploadData given by . quality argument can be parsed with . prepareData argument given by
Registers your service by the name you specified in . Registered service can accessed by or directly by accessing RSC.Service.Services[name].