Skip to content

Commit

Permalink
Properly trim JSON from http request
Browse files Browse the repository at this point in the history
  • Loading branch information
boatbomber committed Mar 3, 2022
1 parent 8d2ada2 commit ba19d0f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@boatbomber/sheetvalues",
"version": "2.0.2",
"version": "2.0.3",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
16 changes: 7 additions & 9 deletions src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,7 @@ function SheetValues.new(SpreadId: string, SheetId: string?)
}

function SheetManager:_setValues(json: string, timestamp: number)
local body = string.sub(string.sub(json, 1, #json - 2), 48)
local decodeSuccess, sheet = pcall(HttpService.JSONDecode, HttpService, body)
local decodeSuccess, sheet = pcall(HttpService.JSONDecode, HttpService, json)
if not decodeSuccess then
return
end
Expand All @@ -263,13 +262,11 @@ function SheetValues.new(SpreadId: string, SheetId: string?)
local Value = table.create(#RowValue.c)
for i, Comp in ipairs(RowValue.c) do
local key = sheet.table.cols[i].label
local typedComp = ConvertTyped(Comp.v)

if key == "" then
if not key or key == "" then
continue
end

Value[key] = typedComp
Value[key] = ConvertTyped(Comp.v)
end

local Name = Value.Name or Value.name or string.format("%d", Row) -- Index by name, or by row if no names exist
Expand Down Expand Up @@ -310,9 +307,10 @@ function SheetValues.new(SpreadId: string, SheetId: string?)
-- request success, set these values

local now = DateTime.now().UnixTimestamp
local json = string.match(response.Body, "{.+}")

self.LastSource = "Google API"
self:_setValues(response.Body, now)
self:_setValues(json, now)

-- Put these new values into the store
local s, e = pcall(self._DataStore.UpdateAsync, self._DataStore, "JSON", function(storeValues)
Expand All @@ -326,7 +324,7 @@ function SheetValues.new(SpreadId: string, SheetId: string?)
end

storeValues.Timestamp = now
storeValues.JSON = response.Body
storeValues.JSON = json

return storeValues
end)
Expand All @@ -338,7 +336,7 @@ function SheetValues.new(SpreadId: string, SheetId: string?)
MessagingService.PublishAsync,
MessagingService,
GUID,
#response.Body < 1000 and response.Body or "TriggerStore"
#json < 1000 and json or "TriggerStore"
)
--if not s then warn(e) end
end
Expand Down
2 changes: 1 addition & 1 deletion wally.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "boatbomber/sheetvalues"
description = "Use Google Sheets as a live value updater for Roblox games."
version = "2.0.2"
version = "2.0.3"
license = "MIT"
authors = ["boatbomber (https://boatbomber.com)"]
registry = "https://github.com/upliftgames/wally-index"
Expand Down

0 comments on commit ba19d0f

Please sign in to comment.