mirror of
https://github.com/Fishwaldo/huginn.git
synced 2025-03-16 03:41:41 +00:00
Add support to dropbox_file_url_agent for permanent links
This commit is contained in:
parent
daaf75681d
commit
ab017ad2e2
1 changed files with 19 additions and 3 deletions
|
@ -6,7 +6,7 @@ module Agents
|
|||
no_bulk_receive!
|
||||
|
||||
description <<-MD
|
||||
The Dropbox File Url Agent is used to work with Dropbox. It takes a file path (or multiple file paths) and emits events with [temporary links](https://www.dropbox.com/developers/core/docs#media).
|
||||
The _DropboxFileUrlAgent_ is used to work with Dropbox. It takes a file path (or multiple files paths) and emits events with either [temporary links](https://www.dropbox.com/developers/core/docs#media) or [permanent links](https://www.dropbox.com/developers/core/docs#shares).
|
||||
|
||||
#{'## Include the `dropbox-api` and `omniauth-dropbox` gems in your `Gemfile` and set `DROPBOX_OAUTH_KEY` and `DROPBOX_OAUTH_SECRET` in your environment to use Dropbox Agents.' if dependencies_missing?}
|
||||
|
||||
|
@ -28,6 +28,8 @@ module Agents
|
|||
|
||||
An example of usage would be to watch a specific Dropbox directory (with the _DropboxWatchAgent_) and get the URLs for the added or updated files. You could then, for example, send emails with those links.
|
||||
|
||||
Set `link_type` to `'temporary'` if you want temporary links, or to `'permanent'` for permanent ones.
|
||||
|
||||
MD
|
||||
|
||||
event_description <<-MD
|
||||
|
@ -39,21 +41,35 @@ module Agents
|
|||
}
|
||||
MD
|
||||
|
||||
def default_options
|
||||
{
|
||||
'link_type' => 'temporary'
|
||||
}
|
||||
end
|
||||
|
||||
def working?
|
||||
!recent_error_logs?
|
||||
end
|
||||
|
||||
def receive(events)
|
||||
events.map { |e| e.payload['paths'].split(',').map(&:strip) }
|
||||
.flatten.each { |path| create_event payload: url_for(path) }
|
||||
.flatten.each do |path|
|
||||
create_event payload: (options['link_type'] == 'permanent' ? permanent_url_for(path) : temporary_url_for(path))
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def url_for(path)
|
||||
def temporary_url_for(path)
|
||||
dropbox.find(path).direct_url
|
||||
end
|
||||
|
||||
def permanent_url_for(path)
|
||||
result = dropbox.find(path).share_url({ :short_url => false })
|
||||
result.url = result.url.gsub('?dl=0','?dl=1') # cause the url to point to the file, instead of to a preview page for the file
|
||||
result
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue