A simple file sharing site with an easy to use API and online panel.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.6KB

  1. const angular = require('angular');
  2. angular.module('DashCtrl', ['chart.js', 'StatSvc']).controller('DashController', ['$scope', 'StatService', async ($scope, StatService) => {
  3. const colorScheme = ['#2a9fd6'];
  4. // Calculate and format descending dates back one week to use for x-axis labels
  5. const currentDate = new Date();
  6. const oneDay = 1000 * 60 * 60 * 24;
  7. let labels = Array.from({length: 7}, (date, i) =>
  8. (new Date(currentDate - oneDay * (6 - i))).toISOString().substr(5, 5));
  9. const toHumanReadable = bytes => {
  10. const units = ['B', 'KiB', 'MiB', 'GiB', 'TiB'];
  11. let index = 0;
  12. for(; bytes >= 1024 && index < units.length - 1; index++)
  13. bytes /= 1024;
  14. return bytes.toFixed(3) + ' ' + units[index];
  15. };
  16. // Get stats for the week
  17. $scope.statWeekUploads = 0;
  18. $scope.statWeekUploadSize = 0;
  19. $scope.statWeekViews = 0;
  20. const weekStats = await StatService.getWeek();
  21. console.log(weekStats);
  22. $scope.uploadData = [Array.from({length: 7}, (val, i) => weekStats[labels[i]] && weekStats[labels[i]].uploads ? weekStats[labels[i]].uploads : 0)];
  23. $scope.viewData = [Array.from({length: 7}, (val, i) => weekStats[labels[i]] && weekStats[labels[i]].views ? weekStats[labels[i]].views : 0)];
  24. $scope.statWeekUploads = Object.keys(weekStats).reduce((acc, key) => acc + (weekStats[key].uploads ? weekStats[key].uploads : 0), 0);
  25. $scope.statWeekUploadSize = toHumanReadable(Object.keys(weekStats).reduce((acc, key) => acc + (weekStats[key].size ? weekStats[key].size : 0), 0));
  26. $scope.statWeekViews = Object.keys(weekStats).reduce((acc, key) => acc + (weekStats[key].views ? weekStats[key].views : 0), 0);
  27. // Get all-time stats
  28. $scope.statTotalUploads = 0;
  29. $scope.statTotalUploadSize = 0;
  30. $scope.statTotalViews = 0;
  31. const allStats = await StatService.getAll();
  32. console.log(allStats);
  33. $scope.statTotalUploads = allStats.count;
  34. $scope.statTotalUploadSize = toHumanReadable(allStats.size);
  35. $scope.statTotalViews = allStats.views;
  36. $scope.uploadColors = colorScheme;
  37. $scope.uploadLabels = labels;
  38. $scope.uploadSeries = ['Uploads'];
  39. //$scope.uploadData = [[5, 11, 4, 3, 7, 9, 21]];
  40. $scope.uploadOptions = {
  41. title: {
  42. display: true,
  43. text: 'Historical Uploads'
  44. },
  45. };
  46. $scope.viewColors = colorScheme;
  47. $scope.viewLabels = labels;
  48. $scope.viewSeries = ['Views'];
  49. //$scope.viewData = [[5, 11, 4, 3, 7, 9, 21]];
  50. $scope.viewOptions = {
  51. title: {
  52. display: true,
  53. text: 'Historical Views'
  54. }
  55. };
  56. }]);