mirror of
https://github.com/CaramelFur/Picsur.git
synced 2025-11-17 08:40:39 +01:00
small fixes
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
||||
Optional
|
||||
} from '@nestjs/common';
|
||||
import { Reflector } from '@nestjs/core';
|
||||
import { ApiAnySuccessResponse } from 'picsur-shared/dist/dto/api/api.dto';
|
||||
import { ZodDtoStatic } from 'picsur-shared/dist/util/create-zod-dto';
|
||||
import { map, Observable } from 'rxjs';
|
||||
|
||||
@@ -31,7 +32,7 @@ export class SuccessInterceptor<T> implements NestInterceptor {
|
||||
this.strict = options?.strict ?? true;
|
||||
}
|
||||
|
||||
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
|
||||
intercept(context: ExecutionContext, next: CallHandler): Observable<unknown> {
|
||||
return next.handle().pipe(
|
||||
map((data) => {
|
||||
if (data instanceof Buffer) {
|
||||
@@ -47,7 +48,7 @@ export class SuccessInterceptor<T> implements NestInterceptor {
|
||||
);
|
||||
}
|
||||
|
||||
private validate(context: ExecutionContext, data: any): any {
|
||||
private validate(context: ExecutionContext, data: unknown): unknown {
|
||||
const schemaStatic = this.reflector.get<ZodDtoStatic>(
|
||||
'returns',
|
||||
context.getHandler(),
|
||||
@@ -75,10 +76,10 @@ export class SuccessInterceptor<T> implements NestInterceptor {
|
||||
return parseResult.data;
|
||||
}
|
||||
|
||||
private createResponse(context: ExecutionContext, data: any): any {
|
||||
private createResponse(context: ExecutionContext, data: unknown): ApiAnySuccessResponse {
|
||||
const status = context.switchToHttp().getResponse().statusCode;
|
||||
const response = {
|
||||
success: true,
|
||||
success: true as true, // really typescript
|
||||
statusCode: status,
|
||||
timestamp: new Date().toISOString(),
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ export class ViewComponent implements OnInit {
|
||||
) {}
|
||||
|
||||
public imageUrl: string = '';
|
||||
public imageLinks: ImageLinks = new ImageLinks();
|
||||
public imageLinks = new ImageLinks();
|
||||
|
||||
async ngOnInit() {
|
||||
const params = this.route.snapshot.paramMap;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ImageMetaResponse } from 'picsur-shared/dist/dto/api/image.dto';
|
||||
import { ImageLinks } from 'picsur-shared/dist/dto/imagelinks.dto';
|
||||
import { EImage } from 'picsur-shared/dist/entities/image.entity';
|
||||
import { AsyncFailable } from 'picsur-shared/dist/types';
|
||||
import { Open } from 'picsur-shared/dist/types/failable';
|
||||
@@ -31,7 +32,7 @@ export class ImageService {
|
||||
return `${baseURL}/i/${image}`;
|
||||
}
|
||||
|
||||
public CreateImageLinks(imageURL: string) {
|
||||
public CreateImageLinks(imageURL: string): ImageLinks {
|
||||
return {
|
||||
source: imageURL,
|
||||
markdown: ``,
|
||||
|
||||
@@ -26,3 +26,12 @@ export const ApiResponseSchema = <T extends z.AnyZodObject>(data: T) =>
|
||||
ApiErrorResponse.or(ApiSuccessResponse(data));
|
||||
|
||||
export type ApiErrorResponse = z.infer<typeof ApiErrorResponse>;
|
||||
|
||||
const ApiAnySuccessResponseSchema = ApiSuccessResponse(z.object({}))
|
||||
.omit({ data: true })
|
||||
.merge(
|
||||
z.object({
|
||||
data: z.any(),
|
||||
}),
|
||||
);
|
||||
export type ApiAnySuccessResponse = z.infer<typeof ApiAnySuccessResponseSchema>;
|
||||
|
||||
Reference in New Issue
Block a user