Compare commits
No commits in common. "e03d16bdb4b6fa274f599bd0954504f03617085b" and "56df921a9b8bb988f226beb56cfbae012f2e9b6e" have entirely different histories.
e03d16bdb4
...
56df921a9b
@ -73,6 +73,12 @@ export const FilesTable = pgTable("files", {
|
|||||||
})
|
})
|
||||||
.notNull(),
|
.notNull(),
|
||||||
|
|
||||||
|
uploader: p
|
||||||
|
.varchar("uploader", {
|
||||||
|
length: 64,
|
||||||
|
})
|
||||||
|
.notNull(),
|
||||||
|
|
||||||
groupId: p.uuid("group_id").references(() => FilesGroupTable.uuid),
|
groupId: p.uuid("group_id").references(() => FilesGroupTable.uuid),
|
||||||
|
|
||||||
fileSize: p.integer("file_size").notNull(),
|
fileSize: p.integer("file_size").notNull(),
|
||||||
|
@ -1,19 +1,7 @@
|
|||||||
import { Controller, Get, Param, Post, StreamableFile } from '@nestjs/common';
|
import { Controller } from "@nestjs/common";
|
||||||
import { FilesService } from "./files.service";
|
import { FilesService } from "./files.service";
|
||||||
|
|
||||||
@Controller("files")
|
@Controller("files")
|
||||||
export class FilesController {
|
export class FilesController {
|
||||||
constructor(private readonly filesService: FilesService) {}
|
constructor(private readonly filesService: FilesService) {}
|
||||||
|
|
||||||
//TODO POST FILE
|
|
||||||
@Post('new')
|
|
||||||
async saveFile() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get(':fileId')
|
|
||||||
async getFile(@Param('fileId') fileId: string) {
|
|
||||||
return this.filesService.get(fileId);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import { Injectable, NotFoundException, StreamableFile } from '@nestjs/common';
|
import { Injectable, NotFoundException, StreamableFile } from "@nestjs/common";
|
||||||
import { DbService } from 'apps/backend/src/app/db/db.service';
|
import { DbService } from "apps/backend/src/app/db/db.service";
|
||||||
import { FilesTable } from 'apps/backend/src/app/db/schema';
|
import { FilesTable } from "apps/backend/src/app/db/schema";
|
||||||
import { StorageService } from 'apps/backend/src/app/storage/storage.service';
|
import { StorageService } from "apps/backend/src/app/storage/storage.service";
|
||||||
import { eq } from 'drizzle-orm';
|
import { IFileWithInformation } from "apps/backend/src/app/storage/storage.types";
|
||||||
|
import { eq } from "drizzle-orm";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class FilesService {
|
export class FilesService {
|
||||||
@ -19,7 +19,7 @@ export class FilesService {
|
|||||||
* @return A promise that resolves to an object containing the streamable file and additional file information.
|
* @return A promise that resolves to an object containing the streamable file and additional file information.
|
||||||
* @throws NotFoundException if the file does not exist in the database.
|
* @throws NotFoundException if the file does not exist in the database.
|
||||||
*/
|
*/
|
||||||
public async get(fileId: string): Promise<StreamableFile> {
|
public async get(fileId: string): Promise<IFileWithInformation<object>> {
|
||||||
const foundFiles = await this.database
|
const foundFiles = await this.database
|
||||||
.use()
|
.use()
|
||||||
.select()
|
.select()
|
||||||
@ -44,21 +44,20 @@ export class FilesService {
|
|||||||
file.extension,
|
file.extension,
|
||||||
file.isDocumentation,
|
file.isDocumentation,
|
||||||
);
|
);
|
||||||
|
const streamableFile = new StreamableFile(fileBuffer);
|
||||||
const fileInformation = await this.storage.generateInformation(
|
const fileInformation = await this.storage.generateInformation(
|
||||||
fileBuffer,
|
fileBuffer,
|
||||||
file.fileName,
|
file.fileName,
|
||||||
file.isDocumentation,
|
file.isDocumentation,
|
||||||
);
|
);
|
||||||
const fileNameWithoutSpaces = file.fileName.replace(/\s/g, "_");
|
|
||||||
return new StreamableFile(fileBuffer, {
|
|
||||||
disposition: `attachment; filename="${fileNameWithoutSpaces}.${fileInformation.fileType.ext.toLowerCase()}"`
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO list the files
|
|
||||||
|
|
||||||
//TODO save a file
|
|
||||||
public async set() {
|
|
||||||
|
|
||||||
|
return {
|
||||||
|
stream: streamableFile,
|
||||||
|
info: fileInformation,
|
||||||
|
additionalData: {
|
||||||
|
//Since we can have twice or more entry in the database for the same checksum of a file.
|
||||||
|
foundEntry: foundFiles.length,
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import {
|
import {
|
||||||
Body,
|
|
||||||
Controller,
|
Controller,
|
||||||
DefaultValuePipe,
|
DefaultValuePipe,
|
||||||
Delete,
|
Delete,
|
||||||
@ -7,11 +6,10 @@ import {
|
|||||||
Param,
|
Param,
|
||||||
ParseIntPipe,
|
ParseIntPipe,
|
||||||
Post,
|
Post,
|
||||||
Query
|
Query,
|
||||||
} from '@nestjs/common';
|
} from "@nestjs/common";
|
||||||
import { ISearchQuery } from "apps/backend/src/app/groups/groups.types";
|
import { ISearchQuery } from "apps/backend/src/app/groups/groups.types";
|
||||||
import { GroupsService } from "./groups.service";
|
import { GroupsService } from "./groups.service";
|
||||||
import { CreateGroupDto } from 'apps/backend/src/app/groups/groups.dto';
|
|
||||||
|
|
||||||
@Controller("groups")
|
@Controller("groups")
|
||||||
export class GroupsController {
|
export class GroupsController {
|
||||||
@ -24,14 +22,12 @@ export class GroupsController {
|
|||||||
@Query("offset", new DefaultValuePipe(0), ParseIntPipe) offset: number,
|
@Query("offset", new DefaultValuePipe(0), ParseIntPipe) offset: number,
|
||||||
@Query("search", new DefaultValuePipe("")) search: string,
|
@Query("search", new DefaultValuePipe("")) search: string,
|
||||||
) {
|
) {
|
||||||
//TODO add service method
|
const query = { limit, offset, search };
|
||||||
}
|
}
|
||||||
|
|
||||||
//POST a new group
|
//POST a new group
|
||||||
@Post("new")
|
@Post("new")
|
||||||
async newGroup(@Body() dto : CreateGroupDto) {
|
async newGroup() {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//DELETE a group
|
//DELETE a group
|
||||||
@Delete(":groupId")
|
@Delete(":groupId")
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
import { IsString, MinLength, MaxLength } from 'class-validator';
|
|
||||||
|
|
||||||
export class CreateGroupDto {
|
|
||||||
@IsString()
|
|
||||||
@MinLength(4)
|
|
||||||
@MaxLength(64)
|
|
||||||
groupName: string;
|
|
||||||
}
|
|
@ -1,10 +1,8 @@
|
|||||||
import { Module } from "@nestjs/common";
|
import { Module } from "@nestjs/common";
|
||||||
import { GroupsController } from "./groups.controller";
|
import { GroupsController } from "./groups.controller";
|
||||||
import { GroupsService } from "./groups.service";
|
import { GroupsService } from "./groups.service";
|
||||||
import { DbModule } from '../db/db.module';
|
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [DbModule],
|
|
||||||
controllers: [GroupsController],
|
controllers: [GroupsController],
|
||||||
providers: [GroupsService],
|
providers: [GroupsService],
|
||||||
})
|
})
|
||||||
|
@ -1,30 +1,4 @@
|
|||||||
import { Injectable } from "@nestjs/common";
|
import { Injectable } from "@nestjs/common";
|
||||||
import { DbService } from 'apps/backend/src/app/db/db.service';
|
|
||||||
import { FilesGroupTable } from 'apps/backend/src/app/db/schema';
|
|
||||||
import { ilike } from 'drizzle-orm';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class GroupsService {
|
export class GroupsService {}
|
||||||
constructor(private readonly database: DbService) {}
|
|
||||||
|
|
||||||
//TODO a method to fetch groups in the database by a specific search with limit, offset and a search field (can be blank)
|
|
||||||
async getGroupsByName(limit: number, offset: number, search: string) {
|
|
||||||
const result = await this.database.use()
|
|
||||||
.select()
|
|
||||||
.from(FilesGroupTable)
|
|
||||||
.where(ilike(FilesGroupTable.groupName, search))
|
|
||||||
.limit(limit)
|
|
||||||
.offset(offset)
|
|
||||||
.prepare("getGroupsByName")
|
|
||||||
.execute()
|
|
||||||
console.log(`Found ${result.length} groups for search :\n > "${search}"`)
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO The method to create a group
|
|
||||||
|
|
||||||
|
|
||||||
//TODO a method to delete a group and place the associated file at a null group reference
|
|
||||||
|
|
||||||
//TODO a method to get the files of a group in the database by a specific search with limit, offset and a search field (can be blank)
|
|
||||||
}
|
|
||||||
|
@ -1,15 +1,4 @@
|
|||||||
import { Injectable } from "@nestjs/common";
|
import { Injectable } from "@nestjs/common";
|
||||||
import { DbService } from 'apps/backend/src/app/db/db.service';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class MachinesService {
|
export class MachinesService {}
|
||||||
constructor(private readonly database: DbService) {}
|
|
||||||
|
|
||||||
//TODO a method to fetch machines in the database by a specific search with limit, offset and a search field (can be blank)
|
|
||||||
|
|
||||||
//TODO The method to create a machine
|
|
||||||
|
|
||||||
//TODO a method to delete a machine and delete the associated FilesTypeForMachine row
|
|
||||||
|
|
||||||
//TODO a method to get the files of a group in the database by a specific search with limit, offset and a search field (can be blank)
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user