add ability to export generated build code to pobb.in

This commit is contained in:
Peechey
2022-01-31 14:53:27 -07:00
parent e570c5929e
commit fd080cb189

View File

@@ -26,7 +26,7 @@ local ImportTabClass = newClass("ImportTab", "ControlHost", "Control", function(
self.charImportMode = "GETACCOUNTNAME"
self.charImportStatus = "Idle"
self.controls.sectionCharImport = new("SectionControl", {"TOPLEFT",self,"TOPLEFT"}, 10, 18, 600, 250, "Character Import")
self.controls.sectionCharImport = new("SectionControl", {"TOPLEFT",self,"TOPLEFT"}, 10, 18, 630, 250, "Character Import")
self.controls.charImportStatusLabel = new("LabelControl", {"TOPLEFT",self.controls.sectionCharImport,"TOPLEFT"}, 6, 14, 200, 16, function()
return "^7Character import status: "..self.charImportStatus
end)
@@ -154,7 +154,7 @@ You can get this from your web browser's cookies while logged into the Path of E
end)
-- Build import/export
self.controls.sectionBuild = new("SectionControl", {"TOPLEFT",self.controls.sectionCharImport,"BOTTOMLEFT"}, 0, 18, 600, 200, "Build Sharing")
self.controls.sectionBuild = new("SectionControl", {"TOPLEFT",self.controls.sectionCharImport,"BOTTOMLEFT"}, 0, 18, 630, 200, "Build Sharing")
self.controls.generateCodeLabel = new("LabelControl", {"TOPLEFT",self.controls.sectionBuild,"TOPLEFT"}, 6, 14, 0, 16, "^7Generate a code to share this build with other Path of Building users:")
self.controls.generateCode = new("ButtonControl", {"LEFT",self.controls.generateCodeLabel,"RIGHT"}, 4, 0, 80, 20, "Generate", function()
self.controls.generateCodeOut:SetText(common.base64.encode(Deflate(self.build:SaveDB("code"))):gsub("+","-"):gsub("/","_"))
@@ -209,7 +209,50 @@ You can get this from your web browser's cookies while logged into the Path of E
end
end)
self.controls.generateCodePastebin.enabled = function()
return #self.controls.generateCodeOut.buf > 0 and not self.controls.generateCodeOut.buf:match("pastebin%.com")
return #self.controls.generateCodeOut.buf > 0 and not self.controls.generateCodeOut.buf:match("pastebin%.com") and not self.controls.generateCodeOut.buf:match("pobb%.in")
end
self.controls.generateCodePobbin = new("ButtonControl", {"LEFT",self.controls.generateCodePastebin,"RIGHT"}, 8, 0, 140, 20, "Share with Pobb.in", function()
local id = LaunchSubScript([[
local code, proxyURL = ...
local curl = require("lcurl.safe")
local page = ""
local easy = curl.easy()
easy:setopt_url("https://pobb.in/api/v1/paste/")
easy:setopt(curl.OPT_POST, true)
easy:setopt(curl.OPT_POSTFIELDS, code)
easy:setopt(curl.OPT_ACCEPT_ENCODING, "gzip, deflate, br")
if proxyURL then
easy:setopt(curl.OPT_PROXY, proxyURL)
end
easy:setopt_writefunction(function(data)
page = page..data
return true
end)
easy:perform()
easy:close()
if page:match("id") then
return page
else
return nil, page
end
]], "", "", self.controls.generateCodeOut.buf, launch.proxyURL)
if id then
self.controls.generateCodeOut:SetText("")
self.controls.generateCodePobbin.label = "Creating pobb..."
launch:RegisterSubScript(id, function(pasteLink, errMsg)
self.controls.generateCodePobbin.label = "Share with Pobb.in"
if errMsg then
main:OpenMessagePopup("Pobb.in", "Error creating pobb:\n"..errMsg)
else
-- example response from pobbin api: {"id":"qO1_QpuQLeDd"}
local pobbId = string.split(pasteLink, ":")[2]:gsub('\"+',''):gsub('}', '')
self.controls.generateCodeOut:SetText("https://pobb.in/" .. pobbId)
end
end)
end
end)
self.controls.generateCodePobbin.enabled = function()
return #self.controls.generateCodeOut.buf > 0 and not self.controls.generateCodeOut.buf:match("pobb%.in") and not self.controls.generateCodeOut.buf:match("pastebin%.com")
end
self.controls.generateCodeNote = new("LabelControl", {"TOPLEFT",self.controls.generateCodeOut,"BOTTOMLEFT"}, 0, 4, 0, 14, "^7Note: this code can be very long; you can use 'Share with Pastebin' to shrink it.")
self.controls.importCodeHeader = new("LabelControl", {"TOPLEFT",self.controls.generateCodeNote,"BOTTOMLEFT"}, 0, 26, 0, 16, "^7To import a build, enter the code here:")