Skip to content

Commit

Permalink
Add image hosting turboimagehost.com
Browse files Browse the repository at this point in the history
  • Loading branch information
zenden2k committed Nov 28, 2024
1 parent 271a334 commit 1d0ac9c
Show file tree
Hide file tree
Showing 6 changed files with 223 additions and 2 deletions.
Binary file added Data/Favicons/turboimagehost.com.ico
Binary file not shown.
1 change: 0 additions & 1 deletion Data/Scripts/imageup.nut
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ function Authenticate() {

nm.addQueryParam("login",login);
nm.addQueryParam("password", password);
nm.addQueryParam("username", login);
nm.addQueryParam("autologin", "on");
nm.setUrl(BASE_HOST + "/login.html");
nm.doPost("");
Expand Down
191 changes: 191 additions & 0 deletions Data/Scripts/turboimagehost.nut
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
const BASE_HOST = "https://www.turboimagehost.com/";

function Authenticate() {
local login = ServerParams.getParam("Login");
local password = ServerParams.getParam("Password");

if(login == "" ) {
WriteLog("error", "Login should not be empty!");
return 0;
}

nm.addQueryHeader("Origin", BASE_HOST);
nm.addQueryHeader("Referer", BASE_HOST + "login.tu");

nm.addQueryParam("username", login);
nm.addQueryParam("password", password);
nm.addQueryParam("remember", "y");
nm.addQueryParam("login", "Login");
nm.setUrl(BASE_HOST + "login.tu");
nm.doPost("");

if (nm.responseCode() == 200) {
if (nm.responseBody().find("You have some errors") == null) {
return 1;
}
}
WriteLog("error", "[TurboImageHost] authentication failed.");

return 0;
}


function UploadFile(fileName, options) {
// Загружаем главную страницу, чтобы получить endpoint для загрузки
nm.doGet(BASE_HOST);
if (nm.responseCode() != 200) {
WriteLog("error", "[TurboImageHost] Failed to fetch the main page.");
return 0;
}

// Извлекаем адрес для загрузки из JavaScript
local html = nm.responseBody();
local uploadEndpointPattern = "endpoint:\\s*['\"]([^'\"]+)['\"]";
local reg = CRegExp(uploadEndpointPattern, "mi");
local uploadUrl = "";
local albumId = options.getFolderID();

if (reg.match(html)) {
uploadUrl = reg.getMatch(1);
} else{
WriteLog("error", "[TurboImageHost] Failed to extract upload endpoint.");
return 0;
}

WriteLog("info", "[TurboImageHost] Upload endpoint: " + uploadUrl);

local uploadId = _GenerateRandomString(20);
local qquuid = _GenerateRandomUUID();

// Устанавливаем URL для загрузки
nm.setUrl(uploadUrl);

// Добавляем заголовки
nm.addQueryHeader("Accept", "application/json");
nm.addQueryHeader("X-Requested-With", "XMLHttpRequest");
nm.addQueryHeader("Origin", BASE_HOST);
nm.addQueryHeader("Referer", BASE_HOST);

// Добавляем параметры формы
if (albumId != "") {
nm.addQueryParam("album", albumId);
}
nm.addQueryParam("imcontent", "all");
nm.addQueryParam("thumb_size", options.getParam("THUMBWIDTH"));
nm.addQueryParam("upload_id", uploadId);
nm.addQueryParam("qquuid", qquuid);
nm.addQueryParam("qqfilename", ExtractFileName(fileName));
nm.addQueryParam("qqtotalfilesize", GetFileSize(fileName).tostring());
nm.addQueryParamFile("qqfile", fileName, ExtractFileName(fileName), GetFileMimeType(fileName));

// Отправляем запрос
nm.doUploadMultipartData();
if (nm.responseCode() == 200) {
local responseJson = ParseJSON(nm.responseBody());
if ("success" in responseJson && responseJson.success) {
local resultUrl = responseJson.newUrl;
// nm.addQueryHeader("Accept", "application/json");
nm.doGet(resultUrl);

if (nm.responseCode() == 200) {
local viewUrl = "";
local doc = Document(nm.responseBody());
viewUrl = doc.find("#imgCodeIPSTF").attr("value");
options.setViewUrl(viewUrl);
local previewBbCode = doc.find("#imgCodeIPF").attr("value");
local reg2 = CRegExp("\\[img\\](.+?)\\[/img\\]", "im");
if (reg2.match(previewBbCode) ) {
options.setThumbUrl(reg2.getMatch(1));
}
if (viewUrl != "") {
return 1;
} else {
WriteLog("error", "[TurboImageHost] Failed to obtain image link.");
}

} else {
WriteLog("error", "[TurboImageHost] Upload failed, response code = " + nm.responseCode());
}
} else {
WriteLog("error", "[TurboImageHost] Upload failed, server returned success = false.");
}
} else {
WriteLog("error", "[TurboImageHost] Upload failed, response code = " + nm.responseCode());
}
return 0;
}

function GetFolderList(list) {
nm.addQueryHeader("Accept", "application/json");
nm.doGet(BASE_HOST + "g.tu");

if (nm.responseCode() == 200) {
local doc = Document(nm.responseBody());
doc.find(".galleryThumbs > div").each(function(index, elem) {
local id = elem.attr("id");
id = _StrReplace(id, "gall_", "");
local album = CFolderItem();
album.setId(id);
album.setTitle(strip(elem.find(".thumbTitle").text()));
list.AddFolderItem(album);
});
} else {
WriteLog("error", "[TurboImageHost] Failed to load album list, response code = " + nm.responseCode());
}

return 1; //success
}


function CreateFolder(parentAlbum, album) {
nm.setUrl(BASE_HOST + "index.tu");
nm.addQueryParam("addalbum", album.getTitle());
nm.addQueryParam("newalbum", "Create a new gallery");
if (nm.responseCode() == 200) {
album.setId(id);
album.setViewUrl(link);
} else {
WriteLog("error", "[TurboImageHost] Failed to create album, response code = " + nm.responseCode());
}

return 1;
}

function _GenerateRandomString(length) {
local chars = "abcdefghijklmnopqrstuvwxyz0123456789";
local result = "";
for (local i = 0; i < length; i++) {
local pos = Random() % chars.len();
result += chars.slice(pos, pos+1);
}
return result;
}

function _GenerateRandomUUID() {
local pattern = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx";
local result = "";
for (local i = 0; i< pattern.len(); i++){
if (pattern[i]=='x' || pattern[i]=='y'){
local r = Random()%16;
local v = (pattern[i] == 'x') ? r : (r & 0x3 | 0x8);
result+= format("%x", v);
}
else{
result += pattern.slice(i,i+1);
}
}
return result;
}

function _StrReplace(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;
}
21 changes: 21 additions & 0 deletions Data/servers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,27 @@
<Result ImageUrlTemplate="stub" DownloadUrlTemplate="stub"/>
</Server>
<Server Name="imageup.ru" Authorize="2" Plugin="imageup" WebsiteUrl="https://imageup.ru" RegistrationUrl="https://imageup.ru/registration.html">
<SupportedFormats>
<FormatGroup>
<Format MimeType="image/jpeg">*.jpg,*.jpeg</Format>
<Format MimeType="image/png">*.png</Format>
<Format MimeType="image/gif">*.gif</Format>
<Format MimeType="image/bmp">*.bmp</Format>
<Format MimeType="image/tiff">*.tiff,*.tif</Format>
</FormatGroup>
</SupportedFormats>
<Actions>
</Actions>
<Result ImageUrlTemplate="stub" DownloadUrlTemplate="stub" ThumbUrlTemplate="stub"/>
</Server>
<Server Name="turboimagehost.com" Authorize="1" Plugin="turboimagehost" SupportsFolders="1" WebsiteUrl="https://www.turboimagehost.com" RegistrationUrl="https://www.turboimagehost.com/signup.tu">
<SupportedFormats>
<FormatGroup MaxFileSize="20971520">
<Format MimeType="image/jpeg">*.jpg,*.jpeg</Format>
<Format MimeType="image/png">*.png</Format>
<Format MimeType="image/gif">*.gif</Format>
</FormatGroup>
</SupportedFormats>
<Actions>
</Actions>
<Result ImageUrlTemplate="stub" DownloadUrlTemplate="stub" ThumbUrlTemplate="stub"/>
Expand Down
3 changes: 2 additions & 1 deletion Source/Gui/Dialogs/FileFormatCheckErrorDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ LRESULT CFileFormatCheckErrorDlg::OnOK(WORD /*wNotifyCode*/, WORD wID, HWND /*hW
}
}

EndDialog((model_.getCount() - skippedCount) ? IDOK : IDCANCEL);
// EndDialog((model_.getCount() - skippedCount) ? IDOK : IDCANCEL);
EndDialog(wID);
return 0;
}

Expand Down
9 changes: 9 additions & 0 deletions Source/Gui/Dialogs/WizardDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2525,6 +2525,15 @@ bool CWizardDlg::checkFileFormats(const ServerProfileGroup& imageServer, const S
if (fileFormatDlg.DoModal() != IDOK) {
return false;
}
auto n = mainDlg->FileList.GetCount();

for (size_t i = 0; i < n; i++) {
if (!mainDlg->FileList.getFile(i)->isSkipped()) {
return true;
}
}
return false;

}
/* if (!message.empty()) {
GuiTools::LocalizedMessageBox(m_hWnd, U2W(message), TR("Error"), MB_ICONERROR);
Expand Down

0 comments on commit 1d0ac9c

Please sign in to comment.