How do I limit Firebase Storage downloads to a certain maximum amount per time period per user?

1

I would like to know how I can limit the download demand in my application, 20 per hour ... I use firebase, no login, the only way I recognize a user and with id de anúncio do google the application only works with internet connection.

Update
If the client makes 10 downloads and returns after 1 hour, the ideal would be to zero the count.

Here is the code I use for download:

 if (Environment.getExternalStorageState().equals(
                    Environment.MEDIA_MOUNTED)) {

                final String STORAGE = mChat = getIntent().getExtras().getString("storage");

                progress = ProgressDialog.show(MinhaActivity.this, "Download...",
                        "Aguarde...", true);
                FirebaseStorage mStorage = FirebaseStorage.getInstance();
                StorageReference storageRef = mStorage.getReferenceFromUrl("MY_DB").child(STORAGE).child(down+".mp3");

                File sdCardDirectory = Environment.getExternalStorageDirectory();
                final File localFile = new File(sdCardDirectory.getPath()+"/Audio",down+".mp3");


                storageRef.getFile(localFile).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
                    @Override
                    public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
                        Toast.makeText(Minhactivity.this,"Salvo em "+localFile.getAbsolutePath(),Toast.LENGTH_LONG).show();
                        progress.dismiss();

                    }
                }).addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception exception) {
                    }
                });


            }else{
                Toast.makeText(MinhaActivity.this,"Você está sem Cartão de memória",Toast.LENGTH_LONG).show();
            }

        }
    });

Thank you for the attention of everyone involved right now!

    
asked by anonymous 28.11.2017 / 00:14

1 answer

1

You can have a list of users (in your case, ad ids) and, associated with each user, a list of timestamps of the times when each download was made.

Before initializing a download, grab the last 20 and see if everyone is within a two-hour interval (just subtract the most recent from the oldest and see if the interval is less than or equal to two hours). If they are, do not authorize the download. If they are not, add the current timestamp to the list and authorize the download.

    
28.11.2017 / 00:29