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