Browse Source

Merge pull request #7571 from Chocobo1/webui_download

[WebAPI] Add parameters for /command/download & /command/upload
adaptive-webui-19844
Mike Tzou 7 years ago committed by GitHub
parent
commit
bd07cb91bb
  1. 2
      src/base/bittorrent/addtorrentparams.h
  2. 2
      src/base/bittorrent/session.cpp
  3. 4
      src/base/bittorrent/torrenthandle.cpp
  4. 2
      src/base/bittorrent/torrenthandle.h
  5. 9
      src/webui/extra_translations.h
  6. 20
      src/webui/webapplication.cpp
  7. 20
      src/webui/www/private/login.html
  8. 16
      src/webui/www/public/addtrackers.html
  9. 21
      src/webui/www/public/download.html
  10. 12
      src/webui/www/public/preferences.html
  11. 48
      src/webui/www/public/upload.html

2
src/base/bittorrent/addtorrentparams.h

@ -52,5 +52,7 @@ namespace BitTorrent @@ -52,5 +52,7 @@ namespace BitTorrent
bool skipChecking = false;
TriStateBool createSubfolder;
TriStateBool useAutoTMM;
int uploadLimit = -1;
int downloadLimit = -1;
};
}

2
src/base/bittorrent/session.cpp

@ -2193,6 +2193,8 @@ bool Session::addTorrent_impl(AddTorrentData addData, const MagnetUri &magnetUri @@ -2193,6 +2193,8 @@ bool Session::addTorrent_impl(AddTorrentData addData, const MagnetUri &magnetUri
p.max_connections = maxConnectionsPerTorrent();
p.max_uploads = maxUploadsPerTorrent();
p.save_path = Utils::Fs::toNativePath(savePath).toStdString();
p.upload_limit = addData.uploadLimit;
p.download_limit = addData.downloadLimit;
m_addingTorrents.insert(hash, addData);
// Adding torrent to BitTorrent session

4
src/base/bittorrent/torrenthandle.cpp

@ -95,6 +95,8 @@ AddTorrentData::AddTorrentData() @@ -95,6 +95,8 @@ AddTorrentData::AddTorrentData()
, hasRootFolder(true)
, addForced(false)
, addPaused(false)
, uploadLimit(-1)
, downloadLimit(-1)
, ratioLimit(TorrentHandle::USE_GLOBAL_RATIO)
, seedingTimeLimit(TorrentHandle::USE_GLOBAL_SEEDING_TIME)
{
@ -118,6 +120,8 @@ AddTorrentData::AddTorrentData(const AddTorrentParams &params) @@ -118,6 +120,8 @@ AddTorrentData::AddTorrentData(const AddTorrentParams &params)
, addPaused(params.addPaused == TriStateBool::Undefined
? Session::instance()->isAddTorrentPaused()
: params.addPaused == TriStateBool::True)
, uploadLimit(params.uploadLimit)
, downloadLimit(params.downloadLimit)
, filePriorities(params.filePriorities)
, ratioLimit(params.ignoreShareLimits ? TorrentHandle::NO_RATIO_LIMIT : TorrentHandle::USE_GLOBAL_RATIO)
, seedingTimeLimit(params.ignoreShareLimits ? TorrentHandle::NO_SEEDING_TIME_LIMIT : TorrentHandle::USE_GLOBAL_SEEDING_TIME)

2
src/base/bittorrent/torrenthandle.h

@ -104,6 +104,8 @@ namespace BitTorrent @@ -104,6 +104,8 @@ namespace BitTorrent
bool hasRootFolder;
bool addForced;
bool addPaused;
int uploadLimit;
int downloadLimit;
// for new torrents
QVector<int> filePriorities;
// for resumed torrents

9
src/webui/extra_translations.h

@ -73,9 +73,12 @@ static const char *__TRANSLATIONS__[] = { @@ -73,9 +73,12 @@ static const char *__TRANSLATIONS__[] = {
QT_TRANSLATE_NOOP("HttpServer", "Invalid category name:\nPlease do not use any special characters in the category name."),
QT_TRANSLATE_NOOP("HttpServer", "Unknown"),
QT_TRANSLATE_NOOP("HttpServer", "Hard Disk"),
QT_TRANSLATE_NOOP("HttpServer", "Share ratio limit must be between 0 and 9998.")
QT_TRANSLATE_NOOP("HttpServer", "Seeding time limit must be between 0 and 525600 minutes.")
QT_TRANSLATE_NOOP("HttpServer", "Set location")
QT_TRANSLATE_NOOP("HttpServer", "Share ratio limit must be between 0 and 9998."),
QT_TRANSLATE_NOOP("HttpServer", "Seeding time limit must be between 0 and 525600 minutes."),
QT_TRANSLATE_NOOP("HttpServer", "Set location"),
QT_TRANSLATE_NOOP("HttpServer", "Limit upload rate"),
QT_TRANSLATE_NOOP("HttpServer", "Limit download rate"),
QT_TRANSLATE_NOOP("HttpServer", "Rename torrent")
};
static const struct { const char *source; const char *comment; } __COMMENTED_TRANSLATIONS__[] = {

20
src/webui/webapplication.cpp

@ -414,11 +414,16 @@ void WebApplication::action_command_download() @@ -414,11 +414,16 @@ void WebApplication::action_command_download()
const QString urls = request().posts.value("urls");
const bool skipChecking = parseBool(request().posts.value("skip_checking"), false);
const bool seqDownload = parseBool(request().posts.value("sequentialDownload"), false);
const bool firstLastPiece = parseBool(request().posts.value("firstLastPiecePrio"), false);
const TriStateBool addPaused = parseTristatebool(request().posts.value("paused"));
const TriStateBool rootFolder = parseTristatebool(request().posts.value("root_folder"));
const QString savepath = request().posts.value("savepath").trimmed();
const QString category = request().posts.value("category").trimmed();
const QString cookie = request().posts.value("cookie");
const QString torrentName = request().posts.value("rename").trimmed();
const int upLimit = request().posts.value("upLimit").toInt();
const int dlLimit = request().posts.value("dlLimit").toInt();
QList<QNetworkCookie> cookies;
if (!cookie.isEmpty()) {
@ -437,10 +442,15 @@ void WebApplication::action_command_download() @@ -437,10 +442,15 @@ void WebApplication::action_command_download()
BitTorrent::AddTorrentParams params;
// TODO: Check if destination actually exists
params.skipChecking = skipChecking;
params.sequential = seqDownload;
params.firstLastPiecePriority = firstLastPiece;
params.addPaused = addPaused;
params.createSubfolder = rootFolder;
params.savePath = savepath;
params.category = category;
params.name = torrentName;
params.uploadLimit = (upLimit > 0) ? upLimit : -1;
params.downloadLimit = (dlLimit > 0) ? dlLimit : -1;
bool partialSuccess = false;
for (QString url : urls.split('\n')) {
@ -462,10 +472,15 @@ void WebApplication::action_command_upload() @@ -462,10 +472,15 @@ void WebApplication::action_command_upload()
CHECK_URI(0);
const bool skipChecking = parseBool(request().posts.value("skip_checking"), false);
const bool seqDownload = parseBool(request().posts.value("sequentialDownload"), false);
const bool firstLastPiece = parseBool(request().posts.value("firstLastPiecePrio"), false);
const TriStateBool addPaused = parseTristatebool(request().posts.value("paused"));
const TriStateBool rootFolder = parseTristatebool(request().posts.value("root_folder"));
const QString savepath = request().posts.value("savepath").trimmed();
const QString category = request().posts.value("category").trimmed();
const QString torrentName = request().posts.value("rename").trimmed();
const int upLimit = request().posts.value("upLimit").toInt();
const int dlLimit = request().posts.value("dlLimit").toInt();
for (const Http::UploadedFile &torrent : request().files) {
const QString filePath = saveTmpFile(torrent.data);
@ -485,10 +500,15 @@ void WebApplication::action_command_upload() @@ -485,10 +500,15 @@ void WebApplication::action_command_upload()
BitTorrent::AddTorrentParams params;
// TODO: Check if destination actually exists
params.skipChecking = skipChecking;
params.sequential = seqDownload;
params.firstLastPiecePriority = firstLastPiece;
params.addPaused = addPaused;
params.createSubfolder = rootFolder;
params.savePath = savepath;
params.category = category;
params.name = torrentName;
params.uploadLimit = (upLimit > 0) ? upLimit : -1;
params.downloadLimit = (dlLimit > 0) ? dlLimit : -1;
if (!BitTorrent::Session::instance()->addTorrent(torrentInfo, params)) {
status(500, "Internal Server Error");

20
src/webui/www/private/login.html

@ -69,19 +69,19 @@ @@ -69,19 +69,19 @@
</style>
</head>
<body>
<div id="main">
<div id="main">
<h1>qBittorrent QBT_TR(Web UI)QBT_TR[CONTEXT=OptionsDialog]</h1>
<div id="logo" class="col">
<img src="images/qbittorrent.png" alt="qBittorrent logo"/>
</div>
<div id="formplace" class="col">
<form id="loginform" action="">
<div id="logo" class="col">
<img src="images/qbittorrent.png" alt="qBittorrent logo"/>
</div>
<div id="formplace" class="col">
<form id="loginform" action="">
<div class="row"><label for="username">QBT_TR(Username)QBT_TR[CONTEXT=HttpServer]</label><br /><input type="text" id="username" name="username" /></div>
<div class="row"><label for="password">QBT_TR(Password)QBT_TR[CONTEXT=HttpServer]</label><br /><input type="password" id="password" name="password" /></div>
<div class="row"><input type="submit" id="login" value="QBT_TR(Login)QBT_TR[CONTEXT=HttpServer]" /></div>
</form>
</div>
<div id="error_msg"></div>
</div>
</form>
</div>
<div id="error_msg"></div>
</div>
</body>
</html>

16
src/webui/www/public/addtrackers.html

@ -1,11 +1,11 @@ @@ -1,11 +1,11 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>QBT_TR(Trackers addition dialog)QBT_TR[CONTEXT=TrackersAdditionDlg]</title>
<link rel="stylesheet" href="css/style.css" type="text/css" />
<script type="text/javascript" src="scripts/mootools-1.2-core-yc.js" charset="utf-8"></script>
<script type="text/javascript" src="scripts/mootools-1.2-more.js" charset="utf-8"></script>
<link rel="stylesheet" href="css/style.css" type="text/css" />
<script type="text/javascript" src="scripts/mootools-1.2-core-yc.js" charset="utf-8"></script>
<script type="text/javascript" src="scripts/mootools-1.2-more.js" charset="utf-8"></script>
<script type="text/javascript">
window.addEvent('domready', function(){
$('trackersUrls').focus();
@ -26,11 +26,11 @@ @@ -26,11 +26,11 @@
</head>
<body>
<center>
<br/>
<br/>
<h2 class="vcenter">QBT_TR(List of trackers to add (one per line):)QBT_TR[CONTEXT=TrackersAdditionDlg]</h2>
<textarea name="list" id="trackersUrls" rows="10" cols="1"></textarea>
<br/>
<textarea name="list" id="trackersUrls" rows="10" cols="1"></textarea>
<br/>
<input type="button" value="QBT_TR(Add)QBT_TR[CONTEXT=HttpServer]" id="addTrackersButton"/>
</center>
</center>
</body>
</html>

21
src/webui/www/public/download.html

@ -25,6 +25,10 @@ @@ -25,6 +25,10 @@
<label for="cookie" class="leftLabelLarge">QBT_TR(Cookie:)QBT_TR[CONTEXT=HttpServer]</label>
<input type="text" id="cookie" name="cookie" style="width: 16em;"/>
</div>
<div class="formRow">
<label for="rename" class="leftLabelLarge">QBT_TR(Rename torrent)QBT_TR[CONTEXT=HttpServer]</label>
<input type="text" name="rename" style="width: 16em;"/>
</div>
<div class="formRow">
<label for="category" class="leftLabelLarge">QBT_TR(Category:)QBT_TR[CONTEXT=AddNewTorrentDialog]</label>
<input type="text" id="category" name="category" style="width: 16em;"/>
@ -42,6 +46,23 @@ @@ -42,6 +46,23 @@
<label for="root_folder" class="leftLabelLarge">QBT_TR(Create subfolder)QBT_TR[CONTEXT=AddNewTorrentDialog]</label>
<input type="checkbox" name="root_folder" value="true" checked="checked"/>
</div>
</div>
<div class="formRow">
<label for="sequentialDownload" class="leftLabelLarge">QBT_TR(Download in sequential order)QBT_TR[CONTEXT=TransferListWidget]</label>
<input type="checkbox" name="sequentialDownload" value="true"/>
</div>
<div class="formRow">
<label for="firstLastPiecePrio" class="leftLabelLarge">QBT_TR(Download first and last pieces first)QBT_TR[CONTEXT=TransferListWidget]</label>
<input type="checkbox" name="firstLastPiecePrio" value="true"/>
</div>
<div class="formRow">
<label for="dlLimit" class="leftLabelLarge">QBT_TR(Limit download rate)QBT_TR[CONTEXT=HttpServer]</label>
<input type="text" name="dlLimit" style="width: 16em;" placeholder="Bytes/s"/>
</div>
<div class="formRow">
<label for="upLimit" class="leftLabelLarge">QBT_TR(Limit upload rate)QBT_TR[CONTEXT=HttpServer]</label>
<input type="text" name="upLimit" style="width: 16em;" placeholder="Bytes/s"/>
</div>
<div id="submitbutton" style="margin-top: 12px; text-align: center;">
<button type="submit" id="submitButton">QBT_TR(Download)QBT_TR[CONTEXT=downloadFromURL]</button>
</div>

12
src/webui/www/public/preferences.html

@ -1,25 +1,25 @@ @@ -1,25 +1,25 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>QBT_TR(Download from URLs)QBT_TR[CONTEXT=downloadFromURL]</title>
<link rel="stylesheet" href="css/style.css" type="text/css" />
<link rel="stylesheet" href="css/style.css" type="text/css" />
<link rel="stylesheet" href="css/Tabs.css" type="text/css" />
<script type="text/javascript" src="scripts/mootools-1.2-core-yc.js" charset="utf-8"></script>
<script type="text/javascript" src="scripts/mootools-1.2-core-yc.js" charset="utf-8"></script>
<script type="text/javascript" src="scripts/mootools-1.2-more.js" charset="utf-8"></script>
<script type="text/javascript" src="scripts/mocha-yc.js" charset="utf-8"></script>
</head>
<body style="padding: 5px;">
<!-- preferences -->
<div class="toolbarTabs">
<ul id="preferencesTabs" class="tab-menu">
<ul id="preferencesTabs" class="tab-menu">
<li id="PrefDownloadsLink" class="selected"><a>QBT_TR(Downloads)QBT_TR[CONTEXT=OptionsDialog]</a></li>
<li id="PrefConnectionLink"><a>QBT_TR(Connection)QBT_TR[CONTEXT=OptionsDialog]</a></li>
<li id="PrefSpeedLink"><a>QBT_TR(Speed)QBT_TR[CONTEXT=OptionsDialog]</a></li>
<li id="PrefBittorrentLink"><a>QBT_TR(BitTorrent)QBT_TR[CONTEXT=OptionsDialog]</a></li>
<li id="PrefWebUILink"><a>QBT_TR(Web UI)QBT_TR[CONTEXT=OptionsDialog]</a></li>
</ul>
<div class="clear"></div>
</ul>
<div class="clear"></div>
</div>
<script type="text/javascript">

48
src/webui/www/public/upload.html

@ -1,29 +1,33 @@ @@ -1,29 +1,33 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>QBT_TR(Upload local torrent)QBT_TR[CONTEXT=HttpServer]</title>
<link rel="stylesheet" href="css/style.css" type="text/css" />
<link rel="stylesheet" href="css/Window.css" type="text/css" />
<script type="text/javascript" src="scripts/mootools-1.2-core-yc.js" charset="utf-8"></script>
<script type="text/javascript" src="scripts/download.js" charset="utf-8"></script>
<link rel="stylesheet" href="css/style.css" type="text/css" />
<link rel="stylesheet" href="css/Window.css" type="text/css" />
<script type="text/javascript" src="scripts/mootools-1.2-core-yc.js" charset="utf-8"></script>
<script type="text/javascript" src="scripts/download.js" charset="utf-8"></script>
</head>
<body>
<iframe id="upload_frame" name="upload_frame" class="invisible" src="javascript:false;"></iframe>
<form action="command/upload" enctype="multipart/form-data" method="post" id="uploadForm" style="text-align: center;" target="upload_frame">
<p>
<div style="margin-top: 25px; display: inline-block; border: 1px solid lightgrey; border-radius: 4px;">
<input type="file" id="fileselect" name="fileselect[]" multiple="multiple"/>
</div>
<div style="margin-top: 25px; display: inline-block; border: 1px solid lightgrey; border-radius: 4px;">
<input type="file" id="fileselect" name="fileselect[]" multiple="multiple"/>
</div>
</p>
<fieldset class="settings" style="border: 0; text-align: left;">
<div class="formRow" style="margin-top: 12px;">
<label for="savepath" class="leftLabelLarge">QBT_TR(Save files to location:)QBT_TR[CONTEXT=HttpServer]</label>
<input type="text" id="savepath" name="savepath" style="width: 16em;"/>
<input type="text" id="savepath" name="savepath" style="width: 16em;"/>
</div>
<div class="formRow">
<label for="rename" class="leftLabelLarge">QBT_TR(Rename torrent)QBT_TR[CONTEXT=HttpServer]</label>
<input type="text" name="rename" style="width: 16em;"/>
</div>
<div class="formRow">
<label for="category" class="leftLabelLarge">QBT_TR(Category:)QBT_TR[CONTEXT=AddNewTorrentDialog]</label>
<input type="text" id="category" name="category"/ style="width: 16em;"/>
<input type="text" id="category" name="category" style="width: 16em;"/>
</div>
<div class="formRow">
<label for="start_torrent" class="leftLabelLarge">QBT_TR(Start torrent)QBT_TR[CONTEXT=AddNewTorrentDialog]</label>
@ -38,6 +42,22 @@ @@ -38,6 +42,22 @@
<label for="root_folder" class="leftLabelLarge">QBT_TR(Create subfolder)QBT_TR[CONTEXT=AddNewTorrentDialog]</label>
<input type="checkbox" name="root_folder" value="true" checked="checked"/>
</div>
<div class="formRow">
<label for="sequentialDownload" class="leftLabelLarge">QBT_TR(Download in sequential order)QBT_TR[CONTEXT=TransferListWidget]</label>
<input type="checkbox" name="sequentialDownload" value="true"/>
</div>
<div class="formRow">
<label for="firstLastPiecePrio" class="leftLabelLarge">QBT_TR(Download first and last pieces first)QBT_TR[CONTEXT=TransferListWidget]</label>
<input type="checkbox" name="firstLastPiecePrio" value="true"/>
</div>
<div class="formRow">
<label for="dlLimit" class="leftLabelLarge">QBT_TR(Limit download rate)QBT_TR[CONTEXT=HttpServer]</label>
<input type="text" name="dlLimit" style="width: 16em;" placeholder="Bytes/s"/>
</div>
<div class="formRow">
<label for="upLimit" class="leftLabelLarge">QBT_TR(Limit upload rate)QBT_TR[CONTEXT=HttpServer]</label>
<input type="text" name="upLimit" style="width: 16em;" placeholder="Bytes/s"/>
</div>
<div id="submitbutton" style="margin-top: 30px; text-align: center;">
<button type="submit" style="font-size: 1em;">QBT_TR(Upload Torrents)QBT_TR[CONTEXT=HttpServer]</button>
</div>
@ -48,13 +68,13 @@ @@ -48,13 +68,13 @@
var submitted = false;
$('uploadForm').addEventListener("submit", function() {
$('upload_spinner').style.display = "block";
submitted = true;
$('upload_spinner').style.display = "block";
submitted = true;
});
$('upload_frame').addEventListener("load", function() {
if (submitted)
window.parent.closeWindows();
if (submitted)
window.parent.closeWindows();
});
$('start_torrent').addEventListener('change', function() {

Loading…
Cancel
Save