2020
2121public class OnlineLoader extends FileLoader {
2222
23- private static final String TRANSFER_BASE_URL = "https://transfershxuil1jyq- transfer-sh.functions.fnc.nl-ams.scw.cloud " ;
23+ private static final String TRANSFER_BASE_URL = "https://transfer.opendocument.app/ " ;
2424
2525 // https://help.joomlatools.com/article/169-google-viewer
2626 // https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Complete_list_of_MIME_types
@@ -99,7 +99,7 @@ public void loadSync(Options options) {
9999 try {
100100 Uri viewerUri ;
101101 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O &&
102- ("text/rtf" .equals (options .fileType ))) {
102+ ("text/rtf" .equals (options .fileType ) || "application/vnd.wordperfect" . equals ( options . fileType ) || coreLoader . isSupported ( options ) || "application/vnd.ms-excel" . equals ( options . fileType ) || "application/msword" . equals ( options . fileType ) || "application/vnd.ms-powerpoint" . equals ( options . fileType ) || options . fileType . startsWith ( "application/vnd.openxmlformats-officedocument." ) || options . fileType . equals ( "application/pdf" ) )) {
103103 viewerUri = doOnlineConvert (options );
104104 } else {
105105 viewerUri = doTransferUpload (options );
@@ -151,19 +151,12 @@ private Uri doOnlineConvert(Options options) throws IOException {
151151 private Uri doTransferUpload (Options options ) throws IOException {
152152 File binaryFile = AndroidFileCache .getCacheFile (context , options .cacheUri );
153153 String filename = options .filename ;
154- if (filename == null || filename .isEmpty ()) {
155- filename = "document." + options .fileExtension ;
156- }
157-
158154 String encodedFilename = URLEncoder .encode (filename , StreamUtil .ENCODING );
159- String basePath = ensureTrailingSlash ( TRANSFER_BASE_URL );
160- HttpURLConnection connection = (HttpURLConnection ) new URL (basePath + encodedFilename ).openConnection ();
155+
156+ HttpURLConnection connection = (HttpURLConnection ) new URL (TRANSFER_BASE_URL + encodedFilename ).openConnection ();
161157 connection .setRequestMethod ("PUT" );
162158 connection .setDoOutput (true );
163159 connection .setInstanceFollowRedirects (false );
164- if (!"N/A" .equals (options .fileType )) {
165- connection .setRequestProperty ("Content-Type" , options .fileType );
166- }
167160
168161 try (OutputStream outputStream = connection .getOutputStream ()) {
169162 Files .copy (binaryFile .toPath (), outputStream );
@@ -173,10 +166,6 @@ private Uri doTransferUpload(Options options) throws IOException {
173166 int responseCode = connection .getResponseCode ();
174167 if (responseCode >= 200 && responseCode < 300 ) {
175168 String downloadUrl = readBody (connection );
176- if (downloadUrl == null || downloadUrl .isEmpty ()) {
177- downloadUrl = connection .getHeaderField ("Location" );
178- }
179-
180169 if (downloadUrl == null || downloadUrl .isEmpty ()) {
181170 throw new IOException ("server couldn't handle request" );
182171 }
@@ -197,14 +186,6 @@ private Uri buildViewerUri(Options options, String downloadUrl) throws Unsupport
197186 }
198187 }
199188
200- private String ensureTrailingSlash (String base ) {
201- if (base .endsWith ("/" )) {
202- return base ;
203- }
204-
205- return base + "/" ;
206- }
207-
208189 private String readBody (HttpURLConnection connection ) throws IOException {
209190 InputStream inputStream = connection .getInputStream ();
210191 if (inputStream == null ) {
0 commit comments