From ce816cca34a671e8fbdbcf53bbc9b1d26c3ee1b8 Mon Sep 17 00:00:00 2001 From: ccuser44 <68124053+ccuser44@users.noreply.github.com> Date: Sun, 22 Jan 2023 12:08:43 +0200 Subject: [PATCH 1/3] Update SyncAPI.lua --- SyncAPI.lua | 80 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 73 insertions(+), 7 deletions(-) diff --git a/SyncAPI.lua b/SyncAPI.lua index 4db97e95..9c1b94d7 100644 --- a/SyncAPI.lua +++ b/SyncAPI.lua @@ -24,10 +24,45 @@ Options = { CreatedInstances = {}; LastParents = {}; +-- Provide cached data for +local assetTypeCache = {} +local imageIdCache = {} +local IsHttpServiceEnabled = nil + -- Determine whether we're in tool or plugin mode ToolMode = (Tool.Parent:IsA 'Plugin') and 'Plugin' or 'Tool' -local IsHttpServiceEnabled = nil +local function getAssetType(assetId) + if assetTypeCache[assetId] then + return assetTypeCache[assetId] + end + + local success, result = pcall(MarketplaceService.GetProductInfo, MarketplaceService, assetId, Enum.InfoType.Asset) + + if success and result and result.AssetTypeId then + assetTypeCache[assetId] = result.AssetTypeId + return result.AssetTypeId + else + return nil + end +end + +local function getImageFromDecal(assetId) then + if imageIdCache[assetId] then + return imageIdCache[assetId] + end + + local success, result = pcall(function() + return string.match(InsertService:LoadAsset(assetId):FindFirstChildWhichIsA("Decal").Texture, "^.-(%d+)/?$") + end) + + if success and result then + imageIdCache[assetId] = result + return success and result + else + return nil + end +end -- List of actions that could be requested Actions = { @@ -1618,7 +1653,7 @@ Actions = { -- Perform test HTTP request local DidSucceed, Result = pcall(function () - return HttpService:GetAsync('https://google.com') + return HttpService:GetAsync('https://www.google.com/robots.txt') end) -- Determine whether HttpService is enabled based on whether request succeeded @@ -1634,17 +1669,31 @@ Actions = { ['ExtractMeshFromAsset'] = function (AssetId) -- Returns the first found mesh in the given asset + -- Ensure valid asset ID is given + assert(type(AssetId) == 'number', 'Invalid asset ID'); + + -- Add automatic checking for image assets which works client-sided for better UX + if getAssetType(AssetId) == 1 then + return string.format([[{"success":true,"textureID":%d}]], AssetId) + end + -- Offload action to server-side if API is running locally if RunService:IsClient() and not RunService:IsStudio() then return SyncAPI.ServerEndpoint:InvokeServer('ExtractMeshFromAsset', AssetId); end; - -- Ensure valid asset ID is given - assert(type(AssetId) == 'number', 'Invalid asset ID'); + -- Add support for decals which can be inserted via InsertService + if getAssetType(AssetId) == 13 then + local imageId = getImageFromDecal(AssetId) + + if imageId then + return string.format([[{"success":true,"textureID":%d}]], imageId) + end + end -- Return parsed response from API return HttpService:JSONDecode( - HttpService:GetAsync('http://f3xteam.com/bt/getFirstMeshData/' .. AssetId) + HttpService:GetAsync('https://f3xteam.com/bt/getFirstMeshData/' .. AssetId) ); end; @@ -1652,13 +1701,30 @@ Actions = { ['ExtractImageFromDecal'] = function (DecalAssetId) -- Returns the first image found in the given decal asset + -- Ensure valid asset ID is given + assert(type(DecalAssetId) == 'number', 'Invalid asset ID'); + + -- Add automatic checking for image assets which works client-sided for better UX + if getAssetType(DecalAssetId) == 1 then + return DecalAssetId + end + -- Offload action to server-side if API is running locally if RunService:IsClient() and not RunService:IsStudio() then return SyncAPI.ServerEndpoint:InvokeServer('ExtractImageFromDecal', DecalAssetId); end; + -- Add support for decals which can be inserted via InsertService + if getAssetType(DecalAssetId) == 13 then + local imageId = getImageFromDecal(DecalAssetId) + + if imageId then + return imageId + end + end + -- Return direct response from the API - return HttpService:GetAsync('http://f3xteam.com/bt/getDecalImageID/' .. DecalAssetId); + return HttpService:GetAsync('https://f3xteam.com/bt/getDecalImageID/' .. DecalAssetId); end; @@ -1955,4 +2021,4 @@ return { end; -}; \ No newline at end of file +}; From e5cba8505c15dc8e2b0961d8ebcdcec1a39e3bdf Mon Sep 17 00:00:00 2001 From: ccuser44 <68124053+ccuser44@users.noreply.github.com> Date: Sun, 22 Jan 2023 12:12:30 +0200 Subject: [PATCH 2/3] Update SyncAPI.lua --- SyncAPI.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/SyncAPI.lua b/SyncAPI.lua index 9c1b94d7..6cceed9d 100644 --- a/SyncAPI.lua +++ b/SyncAPI.lua @@ -1,5 +1,7 @@ local HttpService = game:GetService('HttpService') local RunService = game:GetService('RunService') +local InsertService = game:GetService("InsertService") +local MarketplaceService = game:GetService("MarketplaceService") -- References SyncAPI = script.Parent; @@ -24,7 +26,7 @@ Options = { CreatedInstances = {}; LastParents = {}; --- Provide cached data for +-- Provide cached data for requests local assetTypeCache = {} local imageIdCache = {} local IsHttpServiceEnabled = nil @@ -32,6 +34,7 @@ local IsHttpServiceEnabled = nil -- Determine whether we're in tool or plugin mode ToolMode = (Tool.Parent:IsA 'Plugin') and 'Plugin' or 'Tool' +-- Get asset type from asset id local function getAssetType(assetId) if assetTypeCache[assetId] then return assetTypeCache[assetId] @@ -47,7 +50,8 @@ local function getAssetType(assetId) end end -local function getImageFromDecal(assetId) then +-- Extract imageid from decalid via insertservice +local function getImageFromDecal(assetId) if imageIdCache[assetId] then return imageIdCache[assetId] end From e8caf42b5a552b0f649b6fa7a9728302a426160e Mon Sep 17 00:00:00 2001 From: ccuser44 <68124053+ccuser44@users.noreply.github.com> Date: Sun, 22 Jan 2023 12:47:30 +0200 Subject: [PATCH 3/3] Update SyncAPI.lua --- SyncAPI.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SyncAPI.lua b/SyncAPI.lua index 6cceed9d..897f2dda 100644 --- a/SyncAPI.lua +++ b/SyncAPI.lua @@ -1626,7 +1626,7 @@ Actions = { -- Push serialized data to server local Response = HttpService:JSONDecode( HttpService:PostAsync( - 'http://f3xteam.com/bt/export', + 'https://f3xteam.com/bt/export', HttpService:JSONEncode { data = SerializedBuildData, version = 3, userId = (Player and Player.UserId) }, Enum.HttpContentType.ApplicationJson, true