Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FiveHub – FiveM Resource (Lua)

English • Español

FiveHub API client for FiveM. List, fetch, and delete assets, and get signed URLs from the server. Designed to be used from other resources via exports.

Requirements

  • API Key from FiveHub (Dashboard → API Key).
  • Optional: X-Organization-Id if the user belongs to multiple organizations.

Installation

  1. Copy the fivem folder (or its contents) into your FiveM server's resources directory, for example:
    resources/
      fivehub/
        fxmanifest.lua
        config.lua
        server.lua
    
  2. Set the convars in server.cfg (or edit config.lua):
set fivehub:baseUrl "https://fivehub.pro"
set fivehub:apiKey "your-api-key"
set fivehub:organizationId "optional-org-id"
  1. Start the resource in server.cfg:
ensure fivehub

Usage from another resource

All functions are server-side and use callbacks with the signature (err, result).

List assets

exports.fivehub:ListAssets(function(err, data)
  if err then
    print("Error: " .. tostring(err))
    return
  end
  -- data.assets, data.total, data.limit, data.offset
  for _, asset in ipairs(data.assets) do
    print(asset.id, asset.name, asset.publicUrl)
  end
end)

-- With pagination
exports.fivehub:ListAssets({ limit = 20, offset = 0 }, function(err, data)
  if err then return end
  -- ...
end)

Get an asset by ID

exports.fivehub:GetAsset("asset-id-here", function(err, asset)
  if err then
    print("Error: " .. tostring(err))
    return
  end
  print(asset.name, asset.publicUrl, asset.size)
end)

Get a signed URL (temporary)

Useful for time-limited links. expiresIn is in seconds (default: 3600).

exports.fivehub:GetAssetUrl("asset-id", 7200, function(err, data)
  if err then return end
  -- data.url, data.expiresIn, data.asset
  print("URL valid for " .. data.expiresIn .. " seconds: " .. data.url)
end)

-- Without the second argument: defaults to 3600 seconds
exports.fivehub:GetAssetUrl("asset-id", function(err, data)
  if err then return end
  print(data.url)
end)

Delete an asset

exports.fivehub:DeleteAsset("asset-id-here", function(err)
  if err then
    print("Error: " .. tostring(err))
    return
  end
  print("Deleted successfully")
end)

Available exports

Export Arguments Callback Description
ListAssets [options], cb (err, data) List assets (options: limit, offset).
GetAsset assetId, cb (err, asset) Get an asset by ID.
GetAssetUrl assetId, [expiresIn], cb (err, data) Return a signed URL (expiresIn in seconds).
DeleteAsset assetId, cb (err) Delete an asset.

File uploads

Uploading files from FiveM requires building a multipart/form-data body and reading files from disk; this resource does not include an upload export. To upload from the server you can:

  • Call the API directly using PerformHttpRequest with a multipart body, or
  • Use a separate service/backend that receives the file and calls the FiveHub API (for example, with the JavaScript SDK).

API reference

These endpoints are used, with the following headers:

  • X-API-KEY: API Key (required).
  • X-Organization-Id: Organization ID (optional).
Method Path Description
GET /api/assets List (query: limit, offset)
GET /api/assets/:id Get one
GET /api/assets/:id/url Signed URL (query: expiresIn)
DELETE /api/assets/:id Delete

Errors

On error, the callback receives a string as the first argument (for example "Invalid API key" or "Asset not found"). Always check err before using the result.

About

SDK oficial de FiveHub.pro para FiveM (Lua) — exports server-side para gestionar assets

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages