chore: sync repo

This commit is contained in:
Hackntosh 2024-02-15 10:06:59 +00:00
parent e17e9bfa72
commit ae826cc130
9 changed files with 159 additions and 92 deletions

62
package-lock.json generated
View file

@ -23,7 +23,7 @@
"@nestjs/platform-fastify": "^10.3.1", "@nestjs/platform-fastify": "^10.3.1",
"@nestjs/swagger": "^7.2.0", "@nestjs/swagger": "^7.2.0",
"@nestjs/throttler": "^5.1.1", "@nestjs/throttler": "^5.1.1",
"@prisma/client": "^5.8.1", "@prisma/client": "^5.9.1",
"bcrypt": "^5.1.1", "bcrypt": "^5.1.1",
"file-type": "^19.0.0", "file-type": "^19.0.0",
"ioredis": "^5.3.2", "ioredis": "^5.3.2",
@ -33,7 +33,6 @@
"passport": "^0.7.0", "passport": "^0.7.0",
"passport-jwt": "^4.0.1", "passport-jwt": "^4.0.1",
"passport-local": "^1.0.0", "passport-local": "^1.0.0",
"prisma": "^5.8.1",
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
"rxjs": "^7.8.1", "rxjs": "^7.8.1",
"sharp": "^0.33.2" "sharp": "^0.33.2"
@ -64,6 +63,7 @@
"jest": "^29.5.0", "jest": "^29.5.0",
"lint-staged": "^15.2.1", "lint-staged": "^15.2.1",
"prettier": "^3.0.0", "prettier": "^3.0.0",
"prisma": "^5.9.1",
"source-map-support": "^0.5.21", "source-map-support": "^0.5.21",
"supertest": "^6.3.3", "supertest": "^6.3.3",
"ts-jest": "^29.1.0", "ts-jest": "^29.1.0",
@ -4224,9 +4224,9 @@
} }
}, },
"node_modules/@prisma/client": { "node_modules/@prisma/client": {
"version": "5.9.0", "version": "5.9.1",
"resolved": "https://registry.npmjs.org/@prisma/client/-/client-5.9.0.tgz", "resolved": "https://registry.npmjs.org/@prisma/client/-/client-5.9.1.tgz",
"integrity": "sha512-dHvFZgCT0BpRS+gRhk3S+50DstXMmVowxbrPeUJaK7sjNq5OhzfpT/OGE1kq9z5Q8WmOwIXJXyxP8O2CmP+nSg==", "integrity": "sha512-caSOnG4kxcSkhqC/2ShV7rEoWwd3XrftokxJqOCMVvia4NYV/TPtJlS9C2os3Igxw/Qyxumj9GBQzcStzECvtQ==",
"hasInstallScript": true, "hasInstallScript": true,
"engines": { "engines": {
"node": ">=16.13" "node": ">=16.13"
@ -4241,43 +4241,48 @@
} }
}, },
"node_modules/@prisma/debug": { "node_modules/@prisma/debug": {
"version": "5.9.0", "version": "5.9.1",
"resolved": "https://registry.npmjs.org/@prisma/debug/-/debug-5.9.0.tgz", "resolved": "https://registry.npmjs.org/@prisma/debug/-/debug-5.9.1.tgz",
"integrity": "sha512-3Uhj5YSPqaIfzJQ6JQzCNBXeBTy0x803fGIoo2tvP/KIEd+o4o49JxCQtKtP8aeef5iNh5Nn9Z25wDrdLjS80A==" "integrity": "sha512-yAHFSFCg8KVoL0oRUno3m60GAjsUKYUDkQ+9BA2X2JfVR3kRVSJFc/GpQ2fSORi4pSHZR9orfM4UC9OVXIFFTA==",
"devOptional": true
}, },
"node_modules/@prisma/engines": { "node_modules/@prisma/engines": {
"version": "5.9.0", "version": "5.9.1",
"resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-5.9.0.tgz", "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-5.9.1.tgz",
"integrity": "sha512-BH1fpXbMH09TwfZH5FVMJwRp6afEhKzqwebbCLdaEkJDuhxA//iwbILLqGFtGTgZbdBNUOThIK+UC3++5kWMTg==", "integrity": "sha512-gkdXmjxQ5jktxWNdDA5aZZ6R8rH74JkoKq6LD5mACSvxd2vbqWeWIOV0Py5wFC8vofOYShbt6XUeCIUmrOzOnQ==",
"devOptional": true,
"hasInstallScript": true, "hasInstallScript": true,
"dependencies": { "dependencies": {
"@prisma/debug": "5.9.0", "@prisma/debug": "5.9.1",
"@prisma/engines-version": "5.9.0-32.23fdc5965b1e05fc54e5f26ed3de66776b93de64", "@prisma/engines-version": "5.9.0-32.23fdc5965b1e05fc54e5f26ed3de66776b93de64",
"@prisma/fetch-engine": "5.9.0", "@prisma/fetch-engine": "5.9.1",
"@prisma/get-platform": "5.9.0" "@prisma/get-platform": "5.9.1"
} }
}, },
"node_modules/@prisma/engines-version": { "node_modules/@prisma/engines-version": {
"version": "5.9.0-32.23fdc5965b1e05fc54e5f26ed3de66776b93de64", "version": "5.9.0-32.23fdc5965b1e05fc54e5f26ed3de66776b93de64",
"resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-5.9.0-32.23fdc5965b1e05fc54e5f26ed3de66776b93de64.tgz", "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-5.9.0-32.23fdc5965b1e05fc54e5f26ed3de66776b93de64.tgz",
"integrity": "sha512-HFl7275yF0FWbdcNvcSRbbu9JCBSLMcurYwvWc8WGDnpu7APxQo2ONtZrUggU3WxLxUJ2uBX+0GOFIcJeVeOOQ==" "integrity": "sha512-HFl7275yF0FWbdcNvcSRbbu9JCBSLMcurYwvWc8WGDnpu7APxQo2ONtZrUggU3WxLxUJ2uBX+0GOFIcJeVeOOQ==",
"devOptional": true
}, },
"node_modules/@prisma/fetch-engine": { "node_modules/@prisma/fetch-engine": {
"version": "5.9.0", "version": "5.9.1",
"resolved": "https://registry.npmjs.org/@prisma/fetch-engine/-/fetch-engine-5.9.0.tgz", "resolved": "https://registry.npmjs.org/@prisma/fetch-engine/-/fetch-engine-5.9.1.tgz",
"integrity": "sha512-NL8Vm8Vl2d6NOSkkPGN5TTTz4s6cyCleXOzqtOFWzfKFJ4wtN2Shu7llOT+ykf6nDzh1lCN2JHUt1S6FGFZGig==", "integrity": "sha512-l0goQOMcNVOJs1kAcwqpKq3ylvkD9F04Ioe1oJoCqmz05mw22bNAKKGWuDd3zTUoUZr97va0c/UfLNru+PDmNA==",
"devOptional": true,
"dependencies": { "dependencies": {
"@prisma/debug": "5.9.0", "@prisma/debug": "5.9.1",
"@prisma/engines-version": "5.9.0-32.23fdc5965b1e05fc54e5f26ed3de66776b93de64", "@prisma/engines-version": "5.9.0-32.23fdc5965b1e05fc54e5f26ed3de66776b93de64",
"@prisma/get-platform": "5.9.0" "@prisma/get-platform": "5.9.1"
} }
}, },
"node_modules/@prisma/get-platform": { "node_modules/@prisma/get-platform": {
"version": "5.9.0", "version": "5.9.1",
"resolved": "https://registry.npmjs.org/@prisma/get-platform/-/get-platform-5.9.0.tgz", "resolved": "https://registry.npmjs.org/@prisma/get-platform/-/get-platform-5.9.1.tgz",
"integrity": "sha512-8CatX+E6eZxcOjJZe5hF8EXxdb5GsQTA/u7pdmUJSxGLacW9K3r5vDdgV8s22PubObQQ6979/rkCMItbCrG4Yg==", "integrity": "sha512-6OQsNxTyhvG+T2Ksr8FPFpuPeL4r9u0JF0OZHUBI/Uy9SS43sPyAIutt4ZEAyqWQt104ERh70EZedkHZKsnNbg==",
"devOptional": true,
"dependencies": { "dependencies": {
"@prisma/debug": "5.9.0" "@prisma/debug": "5.9.1"
} }
}, },
"node_modules/@sinclair/typebox": { "node_modules/@sinclair/typebox": {
@ -12937,12 +12942,13 @@
} }
}, },
"node_modules/prisma": { "node_modules/prisma": {
"version": "5.9.0", "version": "5.9.1",
"resolved": "https://registry.npmjs.org/prisma/-/prisma-5.9.0.tgz", "resolved": "https://registry.npmjs.org/prisma/-/prisma-5.9.1.tgz",
"integrity": "sha512-0UcOofjNuAnd227JMaPqZvP01dsUXw9EXB9iC8fyoZtfv7zkQ0ozxyjY1g+vcjFPOnNLICMnLHx+lM5BJZYqOQ==", "integrity": "sha512-Hy/8KJZz0ELtkw4FnG9MS9rNWlXcJhf98Z2QMqi0QiVMoS8PzsBkpla0/Y5hTlob8F3HeECYphBjqmBxrluUrQ==",
"devOptional": true,
"hasInstallScript": true, "hasInstallScript": true,
"dependencies": { "dependencies": {
"@prisma/engines": "5.9.0" "@prisma/engines": "5.9.1"
}, },
"bin": { "bin": {
"prisma": "build/index.js" "prisma": "build/index.js"

View file

@ -44,7 +44,7 @@
"@nestjs/platform-fastify": "^10.3.1", "@nestjs/platform-fastify": "^10.3.1",
"@nestjs/swagger": "^7.2.0", "@nestjs/swagger": "^7.2.0",
"@nestjs/throttler": "^5.1.1", "@nestjs/throttler": "^5.1.1",
"@prisma/client": "^5.8.1", "@prisma/client": "^5.9.1",
"bcrypt": "^5.1.1", "bcrypt": "^5.1.1",
"file-type": "^19.0.0", "file-type": "^19.0.0",
"ioredis": "^5.3.2", "ioredis": "^5.3.2",
@ -54,7 +54,6 @@
"passport": "^0.7.0", "passport": "^0.7.0",
"passport-jwt": "^4.0.1", "passport-jwt": "^4.0.1",
"passport-local": "^1.0.0", "passport-local": "^1.0.0",
"prisma": "^5.8.1",
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
"rxjs": "^7.8.1", "rxjs": "^7.8.1",
"sharp": "^0.33.2" "sharp": "^0.33.2"
@ -85,6 +84,7 @@
"jest": "^29.5.0", "jest": "^29.5.0",
"lint-staged": "^15.2.1", "lint-staged": "^15.2.1",
"prettier": "^3.0.0", "prettier": "^3.0.0",
"prisma": "^5.9.1",
"source-map-support": "^0.5.21", "source-map-support": "^0.5.21",
"supertest": "^6.3.3", "supertest": "^6.3.3",
"ts-jest": "^29.1.0", "ts-jest": "^29.1.0",

View file

@ -0,0 +1,11 @@
import { Injectable } from "@nestjs/common";
import { PrismaService } from "src/services/prisma/prisma.service";
import { S3Service } from "src/services/s3/s3.service";
@Injectable()
export class CommentsService {
constructor(
private readonly prisma: PrismaService,
private readonly s3: S3Service,
) {}
}

View file

@ -1 +1,11 @@
export class UpdateKweekDTO {} import { createZodDto } from "nestjs-zod";
import { z } from "nestjs-zod/z";
export const UpdateKweekSchema = z
.object({
id: z.string().toLowerCase().describe("New username - optional"),
content: z.string({ required_error: "Content is required" }).max(300),
})
.required();
export class UpdateKweekDTO extends createZodDto(UpdateKweekSchema) {}

View file

@ -20,7 +20,6 @@ import {
import { ApiCreateKweek } from "src/decorators/create-kweek.decorator"; import { ApiCreateKweek } from "src/decorators/create-kweek.decorator";
import { Public } from "src/decorators/public.decorator"; import { Public } from "src/decorators/public.decorator";
import { MultiFileValidation } from "src/validators/multi-file.validator"; import { MultiFileValidation } from "src/validators/multi-file.validator";
import { UpdateKweekDTO } from "./dto/update-kweek.dto";
import { KweeksService } from "./kweeks.service"; import { KweeksService } from "./kweeks.service";
@ApiTags("Kweeks") @ApiTags("Kweeks")
@ -46,21 +45,21 @@ export class KweeksController {
@Get(":id") @Get(":id")
@ApiOperation({ summary: "Retrieves information about a kweek" }) @ApiOperation({ summary: "Retrieves information about a kweek" })
findOne(@Param("id") id: string) { findOne(@Param("id") id: string) {
return this.kweeksService.findOne(+id); return this.kweeksService.findOne(id);
} }
@Patch(":id") @Patch()
@ApiOperation({ summary: "Updates a kweek content" }) @ApiOperation({ summary: "Updates a kweek content" })
@ApiBearerAuth("JWT") @ApiBearerAuth("JWT")
update(@Param("id") id: string, @Body() updateKweekDto: UpdateKweekDTO) { update(@Body() body: { id: string; content: string }) {
return this.kweeksService.update(+id, updateKweekDto); return this.kweeksService.update(body.id, body.content);
} }
@Delete(":id") @Delete(":id")
@ApiOperation({ summary: "Deletes a kweek" }) @ApiOperation({ summary: "Deletes a kweek" })
@ApiBearerAuth("JWT") @ApiBearerAuth("JWT")
remove(@Param("id") id: string) { remove(@Param("id") id: string) {
return this.kweeksService.remove(+id); return this.kweeksService.remove(id);
} }
@Post(":id/like") @Post(":id/like")

View file

@ -1,12 +1,13 @@
import { Module } from "@nestjs/common"; import { Module } from "@nestjs/common";
import { PrismaModule } from "src/services/prisma/prisma.module"; import { PrismaModule } from "src/services/prisma/prisma.module";
import { S3Service } from "src/services/s3/s3.service"; import { S3Service } from "src/services/s3/s3.service";
import { CommentsService } from "./comments.service";
import { KweeksController } from "./kweeks.controller"; import { KweeksController } from "./kweeks.controller";
import { KweeksService } from "./kweeks.service"; import { KweeksService } from "./kweeks.service";
@Module({ @Module({
imports: [PrismaModule], imports: [PrismaModule],
controllers: [KweeksController], controllers: [KweeksController],
providers: [KweeksService, S3Service], providers: [KweeksService, S3Service, CommentsService],
}) })
export class KweeksModule {} export class KweeksModule {}

View file

@ -1,8 +1,11 @@
import { File } from "@nest-lab/fastify-multer"; import { File } from "@nest-lab/fastify-multer";
import { Injectable } from "@nestjs/common"; import {
BadRequestException,
Injectable,
NotFoundException,
} from "@nestjs/common";
import { PrismaService } from "src/services/prisma/prisma.service"; import { PrismaService } from "src/services/prisma/prisma.service";
import { S3Service } from "src/services/s3/s3.service"; import { S3Service } from "src/services/s3/s3.service";
import { UpdateKweekDTO } from "./dto/update-kweek.dto";
@Injectable() @Injectable()
export class KweeksService { export class KweeksService {
@ -11,36 +14,71 @@ export class KweeksService {
private readonly s3: S3Service, private readonly s3: S3Service,
) {} ) {}
async create(content: string, authorId: string, files: Array<File>) { async create(content: string, authorId: string, files: Array<File>) {
const post = await this.prisma.kweek.create({ if (content.length > 300) {
throw new BadRequestException(
"Content too big. Must have 300 characters or lower",
);
}
const { id } = await this.prisma.kweek.create({
data: { data: {
content, content,
authorId, authorId,
} },
select: {
id: true,
},
}); });
const attachments = await this.s3.multiImageUploadToMinio(post.id, files); const attachments = await this.s3.multiImageUploadToMinio(id, files);
await this.prisma.kweek.updateMany({ await this.prisma.kweek.update({
where: { where: {
id: post.id id,
}, },
data: { data: {
attachments attachments,
}, },
}); });
return await this.prisma.kweek.findUnique({where: {id: post.id}}); return await this.prisma.kweek.findFirst({ where: { id } });
} }
findOne(id: number) { async findOne(id: string) {
return `This action returns a #${id} kweek`; const post = await this.prisma.kweek.findFirst({
where: {
id,
},
select: {
id: true,
content: true,
attachments: true,
createdAt: true,
updatedAt: true,
author: {
select: {
displayName: true,
username: true,
profileImage: true,
},
},
likes: true,
comments: true,
},
});
if (post === null) {
throw new NotFoundException("Post not found");
} }
update(id: number, updateKweekDto: UpdateKweekDTO) { return post;
}
update(id: string, content: string) {
return `This action updates a #${id} kweek`; return `This action updates a #${id} kweek`;
} }
remove(id: number) { remove(id: string) {
return `This action removes a #${id} kweek`; return `This action removes a #${id} kweek`;
} }
} }

View file

@ -1,7 +1,7 @@
import { PutObjectCommand, PutObjectCommandInput } from "@aws-sdk/client-s3"; import { PutObjectCommand, PutObjectCommandInput } from "@aws-sdk/client-s3";
import { BadRequestException, Injectable, InternalServerErrorException } from "@nestjs/common";
import { InjectS3, S3 } from "nestjs-s3";
import { File } from "@nest-lab/fastify-multer"; import { File } from "@nest-lab/fastify-multer";
import { Injectable, InternalServerErrorException } from "@nestjs/common";
import { InjectS3, S3 } from "nestjs-s3";
import sharp from "sharp"; import sharp from "sharp";
@Injectable() @Injectable()
@ -47,7 +47,9 @@ export class S3Service {
for (let i = 0; i < files.length; i++) { for (let i = 0; i < files.length; i++) {
const { buffer } = files[i]; const { buffer } = files[i];
const compressedBuffers = await sharp(buffer).webp({quality: 70}).toBuffer(); const compressedBuffers = await sharp(buffer)
.webp({ quality: 70 })
.toBuffer();
buffers.push(compressedBuffers); buffers.push(compressedBuffers);
} }
@ -65,10 +67,10 @@ export class S3Service {
Bucket: process.env.MINIO_DEFAULT_BUCKETS, Bucket: process.env.MINIO_DEFAULT_BUCKETS,
Key, Key,
Body: buffer, Body: buffer,
ContentType: 'image/webp', ContentType: "image/webp",
}; };
await this.s3.send(new PutObjectCommand(params)) await this.s3.send(new PutObjectCommand(params));
return `${process.env.MINIO_ENDPOINT}/${process.env.MINIO_DEFAULT_BUCKETS}/${Key}` return `${process.env.MINIO_ENDPOINT}/${process.env.MINIO_DEFAULT_BUCKETS}/${Key}`;
} }
} }