Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make the filename on system default in table #158

Merged
merged 2 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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