diff --git a/res/include/script/user_home.js b/res/include/script/user_home.js index e986b8a..5f91752 100644 --- a/res/include/script/user_home.js +++ b/res/include/script/user_home.js @@ -1,24 +1,24 @@ -function loadGraph(graph, stat, minutes, interval){ +function loadGraph(graph, stat, minutes, interval) { let today = new Date() let start = new Date() - start.setMinutes(start.getMinutes()-minutes) + start.setMinutes(start.getMinutes() - minutes) fetch( - apiEndpoint+"/user/time_series/" + stat + - "?start="+start.toISOString() + - "&end="+today.toISOString() + - "&interval="+interval + apiEndpoint + "/user/time_series/" + stat + + "?start=" + start.toISOString() + + "&end=" + today.toISOString() + + "&interval=" + interval ).then(resp => { - if (!resp.ok) { return Promise.reject("Error: "+resp.status);} + if (!resp.ok) { return Promise.reject("Error: " + resp.status); } return resp.json(); }).then(resp => { resp.timestamps.forEach((val, idx) => { let date = new Date(val); - let dateStr = ("00"+(date.getMonth()+1)).slice(-2); - dateStr += "-"+("00"+date.getDate()).slice(-2); - dateStr += " "+("00"+date.getHours()).slice(-2); - dateStr += ":"+("00"+date.getMinutes()).slice(-2); - resp.timestamps[idx] = " "+dateStr+" "; // Poor man's padding + let dateStr = ("00" + (date.getMonth() + 1)).slice(-2); + dateStr += "-" + ("00" + date.getDate()).slice(-2); + dateStr += " " + ("00" + date.getHours()).slice(-2); + dateStr += ":" + ("00" + date.getMinutes()).slice(-2); + resp.timestamps[idx] = " " + dateStr + " "; // Poor man's padding }); graph.data.labels = resp.timestamps; graph.data.datasets[0].data = resp.amounts; @@ -35,27 +35,53 @@ function loadGraph(graph, stat, minutes, interval){ document.getElementById("total_downloads").innerText = formatThousands(total); } else if (stat == "bandwidth") { document.getElementById("total_bandwidth").innerText = formatDataVolume(total, 3); + } else if (stat == "direct_bandwidth") { + document.getElementById("total_direct_bandwidth").innerText = formatDataVolume(total, 3); } }).catch(e => { - console.error("Error requesting time series: "+e); + console.error("Error requesting time series: " + e); + }) +} + +function loadDirectBW() { + let today = new Date() + let start = new Date() + start.setDate(start.getDate() - 30) + + fetch( + apiEndpoint + "/user/time_series/direct_bandwidth" + + "?start=" + start.toISOString() + + "&end=" + today.toISOString() + + "&interval=60" + ).then(resp => { + if (!resp.ok) { return Promise.reject("Error: " + resp.status); } + return resp.json(); + }).then(resp => { + let total = resp.amounts.reduce((accum, val) => accum += val, 0); + document.getElementById("direct_bandwidth_month").innerText = formatDataVolume(total, 4) + }).catch(e => { + console.error("Error requesting time series: " + e); }) } let graphViews = drawGraph(document.getElementById("views_chart"), "Views", "number"); let graphDownloads = drawGraph(document.getElementById("downloads_chart"), "Downloads", "number"); let graphBandwidth = drawGraph(document.getElementById("bandwidth_chart"), "Bandwidth", "bytes"); +let graphDirectBandwidth = drawGraph(document.getElementById("direct_bandwidth_chart"), "Direct Bandwidth", "bytes"); let graphTimeout = null; function updateGraphs(minutes, interval, live) { if (graphTimeout !== null) { clearTimeout(graphTimeout) } if (live) { - graphTimeout = setTimeout(() => {updateGraphs(minutes, interval, true)}, 10000) + graphTimeout = setTimeout(() => { updateGraphs(minutes, interval, true) }, 10000) } loadGraph(graphViews, "views", minutes, interval); loadGraph(graphDownloads, "downloads", minutes, interval); loadGraph(graphBandwidth, "bandwidth", minutes, interval); + loadGraph(graphDirectBandwidth, "direct_bandwidth", minutes, interval); + loadDirectBW() } // Default -updateGraphs(10080, 60, false); +updateGraphs(1440, 1, true); diff --git a/res/template/account/user_home.html b/res/template/account/user_home.html index d41f988..56c7a93 100644 --- a/res/template/account/user_home.html +++ b/res/template/account/user_home.html @@ -31,6 +31,11 @@
  • Files never expire
  • {{end}}
  • File size limit: {{formatData .User.Subscription.FileSizeLimit}}
  • +
  • + Direct linking bandwidth: + {{formatData .User.Subscription.DirectLinkingBandwidth}} + (0 B used in the last 30 days) +
  • @@ -44,14 +49,13 @@

    Here you can see how often your files are viewed, downloaded and how much bandwidth they consume. The buttons at the top - can be pressed to adjust the timeframe. If you choose 'Live' - or 'Day' the statistics will be updated periodically. No - need to refresh the page. + can be pressed to adjust the timeframe. If you choose 'Day' + the statistics will be updated periodically. No need to + refresh the page.

    - - + @@ -59,23 +63,63 @@
    -

    Views

    +
    +

    Views

    +

    + A view is counted when someone visits the download page of one + of your files. Views are unique per user per file. +

    +
    -

    Downloads

    +
    +

    Downloads

    +

    + Downloads are counted when a user clicks the download button + on one of your files. It does not matter whether the + download is completed or not, only the start of the download + is counted. +

    +
    -

    Bandwidth

    +
    +

    Bandwidth

    +

    + This is how much bandwidth your files are using in total. + Bandwidth is used when a file is tranferred from a + pixeldrain server to a user who is downloading the file. + When a 5 MB file is downloaded 8 times it has used 40 MB of + bandwidth. +

    +
    +
    +

    Direct link bandwidth

    +

    + When a file is downloaded without going through pixeldrain's + download page it counts as a direct download. Because direct + downloads cost us bandwidth and don't generate any ad + revenue we have to limit them. When your direct link + bandwidth runs out people will be asked to do a test before + they can download your files. See our + subscription options to get more direct + linking bandwidth. +

    +
    +
    + +
    Total usage from to
    views, - downloads and - bandwidth + downloads, + bandwidth and + direct link bandwidth
    diff --git a/webcontroller/file_viewer.go b/webcontroller/file_viewer.go index b7be6c3..148bec4 100644 --- a/webcontroller/file_viewer.go +++ b/webcontroller/file_viewer.go @@ -78,23 +78,19 @@ func (vd *viewerData) adType(files []pixelapi.ListFile) { // Intn returns a number up to n, but never n itself. So to get a random 0 // or 1 we need to give it n=2. We can use this function to make other // splits like 1/3 1/4, etc - switch i := rand.Intn(8); i { - case 0: // 12.5% + switch i := rand.Intn(4); i { + case 0: // 25% vd.AdBannerType = brave - case 1, 2, 3, 4, 5, 6, 7: // 87.5% + case 2, 3, 4: // 75% vd.AdBannerType = aAds default: panic(fmt.Errorf("random number generator returned unrecognised number: %d", i)) } - // If the file is larger than 10 MB we enable floating popups - if avgSize > 10e6 { + // If the file is larger than 5 MB we enable floating popups + if avgSize > 5e6 { vd.AdFloaterType = propellerFloat } - - if avgSize > 250e6 { - vd.AdPopupType = clickAduPopup - } } // ServeFileViewer controller for GET /u/:id