load public media from cache

This commit is contained in:
Page Asgardius 2023-02-03 16:24:18 -07:00
parent 7aa05c783a
commit 55b5113fd3
3 changed files with 21 additions and 12 deletions

View file

@ -44,7 +44,7 @@ public class ObjectSelect extends AppCompatActivity {
ArrayList Img;
//ArrayList object;
RecyclerView recyclerView;
String username, password, endpoint, bucket, prefix, location, pdfendpoint, query;
String username, password, endpoint, bucket, prefix, location, pdfendpoint, query, policy;
boolean style, isplaylist;
String[] filename;
Region region;
@ -321,6 +321,7 @@ public class ObjectSelect extends AppCompatActivity {
pdfread.start();
}
} else if (Img.get(position).equals(R.drawable.audiofile) || Img.get(position).equals(R.drawable.videofile)) {
simpleProgressBar.setVisibility(View.VISIBLE);
if (isplaylist) {
videoPlayer(null, Name.get(position).toString());
} else {
@ -337,15 +338,21 @@ public class ObjectSelect extends AppCompatActivity {
mycal.add(Calendar.HOUR, videotime);
//System.out.println("Expiration date: " + mycal.getTime());
expiration = mycal.getTime();
GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket, prefix + Name.get(position).toString()).withExpiration(expiration);;
URL objectURL = s3client.generatePresignedUrl(request);
try {
policy = s3client.getBucketPolicy(bucket).getPolicyText();
} catch (Exception e) {
policy = null;
}
String objectURL = PolicyCheck.getFileKey(s3client, bucket, prefix + Name.get(position).toString(), expiration, policy);
/*GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket, prefix + Name.get(position).toString()).withExpiration(expiration);;
URL objectURL = s3client.generatePresignedUrl(request);*/
runOnUiThread(new Runnable() {
@Override
public void run() {
// Sending reference and data to Adapter
videoPlayer(objectURL.toString(), Name.get(position).toString());
videoPlayer(objectURL, Name.get(position).toString());
}
});
//System.out.println("tree "+treelevel);
@ -493,6 +500,7 @@ public class ObjectSelect extends AppCompatActivity {
intent.putExtra("isplaylist", isplaylist);
intent.putExtra("queue", links);
intent.putExtra("names", medialist);
simpleProgressBar.setVisibility(View.INVISIBLE);
startActivity(intent);
}
});
@ -519,6 +527,7 @@ public class ObjectSelect extends AppCompatActivity {
intent.putExtra("videocache", videocache);
intent.putExtra("buffersize", buffersize);
intent.putExtra("isplaylist", isplaylist);
simpleProgressBar.setVisibility(View.INVISIBLE);
startActivity(intent);
}
@ -774,8 +783,9 @@ public class ObjectSelect extends AppCompatActivity {
//System.out.println("Expiration date: " + mycal.getTime());
expiration = mycal.getTime();
for (int i = 0; i < medialist.size(); i++) {
GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket, prefix+medialist.get(i)).withExpiration(expiration);;
links.add(s3client.generatePresignedUrl(request).toString());
//GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket, prefix+medialist.get(i)).withExpiration(expiration);;
//links.add(s3client.generatePresignedUrl(request).toString());
links.add(PolicyCheck.getFileKey(s3client, bucket, prefix+medialist.get(i), expiration, policy));
}
return links;
}

View file

@ -6,11 +6,10 @@ import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest;
import java.util.Date;
public class PolicyCheck {
public static String getFileKey(AmazonS3 s3client, String bucket, String object, Date expiration) {
public static String getFileKey(AmazonS3 s3client, String bucket, String object, Date expiration, String policy) {
try {
Boolean publicobject;
String fileKey = null;
String policy = s3client.getBucketPolicy(bucket).getPolicyText();
publicobject = false;
if(policy.contains("arn:aws:s3:::"+bucket+"/*") && policy.contains("s3:GetObject")) {
publicobject = true;

View file

@ -35,7 +35,7 @@ import java.util.Date;
import java.util.List;
public class Share extends AppCompatActivity {
String username, password, endpoint, bucket, object, location, title, objectlist;
String username, password, endpoint, bucket, object, location, title, objectlist, policy;
boolean mediafile, style, publicobject;
TextView expirationtext;
ProgressBar simpleProgressBar;
@ -126,7 +126,7 @@ public class Share extends AppCompatActivity {
public void run() {
try {
//Your code goes here
String policy = s3client.getBucketPolicy(bucket).getPolicyText();
policy = s3client.getBucketPolicy(bucket).getPolicyText();
publicobject = false;
if(policy.contains("arn:aws:s3:::"+bucket+"/*") && policy.contains("s3:GetObject")) {
publicobject = true;
@ -372,13 +372,13 @@ public class Share extends AppCompatActivity {
objectlist = "";
List<S3ObjectSummary> objects = result.getObjectSummaries();
for (S3ObjectSummary os : objects) {
objectlist = objectlist+PolicyCheck.getFileKey(s3client, bucket, os.getKey(), expiration)+"\n";
objectlist = objectlist+PolicyCheck.getFileKey(s3client, bucket, os.getKey(), expiration, policy)+"\n";
}
while (result.isTruncated()) {
result = s3client.listNextBatchOfObjects (result);
objects = result.getObjectSummaries();
for (S3ObjectSummary os : objects) {
objectlist = objectlist+PolicyCheck.getFileKey(s3client, bucket, os.getKey(), expiration)+"\n";
objectlist = objectlist+PolicyCheck.getFileKey(s3client, bucket, os.getKey(), expiration, policy)+"\n";
}
}