From fca71fde0161a59ac650bd690a3413ffd866662d Mon Sep 17 00:00:00 2001 From: Jeffrey Armstrong Date: Mon, 12 Apr 2021 10:32:39 -0400 Subject: URLs in instructions can now leave out the server implying download and upload from the server itself. Download and upload both work correctly. --- player/tasks.f90 | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) (limited to 'player/tasks.f90') diff --git a/player/tasks.f90 b/player/tasks.f90 index c64cb40..87b7d66 100644 --- a/player/tasks.f90 +++ b/player/tasks.f90 @@ -70,7 +70,7 @@ contains end function shell function upload(url, source_filename) - use config, only: token + use config, only: token, captain use gemini_protocol, only: titan_post_url, STATUS_SUCCESS implicit none @@ -81,15 +81,26 @@ contains character(len=:), allocatable::mod_url integer(kind=8)::file_size - integer::unit_number, istatus + integer::unit_number, istatus, url_length inquire(file=source_filename, size=file_size) open(newunit=unit_number, file=trim(source_filename), status='UNKNOWN', & access='STREAM', form='UNFORMATTED', iostat=istatus) - - allocate(character(len=len_trim(url)) :: mod_url) - mod_url = url + + if(index(url, "://") > 0) then + allocate(character(len=len_trim(url)) :: mod_url) + mod_url = url + else + url_length = len_trim(url) + len_trim(captain) + 16 + allocate(character(len=url_length) :: mod_url) + mod_url = "titan://"//trim(captain) + if(url(1:1) == "/") then + mod_url = trim(mod_url)//trim(url) + else + mod_url = trim(mod_url)//"/"//trim(url) + end if + end if if(istatus == 0) then istatus = titan_post_url(mod_url, unit_number, file_size, token) @@ -105,6 +116,7 @@ contains function download(url, destination_filename) use gemini_protocol, only: request_url, STATUS_SUCCESS + use config, only: captain implicit none logical::download @@ -114,14 +126,26 @@ contains character(len=256)::mimetype character(len=:), allocatable::mod_url + integer::url_length integer::unit_number, istatus - allocate(character(len=len_trim(url)) :: mod_url) - mod_url = url + if(index(url, "://") > 0) then + allocate(character(len=len_trim(url)) :: mod_url) + mod_url = url + else + url_length = len_trim(url) + len_trim(captain) + 16 + allocate(character(len=url_length) :: mod_url) + mod_url = "gemini://"//trim(captain) + if(url(1:1) == "/") then + mod_url = trim(mod_url)//trim(url) + else + mod_url = trim(mod_url)//"/"//trim(url) + end if + end if open(newunit=unit_number, file=trim(destination_filename), status='UNKNOWN', & - access='STREAM', form='UNFORMATTED', iostat=istatus) + access='STREAM', form='FORMATTED', iostat=istatus) if(istatus == 0) then istatus = request_url(mod_url, unit_number, mimetype) -- cgit v1.2.3