Skip to content

Commit

Permalink
Show notification when torrent added
Browse files Browse the repository at this point in the history
  • Loading branch information
wolandmaster committed Jun 28, 2021
1 parent 3ce483d commit fc2246f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/usr/lib/lua/luci/model/cbi/rtorrent/add.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ local uploads = "/etc/luci-uploads/rtorrent"
local form, uri, file, dir, tags, start

form = SimpleForm("rtorrent", "Add Torrent")
form.template = "rtorrent/simpleform"
form.submit = "Add"
form.notifications = {}
form.parse = function(self, ...)
local state = SimpleForm.parse(self, ...)
if state == FORM_VALID then
Expand All @@ -24,6 +26,10 @@ form.parse = function(self, ...)
file:add_error(1, "missing", "Either a torrent URL / magnet URI or "
.. "an uploaded torrent file must be provided!")
state = FORM_INVALID
else
for _, torrent in torrents:pairs() do
table.insert(form.notifications, "Added <i>%s</i>" % torrent:get("name"))
end
end
end
return state
Expand Down Expand Up @@ -55,6 +61,8 @@ uri.validate = function(self, value, section)
if not content then errors:insert("Failed to encode torrent: " .. err .. "!")
else
torrents:insert({
["name"] = magnet:get("dn")
and magnet:get("dn"):get(1) or line:trim(),
["data"] = nixio.bin.b64encode(content),
["icon"] = common.tracker_icon(common.extract_urls(magnet))
})
Expand All @@ -76,6 +84,7 @@ uri.validate = function(self, value, section)
else
-- TODO: extract comment from torrent file
torrents:insert({
["name"] = data.info.name,
["data"] = nixio.bin.b64encode(content),
["icon"] = common.tracker_icon(array({ line:trim(),
unpack(common.extract_urls(array(data)):get()) })),
Expand Down Expand Up @@ -114,6 +123,7 @@ file.validate = function(self, value, section)
end
-- TODO: extract comment from torrent file
torrents:insert({
["name"] = data.info.name,
["data"] = nixio.bin.b64encode(content),
["icon"] = common.tracker_icon(common.extract_urls(array(data)))
})
Expand Down
2 changes: 1 addition & 1 deletion src/usr/lib/lua/luci/model/cbi/rtorrent/string.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ end
function string.urldecode(str)
return (str:gsub("%%(%x%x)", function(hex)
return string.char(tonumber(hex, 16))
end))
end):gsub("+", " "))
end

function string.unicode_to_html(str)
Expand Down
7 changes: 6 additions & 1 deletion src/usr/lib/lua/luci/view/rtorrent/simpleform.htm
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
document.addEventListener("luci-loaded", async () => {
const header = await selectElement("div.cbi-map h2");
selectElement("#maincontent").then(main => main[0].prepend(...header));
<% for i, tab in ipairs(self.all_tabs) do %>
<% for i, tab in ipairs(self.all_tabs or {}) do %>
eachElement("ul.tabs li.tabmenu-item-<%=tab%> a",
tab => tab.href += "/<%=self.tab_url_postfix(tab)%>");
<%- end %>
});
L.require('ui').then(function(ui) {
<% for _, notification in ipairs(self.notifications or {}) do %>
ui.addNotification(null, "<p><%=notification%></p>");
<%- end %>
});
</script>

0 comments on commit fc2246f

Please sign in to comment.