a badly looking image cards thing

This commit is contained in:
2020-10-14 20:50:30 +03:00
committed by Stepan Usatiuk
parent 07ccc56636
commit c20642dba4
17 changed files with 364 additions and 65 deletions

View File

@@ -2,6 +2,7 @@ import * as path from "path";
import * as fs from "fs/promises";
import * as mime from "mime-types";
import { constants as fsConstants } from "fs";
import * as jwt from "jsonwebtoken";
import {
AfterRemove,
@@ -25,6 +26,7 @@ import {
Matches,
validateOrReject,
} from "class-validator";
import { config } from "~config";
export interface IPhotoJSON {
id: number;
@@ -36,6 +38,10 @@ export interface IPhotoJSON {
editedAt: number;
}
export interface IPhotoReqJSON extends IPhotoJSON {
accessToken: string;
}
@Entity()
export class Photo extends BaseEntity {
@PrimaryGeneratedColumn()
@@ -114,6 +120,13 @@ export class Photo extends BaseEntity {
this.user = user;
}
public getJWTToken(): string {
return jwt.sign(this.toJSON(), config.jwtSecret, {
expiresIn: "1h",
algorithm: "HS256",
});
}
public toJSON(): IPhotoJSON {
return {
id: this.id,
@@ -125,4 +138,17 @@ export class Photo extends BaseEntity {
editedAt: this.editedAt.getTime(),
};
}
public toReqJSON(): IPhotoReqJSON {
return {
id: this.id,
user: this.user.id,
hash: this.hash,
size: this.size,
format: this.format,
createdAt: this.createdAt.getTime(),
editedAt: this.editedAt.getTime(),
accessToken: this.getJWTToken(),
};
}
}