diff --git a/backend/masz/Controllers/api/v1/AdminStatsController.cs b/backend/masz/Controllers/api/v1/AdminStatsController.cs index 56dcd19c6..c1fa5044c 100644 --- a/backend/masz/Controllers/api/v1/AdminStatsController.cs +++ b/backend/masz/Controllers/api/v1/AdminStatsController.cs @@ -63,5 +63,21 @@ public async Task Status() { cachedDataFromDiscord = cache.Keys }); } + + [HttpPost("cache")] + public async Task TriggerCache() { + logger.LogInformation($"{HttpContext.Request.Method} {HttpContext.Request.Path} | Incoming request."); + if (! await this.IsSiteAdmin()) { + logger.LogInformation($"{HttpContext.Request.Method} {HttpContext.Request.Path} | 401 Unauthorized."); + return Unauthorized(); + } + + Task task = new Task(() => { + this.cacher.CacheAll(); + }); + task.Start(); + + return Ok(); + } } } \ No newline at end of file diff --git a/backend/masz/Services/Implementations/PunishmentHandler.cs b/backend/masz/Services/Implementations/PunishmentHandler.cs index a89f473b5..71c7330db 100644 --- a/backend/masz/Services/Implementations/PunishmentHandler.cs +++ b/backend/masz/Services/Implementations/PunishmentHandler.cs @@ -37,7 +37,7 @@ public void StartTimer() Thread.Sleep(1000 * 60); } }); - task.Start(); + task.Start(); logger.LogWarning("Finished action loop."); } diff --git a/docs/discord-masz.postman_collection.json b/docs/discord-masz.postman_collection.json index 5ee6f84d4..8d56bbcde 100644 --- a/docs/discord-masz.postman_collection.json +++ b/docs/discord-masz.postman_collection.json @@ -1,6 +1,6 @@ { "info": { - "_postman_id": "b4f361ca-1687-49f0-a9d9-672384917577", + "_postman_id": "2b26a0ad-43ae-4279-9f65-7298cf76f29c", "name": "discord-masz", "description": "# Introduction\nWhat does your API do?\n\n# Overview\nThings that the developers should know about\n\n# Authentication\nWhat is the preferred way of using the API?\n\n# Error Codes\nWhat errors and status codes can a user expect?\n\n# Rate limit\nIs there a limit to the number of requests an user can send?", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" @@ -25,6 +25,12 @@ { "key": "Cookie", "value": "masz_access_token={{masz_access_token}}", + "type": "text", + "disabled": true + }, + { + "key": "Authorization", + "value": "Bearer {{masz_api_token}}", "type": "text" } ], @@ -674,8 +680,7 @@ "variable": [ { "key": "caseid", - "value": "1", - "type": "string" + "value": "1" } ] } @@ -788,8 +793,7 @@ }, { "key": "dataname", - "value": "680e67b0d3528da5c1c10bc5b6db33520f4a2db5_7d2801f2_bobtreffen.png", - "type": "string" + "value": "680e67b0d3528da5c1c10bc5b6db33520f4a2db5_7d2801f2_bobtreffen.png" } ] } @@ -899,8 +903,7 @@ "variable": [ { "key": "dataname", - "value": "680e67b0d3528da5c1c10bc5b6db33520f4a2db5_7d2801f2_bobtreffen.png", - "type": "string" + "value": "680e67b0d3528da5c1c10bc5b6db33520f4a2db5_7d2801f2_bobtreffen.png" } ] } @@ -921,6 +924,11 @@ "key": "Cookie", "value": "masz_access_token={{masz_access_token}}", "type": "text" + }, + { + "key": "Authorization", + "value": "Bearer {{masz_api_token}}", + "type": "text" } ], "url": { @@ -947,6 +955,12 @@ { "key": "Cookie", "value": "masz_access_token={{masz_access_token}}", + "type": "text", + "disabled": true + }, + { + "key": "Authorization", + "value": "Bearer {{masz_api_token}}", "type": "text" } ], @@ -965,8 +979,7 @@ "variable": [ { "key": "userid", - "value": "749886323380453438", - "type": "string" + "value": "272655001329991681" } ] } @@ -1338,8 +1351,7 @@ "variable": [ { "key": "type", - "value": "0", - "type": "string" + "value": "0" } ] } @@ -1373,8 +1385,7 @@ "variable": [ { "key": "type", - "value": "0", - "type": "string" + "value": "0" } ] } @@ -1453,8 +1464,7 @@ "variable": [ { "key": "id", - "value": "9", - "type": "string" + "value": "9" } ] } @@ -1486,8 +1496,7 @@ "variable": [ { "key": "id", - "value": "1", - "type": "string" + "value": "1" } ] } @@ -1909,7 +1918,7 @@ "variable": [ { "key": "userid", - "value": "12" + "value": "272655001329991681" } ] } @@ -2304,6 +2313,73 @@ "response": [] } ] + }, + { + "name": "admin", + "item": [ + { + "name": "adminstats", + "request": { + "method": "GET", + "header": [ + { + "key": "Accept", + "value": "application/json", + "type": "text" + }, + { + "key": "Cookie", + "value": "masz_access_token={{masz_access_token}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/api/v1/meta/adminstats", + "host": [ + "{{url}}" + ], + "path": [ + "api", + "v1", + "meta", + "adminstats" + ] + } + }, + "response": [] + }, + { + "name": "trigger recache", + "request": { + "method": "POST", + "header": [ + { + "key": "Accept", + "value": "application/json", + "type": "text" + }, + { + "key": "Cookie", + "value": "masz_access_token={{masz_access_token}}", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/api/v1/meta/cache", + "host": [ + "{{url}}" + ], + "path": [ + "api", + "v1", + "meta", + "cache" + ] + } + }, + "response": [] + } + ] } ], "description": "api v1\r\n" diff --git a/nginx/MASZ/src/app/components/api/adminstats/adminlist/adminlist.component.html b/nginx/MASZ/src/app/components/api/adminstats/adminlist/adminlist.component.html index 17e6d2ed2..ed80c2a4e 100644 --- a/nginx/MASZ/src/app/components/api/adminstats/adminlist/adminlist.component.html +++ b/nginx/MASZ/src/app/components/api/adminstats/adminlist/adminlist.component.html @@ -31,11 +31,11 @@ error_outline -
No logins found.
+
{{ errorMessage }}
diff --git a/nginx/MASZ/src/app/components/api/adminstats/adminlist/adminlist.component.ts b/nginx/MASZ/src/app/components/api/adminstats/adminlist/adminlist.component.ts index 11f15ef34..d86943c77 100644 --- a/nginx/MASZ/src/app/components/api/adminstats/adminlist/adminlist.component.ts +++ b/nginx/MASZ/src/app/components/api/adminstats/adminlist/adminlist.component.ts @@ -11,6 +11,7 @@ export class AdminlistComponent implements OnInit { @Input() public showList: string[] | undefined = [] @Input() public loading: boolean = true; @Input() public emote: string = "person"; + @Input() public errorMessage: string = "No logins found."; public showAll: boolean = false; constructor() { } diff --git a/nginx/MASZ/src/app/components/api/adminstats/adminstats.component.html b/nginx/MASZ/src/app/components/api/adminstats/adminstats.component.html index f4b773d29..24819e87b 100644 --- a/nginx/MASZ/src/app/components/api/adminstats/adminstats.component.html +++ b/nginx/MASZ/src/app/components/api/adminstats/adminstats.component.html @@ -1,7 +1,13 @@
-
Insights
+
Insights
+
+ +
+ [emote]="'save'" + [errorMessage]="'No cached data found.'">
\ No newline at end of file diff --git a/nginx/MASZ/src/app/components/api/adminstats/adminstats.component.ts b/nginx/MASZ/src/app/components/api/adminstats/adminstats.component.ts index d5631c6a5..db67c5c39 100644 --- a/nginx/MASZ/src/app/components/api/adminstats/adminstats.component.ts +++ b/nginx/MASZ/src/app/components/api/adminstats/adminstats.component.ts @@ -1,9 +1,11 @@ import { Component, OnInit } from '@angular/core'; +import { MatDialog } from '@angular/material/dialog'; import { ToastrService } from 'ngx-toastr'; import { interval } from 'rxjs'; import { Adminstats } from 'src/app/models/Adminstats'; import { ContentLoading } from 'src/app/models/ContentLoading'; import { ApiService } from 'src/app/services/api.service'; +import { ConfirmationDialogComponent } from '../../dialogs/confirmation-dialog/confirmation-dialog.component'; @Component({ selector: 'app-adminstats', @@ -18,7 +20,7 @@ export class AdminstatsComponent implements OnInit { public minutesToNewCache?: string = '--'; public stats: ContentLoading = { loading: true, content: undefined }; - constructor(private api: ApiService, private toastr: ToastrService) { } + constructor(private api: ApiService, private toastr: ToastrService, private dialog: MatDialog) { } ngOnInit(): void { this.reload(); @@ -52,5 +54,23 @@ export class AdminstatsComponent implements OnInit { ngOnDestroy() { this.subscription?.unsubscribe(); - } + } + + public triggerCache() { + const confirmDialogRef = this.dialog.open(ConfirmationDialogComponent); + confirmDialogRef.afterClosed().subscribe(confirmed => { + if (confirmed) { + this.api.postSimpleData(`/meta/cache`, {}).subscribe((data) => { + this.stats = { loading: true, content: undefined }; + this.toastr.success("Cache cleared."); + setTimeout(() => { + this.reload(); + }, 2000); + }, (error) => { + this.toastr.error("Something went wrong."); + console.error(error); + }); + } + }); + } } diff --git a/nginx/static/patchnotes.json b/nginx/static/patchnotes.json index 35ebbee19..9f554586e 100644 --- a/nginx/static/patchnotes.json +++ b/nginx/static/patchnotes.json @@ -1,4 +1,12 @@ [ + { + "title": "Version 1.11.6", + "version": "v1.11.6", + "changes": [ + "Added a clear cache button in the insights dashboard.", + "Adjusted some error messages to be clearer." + ] + }, { "title": "Version 1.11.5", "version": "v1.11.5", diff --git a/nginx/static/version.json b/nginx/static/version.json index ee6a4b2c4..6a86ef6aa 100644 --- a/nginx/static/version.json +++ b/nginx/static/version.json @@ -1,4 +1,4 @@ { - "version": "v1.11.5", + "version": "v1.11.6", "pre_release": false }