fivemanage

if not GetResourceState('fmsdk') == 'started' then return end

Media = {}

--- @param source number
--- @param metadata table?
--- @param timeout number?
--- @return boolean, table<
function Media.uploadImage(source, metadata, timeout)
  if type(source) ~= "number" or not GetPlayerName(source) then
    return false, "Invalid or missing player source"
  end

  local apiKey = GetConvar("FIVEMANAGE_MEDIA_API_KEY", "")
  if apiKey == "" then
    return false, "FIVEMANAGE_MEDIA_API_KEY convar is not set"
  end

  local opts = type(metadata) == "table" and metadata or {}
  local to = (type(timeout) == "number" and timeout) or 10000

  local ok, result = pcall(function()
    return exports.fmsdk:takeServerImage(source, opts, to)
  end)

  if not ok then
    return false, ("takeServerImage error: %s"):format(tostring(result))
  end

  if type(result) ~= "table" or type(result.data) ~= "table" or type(result.data.url) ~= "string"
  then
    local dump = json.encode(result) or tostring(result)
    return false, ("SERVER BRIDGE: Invalid SDK response: %s"):format(dump)
  end

  return true, result.data
end

Last updated

Was this helpful?