v0.1.1: add configure() method, wally dependency, project config

This commit is contained in:
2026-02-16 17:58:06 -05:00
parent def085b839
commit e4fa158e8e
3 changed files with 42 additions and 9 deletions
+15 -7
View File
@@ -4,15 +4,23 @@ 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 BASE_URL: string? = nil
local API_KEY: Secret? = nil
local API_KEY = HttpService:GetSecret(API_KEY_SECRET_NAME)
export type Config = {
baseUrl: string,
apiKeySecretName: string?,
}
function module.configure(config: Config)
BASE_URL = config.baseUrl
local secretName = config.apiKeySecretName or "FILOXEN_API_KEY"
API_KEY = HttpService:GetSecret(secretName)
end
-- Makes a GET request to the Filoxen API and decodes the assets array from the response.
local function makeApiRequest(url: string): {Types.Asset}?
assert(BASE_URL and API_KEY, "[Filoxen] Must call .configure() before using the API")
local success, response = pcall(function()
return HttpService:RequestAsync({
Url = url,
@@ -43,7 +51,7 @@ 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}`
local REQUEST_URL = `{BASE_URL}/assets/random?assetTypeIds={table.concat(assetTypeIds, ',')}&batch={batch}`
if type(onsale) == "boolean" then
onsale = if onsale then 1 else 0
end
@@ -70,7 +78,7 @@ 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}`
local REQUEST_URL = `{BASE_URL}/assets/search?assetTypeId={assetTypeId}&query={HttpService:UrlEncode(query)}&page={page}`
return makeApiRequest(REQUEST_URL)
end