forked from waifuvault/WaifuVault
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7380eb2
commit 1c93c84
Showing
26 changed files
with
890 additions
and
716 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { PlatformResponse } from "@tsed/common"; | ||
import type { DatatableColumn, DatatableOrder, DatatableSearch } from "../../utils/typeings.js"; | ||
|
||
export interface IAdminController { | ||
getAllEntries(): Promise<unknown>; | ||
|
||
deleteEntries(res: PlatformResponse, ids: number[]): Promise<unknown>; | ||
|
||
getStatsData(): Promise<unknown>; | ||
|
||
getDatatablesEntries( | ||
draw: number, | ||
start: number, | ||
length: number, | ||
order: DatatableOrder[], | ||
columns: DatatableColumn[], | ||
search: DatatableSearch, | ||
): Promise<unknown>; | ||
} |
36 changes: 36 additions & 0 deletions
36
src/controllers/rest/impl/security/AbstractAdminController.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { PlatformResponse } from "@tsed/common"; | ||
import { NotFound } from "@tsed/exceptions"; | ||
import type { DatatableColumn, DatatableOrder, DatatableSearch } from "../../../../utils/typeings.js"; | ||
import { IAdminService } from "../../../../services/IAdminService.js"; | ||
import { BaseRestController } from "../../BaseRestController.js"; | ||
|
||
export abstract class AbstractAdminController extends BaseRestController { | ||
protected constructor(protected adminService: IAdminService) { | ||
super(); | ||
} | ||
|
||
public getAllEntries(): Promise<unknown> { | ||
return this.adminService.getAllEntries(); | ||
} | ||
|
||
public async deleteEntries(res: PlatformResponse, ids: number[]): Promise<unknown> { | ||
const result = await this.adminService.deleteEntries(ids); | ||
if (!result) { | ||
throw new NotFound(`No entry with IDs ${ids.join(", ")} found.`); | ||
} | ||
return super.doSuccess(res, `Entries have been deleted.`); | ||
} | ||
|
||
public getStatsData(): Promise<unknown> { | ||
return this.adminService.getStatsData(); | ||
} | ||
|
||
public abstract getDatatablesEntries( | ||
draw: number, | ||
start: number, | ||
length: number, | ||
order: DatatableOrder[], | ||
columns: DatatableColumn[], | ||
search: DatatableSearch, | ||
): Promise<unknown>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/controllers/rest/impl/security/BucketAdminController.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { AbstractAdminController } from "./AbstractAdminController.js"; | ||
import { Controller, Inject } from "@tsed/di"; | ||
import { Delete, Get, Hidden } from "@tsed/schema"; | ||
import { PlatformResponse, QueryParams, Res, UseBefore } from "@tsed/common"; | ||
import type { DatatableColumn, DatatableOrder, DatatableSearch } from "../../../../utils/typeings.js"; | ||
import { AuthoriseBucket } from "../../../../middleware/endpoint/AuthoriseBucket.js"; | ||
import { BodyParams } from "@tsed/platform-params"; | ||
import { IAdminController } from "../../IAdminController.js"; | ||
import { BucketAdminService } from "../../../../services/BucketAdminService.js"; | ||
import { BucketService } from "../../../../services/BucketService.js"; | ||
|
||
@Hidden() | ||
@Controller("/admin/bucket") | ||
@UseBefore(AuthoriseBucket) | ||
export class BucketAdminController extends AbstractAdminController implements IAdminController { | ||
public constructor( | ||
@Inject() private bucketAdminService: BucketAdminService, | ||
@Inject() private bucketService: BucketService, | ||
) { | ||
super(bucketAdminService); | ||
} | ||
|
||
@Get("/datatablesEntries") | ||
public override async getDatatablesEntries( | ||
@QueryParams("draw") draw: number, | ||
@QueryParams("start") start: number, | ||
@QueryParams("length") length: number, | ||
@QueryParams("order") order: DatatableOrder[], | ||
@QueryParams("columns") columns: DatatableColumn[], | ||
@QueryParams("search") search: DatatableSearch, | ||
): Promise<unknown> { | ||
let sortColumn; | ||
let sortOrder; | ||
const searchVal = search ? search.value : undefined; | ||
if (order && columns) { | ||
sortOrder = order[0]?.dir.toUpperCase(); | ||
sortColumn = columns[order[0]?.column ?? 0]?.data; | ||
} | ||
const bucket = await this.bucketService.getBucket(); | ||
const bucketToken = bucket!.bucketToken; | ||
const data = await this.bucketAdminService.getPagedEntries( | ||
start, | ||
length, | ||
sortColumn, | ||
sortOrder, | ||
bucketToken, | ||
searchVal, | ||
); | ||
const records = searchVal | ||
? await this.bucketAdminService.getFileSearchRecordCount(search.value, bucketToken) | ||
: await this.bucketAdminService.getFileRecordCount(bucketToken); | ||
return { | ||
draw: draw, | ||
recordsTotal: records, | ||
recordsFiltered: records, | ||
data: data, | ||
}; | ||
} | ||
|
||
@Get("/allEntries") | ||
public override getAllEntries(): Promise<unknown> { | ||
return super.getAllEntries(); | ||
} | ||
|
||
@Delete("/deleteEntries") | ||
public override deleteEntries(@Res() res: PlatformResponse, @BodyParams() ids: number[]): Promise<unknown> { | ||
return super.deleteEntries(res, ids); | ||
} | ||
|
||
@Get("/statsData") | ||
public override getStatsData(): Promise<unknown> { | ||
return super.getStatsData(); | ||
} | ||
} |
Oops, something went wrong.