Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 007a30da95 | |||
| 206429866a | |||
| 65fbf7428c | |||
| d5522bb96f |
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2026 Filoxen Labs
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
# threads-client
|
# threads-luau
|
||||||
|
|
||||||
A Roblox server-side client for the [Threads](https://github.com/filoxen/threads) service. Handles reuploading clothing assets through your Threads instance.
|
A Roblox server-side client for the [Threads](https://github.com/filoxen/threads) service. Handles reuploading clothing assets through your Threads instance.
|
||||||
|
|
||||||
@@ -8,7 +8,7 @@ Add to your `wally.toml` dependencies:
|
|||||||
|
|
||||||
```toml
|
```toml
|
||||||
[server-dependencies]
|
[server-dependencies]
|
||||||
ThreadsClient = "secret-rare/threads-luau@0.2.0"
|
ThreadsClient = "secret-rare/threads-luau@0.3.0"
|
||||||
```
|
```
|
||||||
|
|
||||||
Then run:
|
Then run:
|
||||||
@@ -19,15 +19,20 @@ wally install
|
|||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
|
|
||||||
1. Add your API key to the **Secrets Store** in the Creator Dashboard with the name `THREADS_API_KEY` (or your own custom secret name).
|
1. Host your own [Threads](https://github.com/filoxen/threads) instance.
|
||||||
|
|
||||||
2. Update `BASE_URL` in the module to point to your Threads API instance.
|
2. Add your API key to the **Secrets Store** in the Creator Dashboard with the name `THREADS_API_KEY` (or a custom name).
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```luau
|
```luau
|
||||||
local ThreadsClient = require(path.to.ThreadsClient)
|
local ThreadsClient = require(path.to.ThreadsClient)
|
||||||
|
|
||||||
|
ThreadsClient.configure({
|
||||||
|
baseUrl = "https://your-threads-instance.com",
|
||||||
|
apiKeySecretName = "THREADS_API_KEY", -- optional, this is the default
|
||||||
|
})
|
||||||
|
|
||||||
local newAssetId = ThreadsClient.create(assetId)
|
local newAssetId = ThreadsClient.create(assetId)
|
||||||
|
|
||||||
if newAssetId ~= -1 then
|
if newAssetId ~= -1 then
|
||||||
|
|||||||
+17
-8
@@ -2,15 +2,24 @@ local HttpService = game:GetService("HttpService")
|
|||||||
|
|
||||||
local clothing_upload = {}
|
local clothing_upload = {}
|
||||||
|
|
||||||
-- Change this to your own Threads API instance URL
|
local BASE_URL: string? = nil
|
||||||
local BASE_URL = "https://threads.example.com"
|
local API_KEY: Secret? = nil
|
||||||
-- Name of the secret in the Secrets Store (Creator Dashboard -> Secrets).
|
|
||||||
local API_KEY_SECRET_NAME = "THREADS_API_KEY"
|
|
||||||
|
|
||||||
local API_KEY = HttpService:GetSecret(API_KEY_SECRET_NAME)
|
export type Config = {
|
||||||
|
baseUrl: string,
|
||||||
|
apiKeySecretName: string?,
|
||||||
|
}
|
||||||
|
|
||||||
|
function clothing_upload.configure(config: Config)
|
||||||
|
BASE_URL = config.baseUrl
|
||||||
|
local secretName = config.apiKeySecretName or "THREADS_API_KEY"
|
||||||
|
API_KEY = HttpService:GetSecret(secretName)
|
||||||
|
end
|
||||||
|
|
||||||
-- Sends a reupload request to the Threads API for the given asset ID. Returns the new asset ID, or -1 on failure.
|
-- Sends a reupload request to the Threads API for the given asset ID. Returns the new asset ID, or -1 on failure.
|
||||||
function clothing_upload.create(id: number): number
|
function clothing_upload.create(id: number): number
|
||||||
|
assert(BASE_URL and API_KEY, "[ThreadsClient] Must call .configure() before using .create()")
|
||||||
|
|
||||||
local create_url = `{BASE_URL}/create/?asset_id={id}`
|
local create_url = `{BASE_URL}/create/?asset_id={id}`
|
||||||
|
|
||||||
local request_data = {
|
local request_data = {
|
||||||
@@ -30,14 +39,14 @@ function clothing_upload.create(id: number): number
|
|||||||
local response_data = HttpService:JSONDecode(response.Body)
|
local response_data = HttpService:JSONDecode(response.Body)
|
||||||
if response_data["uploaded"] then
|
if response_data["uploaded"] then
|
||||||
local newAssetId = tonumber(response_data["uploaded"]["asset_id"]) :: number
|
local newAssetId = tonumber(response_data["uploaded"]["asset_id"]) :: number
|
||||||
print(`[ClothingUploadClient] Successfully reuploaded asset {id} -> {newAssetId}`)
|
print(`[ThreadsClient] Successfully reuploaded asset {id} -> {newAssetId}`)
|
||||||
return newAssetId
|
return newAssetId
|
||||||
else
|
else
|
||||||
warn(`[ClothingUploadClient] Reupload failed for asset {id}: Response missing 'uploaded' field`)
|
warn(`[ThreadsClient] Reupload failed for asset {id}: Response missing 'uploaded' field`)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local errorMsg = if response then response.StatusMessage else "Unknown Error"
|
local errorMsg = if response then response.StatusMessage else "Unknown Error"
|
||||||
warn(`[ClothingUploadClient] API request failed for asset {id}: {errorMsg}`)
|
warn(`[ThreadsClient] API request failed for asset {id}: {errorMsg}`)
|
||||||
end
|
end
|
||||||
return -1
|
return -1
|
||||||
end
|
end
|
||||||
|
|||||||
+2
-2
@@ -1,8 +1,8 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "secret-rare/threads-luau"
|
name = "secret-rare/threads-luau"
|
||||||
version = "0.2.0"
|
version = "0.3.0"
|
||||||
registry = "https://github.com/UpliftGames/wally-index"
|
registry = "https://github.com/UpliftGames/wally-index"
|
||||||
license = "GPL-3.0"
|
license = "MIT"
|
||||||
realm = "server"
|
realm = "server"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
Reference in New Issue
Block a user