How can I do it a upload limit per day?

I’m making a system that uses the upload button, but I want to avoid members using the upload and filling the site, is there any way to make users limited by upload per day?
or create a timer to disable a box for a certain time?

Perhaps this one might help you…

https://russian-dima.wixsite.com/meinewebsite/date-time-onclick

russia i have a question, how does the code line work for seconds, minutes, hours, days.
I want to put this code below, with which when clicking the button it disable the button, and after 10 seconds it enable the button, as a test.

export function button160_click(event) {
    setInterval(Timer, 1000); // loop to check date

 const today = new Date(); // get date
 const currentItem = $w('#dataset1').getCurrentItem();

    $w('#dataset1').setFieldValue("ButtonlastPressed", today); // save actual date

 let currentTime = today.toLocaleTimeString()

    $w('#input1').value = currentTime
    $w("#dataset1").save(); //save dataset // actual time

 function Timer() { // loop to check date
 if (currentItem.ButtonlastPressed > '10 Seconds') {
            $w('#button160').enable();
        } else {
            $w('#button160').disable();
        }
    }
}

To disable a button for 10-seconds, you also could use for example …

$w.onReady(function () {
    $w('#button1').onClick(()=>{
        $w('#button2').hide()
        setTimeout(function() {$w('#button2').show('fade'); }, 10000);
    })
})
  1. Create 2x-buttons (ID =#button1 and #button2.
  2. Put in this code.
  3. Test it :wink:

1000Milliseconds = 1-second

Calculate the waiting time as you want (10006060) = 1-hour
(10006060*24) = 1-day
and so on…

Good-Luck and happy coding.

Perhaps also take a look here…
https://russian-dima.wixsite.com/meinewebsite/test-1

yes, i know about the timeout (function), but if the member restarts the page he can simply circumvent it, right?
my idea is to limit the upload of one user per day.

for that I think about saving a current user data in his own database as “ButtonlastPressed” in date and time format.

then a loop to detect the current time and see if a (specific time) has passed:

function Timer() { // loop to check date
 if (currentItem.ButtonlastPressed > '10 Seconds') {
            $w('#button160').enable();
        } else {
            $w('#button160').disable();
        }

it saves the date information perfectly, but it is not updating.

as a test I put “10S” (10 seconds)
but when this time is exceeded the button is not active.

the reason I avoid wix-storage [local, session, etc]
it is because when the page cache is cleared, it also erases the saved data.

and with setTimeOut (function)
the user would have to wait with the page open 1 day for the button to activate, but he can restart the page and the button will be active again, and he will end up making another upload.

Yes you are right and you are on the right way.

You will need a combination of the following examples…

  1. https://russian-dima.wixsite.com/meinewebsite/oneway-ticket
    2) https://russian-dima.wixsite.com/meinewebsite/date-time-onclick
    3) https://russian-dima.wixsite.com/meinewebsite/onetime-popup

Example 3 shows exactly what will not work 100% because, when you close the site completely and reopen it, it lost the saved data (as you described it).

Yes, i think it will be nessaccery to save data for each user into a database and set a TIMER. How to make a timer, you will find in example-2

//Set-Timer / Check-Alarm
export function BTNsetTimer_click(event) {
    myTimer = $w('#input1').value
    console.log(myTimer)
    $w('#input2').value = myTimer
}
​
export function BTNcheckTime_click(event) {
    const today = new Date();
    let currentTime = today.toLocaleTimeString()
    if (currentTime<=myTimer) {
        console.log("NO-ALARM")
        $w('#TXTwindow').text = "NO-ALARM"
    } else {
        console.log("ALARM")
        $w('#TXTwindow').text = "ALARM"
    }
}

Try example-2 and test the ALARM-function. This could be the key to your solution.

I couldn’t do it at all, that’s fine.

@p3tri1ell0
Ok, i will try to make an example, but you have to wait. Totaly overload at moment :grin:

@p3tri1ell0

https://www.media-junkie.com/one-time-download

And here the relevant code-part…

export function BTNgetData_click(event) {
 const NOW = new Date();
    console.log(NOW)
    $w('#TXTdata').text=NOW.toString()
    $w('#TXTcodeData').text = "const NOW = new Date(); NOW.toString() console.log(NOW)"
}

