]> Joshua Wise's Git repositories - dumload.git/blobdiff - src/com/joshuawise/dumload/Uploader.java
GPLv3
[dumload.git] / src / com / joshuawise / dumload / Uploader.java
index 763e3f0d31e9c2d91d8ec9059cee91991aee6867..12f71e280bf08ab896d237d2b2e8ee179b7d4f1e 100644 (file)
@@ -1,3 +1,19 @@
+/* Uploader.java
+ * Back-end upload logic for Dumload.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License, version 3, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 package com.joshuawise.dumload;
 
 import java.io.InputStream;
@@ -35,6 +51,7 @@ public class Uploader extends Service implements Runnable, UserInfo, UIKeyboardI
        private int thenotifid;
        private Notification thenotif;
        private String headline;
+       private String dest;
        
        private InputStream is;
        
@@ -267,7 +284,7 @@ public class Uploader extends Service implements Runnable, UserInfo, UIKeyboardI
                
                Log.e("Dumload.Uploader[thread]", "This brought to you from the new thread.");
                
-               set_up_notif("Dumload upload in progress");
+               set_up_notif("Dumload upload: " + dest);
                
                try {
                        say("Uploading "+(Integer.toString(is.available()))+" bytes");
@@ -276,12 +293,16 @@ public class Uploader extends Service implements Runnable, UserInfo, UIKeyboardI
                
                        JSch jsch = new JSch();
                        jsch.setKnownHosts(homedir + "/known_hosts");
+                       try {
+                               jsch.addIdentity(homedir + "/id_dsa");
+                       } catch (java.lang.Exception e) {
+                       }
                        Session s = jsch.getSession("joshua", "nyus.joshuawise.com", 22);
                        s.setUserInfo(this);
                        s.connect();
                        
                        Channel channel = s.openChannel("exec");
-                       ((ChannelExec)channel).setCommand("scp -t /tmp/lol");
+                       ((ChannelExec)channel).setCommand("scp -t "+dest);
                        channel.connect();
                        
                        OutputStream scp_out = channel.getOutputStream();
@@ -292,7 +313,13 @@ public class Uploader extends Service implements Runnable, UserInfo, UIKeyboardI
                        /* Okay, BS out of the way.  Now go send the file. */
                        expect_ack(scp_in);
                        
-                       scp_out.write(("C0644 " + (Integer.toString(is.available())) + " lol\n").getBytes());
+                       String stfu;
+                       if (dest.lastIndexOf("/") > 0)
+                               stfu = dest.substring(dest.lastIndexOf("/") + 1);
+                       else
+                               stfu = dest;
+                       
+                       scp_out.write(("C0644 " + (Integer.toString(is.available())) + " "+stfu+"\n").getBytes());
                        scp_out.flush();
                        
                        expect_ack(scp_in);
@@ -311,16 +338,32 @@ public class Uploader extends Service implements Runnable, UserInfo, UIKeyboardI
                        
                        is.close();
                        
-                       update_notif("Disconnecting...");
+                       update_notif("Finishing file transfer...");
                        
                        scp_out.write("\0".getBytes());
                        scp_out.flush();
                        
                        expect_ack(scp_in);
                        
-                       sayNullNotification("Dumload upload complete", "Upload complete", "Dumload has finished uploading your file.");
-
                        channel.disconnect();
+                       
+                       update_notif("Preparing to resize image...");
+                       
+                       channel = s.openChannel("exec");
+                       ((ChannelExec)channel).setCommand("pscale "+dest);
+                       channel.connect();
+                       
+                       scp_in = channel.getInputStream();
+                       
+                       update_notif("Resizing image...");
+                       while ((len = scp_in.read(buf, 0, buf.length)) > 0)
+                               ;
+                       
+                       channel.disconnect();
+                       update_notif("Upload complete.");
+                       
+                       sayNullNotification("Dumload upload complete: " + dest, "Upload complete", "Uploaded: " + dest);
+
                        s.disconnect();
                } catch (Exception e) {
                        Log.e("Dumload.uploader[thread]", "JSchException: "+(e.toString()));
@@ -340,6 +383,7 @@ public class Uploader extends Service implements Runnable, UserInfo, UIKeyboardI
        public void onStart(Intent i, int startId)
        {
                uri = i.getData();
+               dest = i.getStringExtra("com.joshuawise.dumload.dest");
                homedir = getApplicationContext().getFilesDir().getAbsolutePath();
                int shits = 0;
                
This page took 0.027166 seconds and 4 git commands to generate.