🌐Service
All services are contained at rsc/services/*.lua
I also recommend to check promise documentation since services heavily use promises
RSC.RECOMMENDED_SERVICE
RSC.RECOMMENDED_SERVICE = "gmod.express"
Constant that have name of recommended service. Used as fallback in CaptureRequest 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
:GetName()
str Service:GetName()
Returns service name specified in RSC.Service.New.
You shouldn't overwrite this function.
:GetDownloadURL(...)
Promise<str> / str Service:GetDownloadURL( data: str, prepareData?: str )
This functions must return url to download uploaded image. data
is given by Service:Upload(...) and prepareData
is given by Service:Prepare(...)
:Ping()
Promise<bool> Service:Ping()
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.
:Upload(...)
Promise<str> Service:Upload( imageData: str, quality: number, prepareData?: str )
This function must upload imageData
. quality
argument can be parsed with RSC.ParseQuality. prepareData
argument given by Service:Prepare
This function must be implemented
-- 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
:Download(...)
Promise<str> Service:Download( uploadData: str, quality: number, prepareData?: str )
This function must download image. Argument uploadData
given by Service:Upload. quality
argument can be parsed with RSC.ParseQuality. prepareData
argument given by Service:Prepare
This function must be implemented
-- 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()
Registers your service by the name you specified in RSC.Service.New. Registered service can accessed by RSC.Service.Get or directly by accessing RSC.Service.Services[name]
.
You shouldn't overwrite this function
Last updated