Initial commit
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
Packages/
|
||||
wally.lock
|
||||
@@ -0,0 +1,21 @@
|
||||
# filoxen-luau
|
||||
|
||||
Luau client library for the Filoxen asset API. Fetch random or search for Roblox assets.
|
||||
|
||||
## Installation
|
||||
|
||||
Requires [Wally](https://wally.run).
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
Filoxen = "secret-rare/filoxen-luau@0.1.0"
|
||||
```
|
||||
|
||||
```sh
|
||||
wally install
|
||||
```
|
||||
|
||||
## Setup
|
||||
|
||||
1. Add your Filoxen API key as a secret named `FILOXEN_API_KEY` in the [Creator Dashboard](https://create.roblox.com) under Secrets.
|
||||
2. Make sure `HttpService` is enabled for your game.
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "filoxen-luau",
|
||||
"tree": {
|
||||
"$path": "src",
|
||||
"Packages": {
|
||||
"$path": "Packages"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
# This file lists tools managed by Rokit, a toolchain manager for Roblox projects.
|
||||
# For more information, see https://github.com/rojo-rbx/rokit
|
||||
|
||||
# New tools can be added by running `rokit add <tool>` in a terminal.
|
||||
|
||||
[tools]
|
||||
wally = "UpliftGames/wally@0.3.2"
|
||||
@@ -0,0 +1,77 @@
|
||||
local module = {}
|
||||
|
||||
local HttpService = game:GetService("HttpService")
|
||||
local RbxAssetUtils = require(script.Packages.RbxAssetUtils)
|
||||
local Types = RbxAssetUtils.Types
|
||||
|
||||
-- Change this to your own API instance URL if self-hosting.
|
||||
local API_URL_BASE = "https://filoxen.example.com"
|
||||
-- Name of the secret in the Secrets Store (Creator Dashboard -> Secrets).
|
||||
local API_KEY_SECRET_NAME = "FILOXEN_API_KEY"
|
||||
|
||||
local API_KEY = HttpService:GetSecret(API_KEY_SECRET_NAME)
|
||||
|
||||
-- Makes a GET request to the Filoxen API and decodes the assets array from the response.
|
||||
local function makeApiRequest(url: string): {Types.Asset}?
|
||||
local success, response = pcall(function()
|
||||
return HttpService:RequestAsync({
|
||||
Url = url,
|
||||
Method = "GET",
|
||||
Headers = {
|
||||
["x-api-key"] = API_KEY
|
||||
}
|
||||
})
|
||||
end)
|
||||
if success and response.Success then
|
||||
local decodeSuccess, responseData = pcall(HttpService.JSONDecode, HttpService, response.Body)
|
||||
if not decodeSuccess then
|
||||
warn(`[Filoxen] API response decode failed: {tostring(responseData)}`)
|
||||
return {}
|
||||
end
|
||||
local assets: {Types.Asset}? = responseData["assets"]
|
||||
if not assets then
|
||||
warn("[Filoxen] API response missing 'assets' field")
|
||||
return {}
|
||||
end
|
||||
return assets
|
||||
else
|
||||
local errorMessage = if success then `HTTP {response.StatusCode}: {response.StatusMessage}` else tostring(response)
|
||||
warn(`[Filoxen] API request failed: {errorMessage}`)
|
||||
return {}
|
||||
end
|
||||
end
|
||||
|
||||
-- Fetches random assets from the Filoxen API with the given filters.
|
||||
function module.random(assetTypeIds: {number | Enum.AssetType}, maxAssetId: number?, minAssetId: number?, batch: number, onsale: number | boolean?, playable: number?): {Types.Asset}?
|
||||
local REQUEST_URL = `{API_URL_BASE}/assets/random?assetTypeIds={table.concat(assetTypeIds, ',')}&batch={batch}`
|
||||
if type(onsale) == "boolean" then
|
||||
onsale = if onsale then 1 else 0
|
||||
end
|
||||
for i, assetTypeId in ipairs(assetTypeIds) do
|
||||
if typeof(assetTypeId) == "EnumItem" then
|
||||
assetTypeIds[i] = assetTypeId.Value
|
||||
end
|
||||
end
|
||||
if maxAssetId then
|
||||
REQUEST_URL = `{REQUEST_URL}&maxAssetId={maxAssetId}`
|
||||
end
|
||||
if minAssetId then
|
||||
REQUEST_URL = `{REQUEST_URL}&minAssetId={minAssetId}`
|
||||
end
|
||||
if onsale then
|
||||
REQUEST_URL = `{REQUEST_URL}&onsale={onsale}`
|
||||
end
|
||||
if playable then
|
||||
REQUEST_URL = `{REQUEST_URL}&playable={playable}`
|
||||
end
|
||||
return makeApiRequest(REQUEST_URL)
|
||||
end
|
||||
|
||||
-- Searches for assets matching a query string via the Filoxen API.
|
||||
function module.search(query: string, assetTypeId: number, page: number?): {Types.Asset}?
|
||||
if not page then page = 1 end
|
||||
local REQUEST_URL = `{API_URL_BASE}/assets/search?assetTypeId={assetTypeId}&query={HttpService:UrlEncode(query)}&page={page}`
|
||||
return makeApiRequest(REQUEST_URL)
|
||||
end
|
||||
|
||||
return module
|
||||
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "secret-rare/filoxen-luau"
|
||||
version = "0.1.0"
|
||||
registry = "https://github.com/UpliftGames/wally-index"
|
||||
realm = "server"
|
||||
|
||||
[dependencies]
|
||||
RbxAssetUtils = "secret-rare/rbx-asset-utils@0.1.0"
|
||||
Reference in New Issue
Block a user