Skip to content

Commit

Permalink
Fastpic.org view full image, imagebam.com direct link #77
Browse files Browse the repository at this point in the history
Add CNode and CSelection's attribute function to scripting API (there was a mistake in docs)
  • Loading branch information
zenden2k committed Mar 27, 2024
1 parent c4574a6 commit 074a865
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
19 changes: 16 additions & 3 deletions Data/Scripts/fastpic.nut
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
function _RegReplace(str, pattern, replace_with) {
local resultStr = str;
local res;
local start = 0;

while( (res = resultStr.find(pattern,start)) != null ) {
resultStr = resultStr.slice(0,res) +replace_with+ resultStr.slice(res + pattern.len());
start = res + replace_with.len();
}
return resultStr;
}

function UploadFile(FileName, options) {
nm.setUrl("https://fastpic.org/upload?api=1");
//nm.addQueryHeader("User-Agent","FPUploader");
Expand All @@ -20,11 +32,12 @@ function UploadFile(FileName, options) {
if(statusNode.Text()=="ok"){
local imgUrlNode = root.GetChild("imagepath", false);
local thumbUrlNode = root.GetChild("thumbpath", false);
local viewUrl = root.GetChild("viewurl", false);

local viewUrl = root.GetChild("viewfullurl", false);
options.setDirectUrl(imgUrlNode.Text());
options.setThumbUrl(thumbUrlNode.Text());
options.setViewUrl(viewUrl.Text());
local viewUrlStr = viewUrl.Text();
viewUrlStr = _RegReplace(viewUrlStr, "fastpic.org/view/", "fastpic.org/fullview/");
options.setViewUrl(viewUrlStr);
return 1;
} else {
local errorNode = root.GetChild("error", false);
Expand Down
14 changes: 13 additions & 1 deletion Data/Scripts/imagebam.com.nut
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,19 @@ function UploadFile(FileName, options) {
local reg = CRegExp(BASE_URL + "view/([A-Za-z0-9]+)", "mi");

if (reg.match(nm.responseBody()) ) {
options.setViewUrl(reg.getMatch(0));
local viewUrl = reg.getMatch(0);
if (viewUrl != "") {
options.setViewUrl(viewUrl);
nm.doGet(viewUrl);
if (nm.responseCode() == 200) {
doc = Document(nm.responseBody());
node = doc.find(".main-image");
if (node != null) {
options.setDirectUrl(node.attr("src"));
}
}
}

local reg2 = CRegExp("\\[IMG\\](.+?)\\[/IMG\\]", "mi");
if (reg2.match(nm.responseBody())) {
options.setThumbUrl(reg2.getMatch(1));
Expand Down
4 changes: 3 additions & 1 deletion Source/Core/Scripting/API/GumboBingings/GumboDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ void RegisterGumboClasses(Sqrat::SqratVM& vm) {
.Func("tagName", &CSelection::tagName)
.Func("each", &CSelection::squirrelEach)
.Func("attr", &CSelection::attribute)
.Func("attribute", &CSelection::attribute)
);

root.Bind("Node", Class<CNode>(vm.GetVM(), "Node")
Expand All @@ -42,10 +43,11 @@ void RegisterGumboClasses(Sqrat::SqratVM& vm) {
.Func("childAt", &CNode::childAt)
.Func("childCount", &CNode::childNum)
.Func("attr", &CNode::attribute)
.Func("attribute", &CNode::attribute)
.Func("text", &CNode::text)
.Func("ownText", &CNode::ownText)
.Func("tagName", &CNode::tag)
.Func("find", &CNode::find)
);
}
}
}

0 comments on commit 074a865

Please sign in to comment.