- GDrive: Migriere zu API Version 3, Fix #7
This commit is contained in:
parent
c6ae1c8e18
commit
a1efc24d20
@ -22,13 +22,13 @@ end
|
|||||||
|
|
||||||
local apikey = cred_data.google_apikey
|
local apikey = cred_data.google_apikey
|
||||||
|
|
||||||
local BASE_URL = 'https://www.googleapis.com/drive/v2'
|
local BASE_URL = 'https://www.googleapis.com/drive/v3'
|
||||||
|
local apikey = cred_data.google_apikey
|
||||||
|
|
||||||
function gdrive:get_drive_document_data (docid)
|
function gdrive:get_drive_document_data (docid)
|
||||||
local apikey = cred_data.google_apikey
|
local url = BASE_URL..'/files/'..docid..'?key='..apikey..'&fields=id,name,mimeType,owners,fullFileExtension'
|
||||||
local url = BASE_URL..'/files/'..docid..'?key='..apikey..'&fields=id,title,mimeType,ownerNames,exportLinks,fileExtension'
|
|
||||||
local res, code = https.request(url)
|
local res, code = https.request(url)
|
||||||
local res = string.gsub(res, 'image/', '')
|
local res = string.gsub(res, 'image/', '') -- snip mimetype
|
||||||
local res = string.gsub(res, 'application/', '')
|
local res = string.gsub(res, 'application/', '')
|
||||||
if code ~= 200 then return nil end
|
if code ~= 200 then return nil end
|
||||||
local data = json.decode(res)
|
local data = json.decode(res)
|
||||||
@ -36,20 +36,20 @@ function gdrive:get_drive_document_data (docid)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function gdrive:send_drive_document_data(data, self, msg)
|
function gdrive:send_drive_document_data(data, self, msg)
|
||||||
local title = data.title
|
local title = data.name
|
||||||
local mimetype = data.mimeType
|
local mimetype = data.mimeType
|
||||||
local id = data.id
|
local id = data.id
|
||||||
local owner = data.ownerNames[1]
|
local owner = data.owners[1].displayName
|
||||||
local text = '"'..title..'", freigegeben von '..owner
|
local text = '"'..title..'", freigegeben von '..owner
|
||||||
if data.exportLinks then
|
if mimetype:match('google') then -- if document is Google document (like a Spreadsheet)
|
||||||
if data.exportLinks.png then
|
if mimetype:match('drawing') then -- Drawing
|
||||||
local image_url = data.exportLinks.png
|
local image_url = BASE_URL..'/files/'..id..'/export?key='..apikey..'&mimeType=image/png'
|
||||||
utilities.send_typing(self, msg.chat.id, 'upload_photo')
|
utilities.send_typing(self, msg.chat.id, 'upload_photo')
|
||||||
local file = download_to_file(image_url, 'photo.png')
|
local file = download_to_file(image_url, 'export.png')
|
||||||
utilities.send_photo(self, msg.chat.id, file, text, msg.message_id)
|
utilities.send_photo(self, msg.chat.id, file, text, msg.message_id)
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
local pdf_url = data.exportLinks.pdf
|
local pdf_url = BASE_URL..'/files/'..id..'/export?key='..apikey..'&mimeType=application/pdf'
|
||||||
utilities.send_typing(self, msg.chat.id, 'upload_document')
|
utilities.send_typing(self, msg.chat.id, 'upload_document')
|
||||||
local file = download_to_file(pdf_url, 'document.pdf')
|
local file = download_to_file(pdf_url, 'document.pdf')
|
||||||
utilities.send_document(self, msg.chat.id, file, text, msg.message_id)
|
utilities.send_document(self, msg.chat.id, file, text, msg.message_id)
|
||||||
@ -58,7 +58,7 @@ function gdrive:send_drive_document_data(data, self, msg)
|
|||||||
else
|
else
|
||||||
local get_file_url = 'https://drive.google.com/uc?id='..id
|
local get_file_url = 'https://drive.google.com/uc?id='..id
|
||||||
local keyboard = '{"inline_keyboard":[[{"text":"Direktlink","url":"'..get_file_url..'"}]]}'
|
local keyboard = '{"inline_keyboard":[[{"text":"Direktlink","url":"'..get_file_url..'"}]]}'
|
||||||
local ext = data.fileExtension
|
local ext = data.fullFileExtension
|
||||||
if mimetype == "png" or mimetype == "jpg" or mimetype == "jpeg" or mimetype == "gif" or mimetype == "webp" then
|
if mimetype == "png" or mimetype == "jpg" or mimetype == "jpeg" or mimetype == "gif" or mimetype == "webp" then
|
||||||
local respbody = {}
|
local respbody = {}
|
||||||
local options = {
|
local options = {
|
||||||
|
Reference in New Issue
Block a user