Skip to content

Commit

Permalink
Merge pull request #158 from waifuvault/ignore-expired-entries
Browse files Browse the repository at this point in the history
make the filename on system default in table
  • Loading branch information
VictoriqueMoe committed Jun 21, 2024
2 parents 5d841b2 + 7cbb9dc commit a19ced7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/controllers/rest/impl/security/AdminController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export class AdminController extends BaseRestController {
}

@Get("/statsData")
public async getStatsData(): Promise<unknown> {
return this.adminService.getStatsData(await this.adminService.getAllEntries());
public getStatsData(): Promise<unknown> {
return this.adminService.getStatsData();
}

@Get("/blockedIps")
Expand Down
22 changes: 19 additions & 3 deletions src/db/dao/FileDao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Inject, Injectable } from "@tsed/di";
import { AbstractDao } from "./AbstractDao.js";
import { FileUploadModel } from "../../model/db/FileUpload.model.js";
import { SQLITE_DATA_SOURCE } from "../../model/di/tokens.js";
import { DataSource, EntityManager, In, Like } from "typeorm";
import { DataSource, EntityManager, In, IsNull, Like, MoreThan } from "typeorm";
import { FindOperator } from "typeorm/find-options/FindOperator.js";

@Injectable()
Expand Down Expand Up @@ -44,7 +44,14 @@ export class FileDao extends AbstractDao<FileUploadModel> {
}

public getTotalFileSize(transaction?: EntityManager): Promise<number | null> {
return this.getRepository(transaction).sum("fileSize");
return this.getRepository(transaction).sum("fileSize", [
{
expires: IsNull(),
},
{
expires: MoreThan(Date.now()),
},
]);
}

public getAllEntriesOrdered(
Expand Down Expand Up @@ -78,7 +85,16 @@ export class FileDao extends AbstractDao<FileUploadModel> {
}

public getRecordCount(transaction?: EntityManager): Promise<number> {
return this.getRepository(transaction).count();
return this.getRepository(transaction).count({
where: [
{
expires: IsNull(),
},
{
expires: MoreThan(Date.now()),
},
],
});
}

public getSearchRecordCount(search: string, transaction?: EntityManager): Promise<number> {
Expand Down
7 changes: 4 additions & 3 deletions src/services/AdminService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ export class AdminService {
@Constant(GlobalEnv.BASE_URL)
private readonly baseUrl: string;

public getStatsData(entries: FileEntryDto[]): Promise<StatsDto> {
public async getStatsData(): Promise<StatsDto> {
const entries = await this.getAllEntries();
return StatsDto.buildStats(entries);
}

public async getAllEntries(): Promise<FileEntryDto[]> {
const allEntries = await this.repo.getAllEntries();
return this.buildFileEntryDtos(allEntries);
return this.buildFileEntryDtos(allEntries.filter(entry => !entry.hasExpired));
}

public async getPagedEntries(
Expand All @@ -37,7 +38,7 @@ export class AdminService {
search?: string,
): Promise<FileEntryDto[]> {
const entries = await this.repo.getAllEntriesOrdered(start, length, sortColumn, sortDir, search);
return this.buildFileEntryDtos(entries);
return this.buildFileEntryDtos(entries.filter(entry => !entry.hasExpired));
}

private async buildFileEntryDtos(entries: FileUploadModel[]): Promise<FileEntryDto[]> {
Expand Down

0 comments on commit a19ced7

Please sign in to comment.