export function BTNgetDate_click(event) {
 const NOW = new Date();
    console.log(NOW)
    $w('#TXTdate').text=NOW.toDateString()
    $w('#TXTcodeDate').text = "const NOW = new Date(); NOW.toDateString() console.log(NOW)"
}

export function BTNgetDateLocale_click(event) {
 const NOW = new Date();
    console.log(NOW)
    $w('#TXTdate').text=NOW.toLocaleDateString()
    console.log("LocaleDateString = " + NOW.toLocaleDateString());
    $w('#TXTcodeDate').text = "const NOW = new Date(); NOW.toLocaleDateString() console.log(NOW)"
}

export function BTNgetTime_click(event) {
 const NOW = new Date();
    console.log(NOW)
    $w('#TXTtime').text=NOW.toLocaleTimeString()
    console.log("LocaleDateString = " + NOW.toLocaleTimeString());
    $w('#TXTcodeTime').text = "const NOW = new Date(); NOW.toTimeString() console.log(NOW)"
}

export function BTNsplitTime_click(event) {
 const NOW = new Date();
 let timeValue = NOW.toLocaleTimeString()
    console.log("timeValue = " + timeValue)
 let SPLITTER = timeValue.split(":");
    console.log("SPLITTER = " + SPLITTER)
 let HOURS = Number(SPLITTER[0]);
    console.log("HOURS = " + HOURS)
 let MINUTES = Number(SPLITTER[1]);
    console.log("MINUTES = " + MINUTES)
 let SECONDS = Number(SPLITTER[2]);
    console.log("SECONDS = " + MINUTES)

    $w('#TXThours').text = HOURS.toString()
    $w('#TXTminutes').text = MINUTES.toString()
    $w('#TXTseconds').text = SECONDS.toString()
}

Now you should be able to complete the rest.

Your steps would be…

  1. create a “download-database” (data-collection)
    a) currentDATE b) currentTIME c) estimated-time d) USER and so on…
  2. When click on a download-button, you save DATE and TIME in your DB of every USER and every DOWNLOAD.
  3. Calculate for example (+ 30min) to the current Time on top. And save it in a seperate field in your DATABASE.

Let us say i am the USER who wants to download from your site.
Now i am clicking onto that button —> a cheking-process starts and checks if it is already time and permission to download again.

I hope you understand now, how to get your solution.

My example is still not ready, but you should see the way how to handle your problem.

@russian-dima thanks, i will try again soon

@russian-dima done

I managed to do a test but still need to clean the code and simplify some things.
further down there is a demo video

export function button2_click(event) { // button function
    $w("#button2").disable(); // disable button
 const today = new Date();
 let currentTime = today.toLocaleTimeString()
 //
    today.setSeconds(today.getSeconds() + 10);

    $w('#dataset1').setFieldValue("ButtonlastPressed", today); // save actual date
    $w("#dataset1").save(); // save data
 //

}

export function dataset1_afterSave() {
    $w("#button2").disable(); // disable button
 let Datatimer = $w("#dataset1").getCurrentItem()["ButtonlastPressed"] // get time saved
    console.log(Datatimer) 
    $w("#input3").value = Datatimer.toLocaleTimeString() // show time
    setInterval(Timercheck_data, 1000); // loop to check date

}

export function dataset1_ready() {
 let Datatimer = $w("#dataset1").getCurrentItem()["ButtonlastPressed"] // get time saved
    $w("#input3").value = Datatimer.toLocaleTimeString()  // show time
 if (("#input3").value !== "") {
        setInterval(Timercheck_data, 1000); // loop to check date
    }
}

function Timercheck_data() {
 let Datatimer = $w("#dataset1").getCurrentItem()["ButtonlastPressed"] // get time saved
 var countDownDate = Datatimer // Countdown date and time

 const today = new Date();
    $w("#input5").value = today.toLocaleTimeString() // show current time

 var x = setInterval(function () {
 var now = new Date().getTime();
 var distance = countDownDate - now;
 var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
 var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
 var seconds = Math.floor((distance % (1000 * 60)) / 1000);

        $w("#input4").value = hours + "h " + minutes + "m " + seconds + "s "; // show time left in hh/mm/ss

 if (distance < 0) {
            clearInterval(x);
            $w("#button2").enable();
        } else {
            $w("#button2").disable();
        }
    }, 1000);

}

@p3tri1ell0
Well done. You improve your coding skills! Very good!
The best way of learning?
Yes!
Learning by doing :wink: