Merge Upstream
This commit is contained in:
commit
59537c6574
@ -25,6 +25,10 @@ Sende /hilfe, um zu starten
|
||||
-- NOTE that it doesn't matter, if the chat is whitelisted! The USER must be whitelisted!
|
||||
enable_inline_for_everyone = true,
|
||||
|
||||
-- Path, where getFile.lua should store the files WITHOUT an ending slash!
|
||||
-- Create the following folders in this folder: photo, document, video, voice
|
||||
getfile_path = '/tmp/telegram_files',
|
||||
|
||||
-- Redis settings. Only edit if you know what you're doing.
|
||||
redis = {
|
||||
host = '127.0.0.1',
|
||||
|
@ -7,7 +7,7 @@ media_download.triggers = {
|
||||
'/nil'
|
||||
}
|
||||
|
||||
function media_download:download_to_file_permanently(url, file_name)
|
||||
function media_download:download_to_file_permanently(url, save_dir, file_name)
|
||||
local respbody = {}
|
||||
local options = {
|
||||
url = url,
|
||||
@ -23,9 +23,7 @@ function media_download:download_to_file_permanently(url, file_name)
|
||||
|
||||
if code ~= 200 then return false end
|
||||
|
||||
-- TODO: Save, when folder doesn't exist
|
||||
-- Create necessary folders in this folder!
|
||||
local file_path = "tmp/"..file_name
|
||||
local file_path = save_dir..'/'..file_name
|
||||
file = io.open(file_path, "w+")
|
||||
file:write(table.concat(respbody))
|
||||
file:close()
|
||||
@ -54,19 +52,25 @@ function media_download:pre_process(msg, self, config)
|
||||
file_id = msg.document.file_id
|
||||
file_size = msg.document.file_size
|
||||
else
|
||||
return
|
||||
return msg
|
||||
end
|
||||
|
||||
if file_size > 19922944 then
|
||||
print('Datei ist größer als 20 MB - Nicht downloadbar!')
|
||||
return
|
||||
return msg
|
||||
end
|
||||
|
||||
local save_dir = config.getfile_path
|
||||
if not save_dir then
|
||||
print('getfile_path wurde nicht in der Config gesetzt, breche ab...')
|
||||
return msg
|
||||
end
|
||||
|
||||
-- Check if file has already been downloaded
|
||||
local already_downloaded = redis:sismember('telegram:file_id', file_id)
|
||||
if already_downloaded == true then
|
||||
print('Datei wurde bereits gedownloadet')
|
||||
return
|
||||
return msg
|
||||
end
|
||||
|
||||
-- Saving file to the Telegram Cloud
|
||||
@ -77,7 +81,7 @@ function media_download:pre_process(msg, self, config)
|
||||
-- Getting file from the Telegram Cloud
|
||||
if not request then
|
||||
print('Download fehlgeschlagen!')
|
||||
return
|
||||
return msg
|
||||
end
|
||||
|
||||
-- Use original filename for documents
|
||||
@ -89,10 +93,11 @@ function media_download:pre_process(msg, self, config)
|
||||
|
||||
-- Construct what we want
|
||||
local download_url = 'https://api.telegram.org/file/bot'..config.bot_api_key..'/'..request.result.file_path
|
||||
local ok = media_download:download_to_file_permanently(download_url, file_path)
|
||||
|
||||
local ok = media_download:download_to_file_permanently(download_url, save_dir, file_path)
|
||||
if not ok then
|
||||
print('Download fehlgeschlagen!')
|
||||
return
|
||||
return msg
|
||||
end
|
||||
|
||||
-- Save file_id to redis to prevent downloading the same file over and over when forwarding
|
||||
|
Reference in New Issue
Block a user