mirror of
https://github.com/usatiuk/photos.git
synced 2025-10-29 07:47:47 +01:00
a badly looking image cards thing
This commit is contained in:
@@ -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(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user