- Version
- 1.4.1
Contents
- Introduction
- Example
- Functions to implement
- Global functions
- Upload filter script
- Parsing HTML with gumbo-query
- Translating scripts into different languages
Introduction
Image Uploader is using scripts written in Squirrel 3 language. Squirrel is a high level imperative, object-oriented programming language, designed to be a light-weight scripting language that fits in the size, memory bandwidth, and real-time requirements of applications like video games.
Squirrel 3.0 reference manual
Squirrel 3.0 Standard Libraries manual (PDF)
Scripts should be saved in utf-8 encoding in files with .nut
extension and placed in the Data/Scripts directory.
Example
test <- "example";
nm.setUrl("http://example.com/upload.php");
nm.addQueryParamFile("file", pathToFile, ExtractFileName(pathToFile),"");
nm.addQueryParam("submit", "Upload file!");
nm.doUploadMultipartData();
local response = nm.responseBody();
local directUrl = _RegexSimple(response, "\\[IMG\\](.+)\\[/IMG\\]",0);
options.setDirectUrl(directUrl);
return 1;
}
function _RegexSimple(data,regStr,start) {
local ex = regexp(regStr);
local res = ex.capture(data, start);
local resultStr = "";
if(res != null){
resultStr = data.slice(res[1].begin, res[1].end);
}
return resultStr;
}
return 1;
}
function GetFolderList(list) {
return 1;
}
function CreateFolder(parentAlbum,album) {
return 1;
}
function ModifyFolder(album) {
return 1;
}
return ["Private", "Public"];
}
int UploadFile(string pathToFile, UploadParams params)
array GetFolderAccessTypeList()
You have to implement at least one function — UploadFile.
If you want to support album listing/creating/modifying, you have to implement also GetFolderList, CreateFolder, ModifyFolder, GetFolderAccessTypeList.
nm
- global object - is an instance of NetworkClient
ServerParams
- global object - is an instance of ServerSettingsStruct
Parsing HTML with gumbo-query
Gumbo-query is a library that provides CSS selector-like queries for Gumbo-Parser. Use ScriptAPI::Document class.
local txt = "<h1><a id=\"logo\" class=\"link\">some link</a></h1>";
local doc = Document(txt);
print(doc.find("h1 a").text()+"\r\n");
print(doc.find("h1 a").length()+"\r\n");
print(doc.find("#logo").attr("class")+"\r\n");
nm.doGet("https://svistunov.dev");
doc = Document(nm.responseBody());
doc.find("a").each( function(index,elem) {
print(elem.text()+"-\r\n");
});