mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 20:35:02 +00:00
Encrypt archives at rest
This commit is contained in:
parent
7562a886e1
commit
a017aa7bfe
3 changed files with 47 additions and 1 deletions
21
backend/src/data/encryptedTextTransformer.ts
Normal file
21
backend/src/data/encryptedTextTransformer.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
import { decrypt, encrypt } from "../utils/crypt";
|
||||
import { ValueTransformer } from "typeorm";
|
||||
|
||||
interface EncryptedTextTransformer extends ValueTransformer {
|
||||
from(dbValue: any): string;
|
||||
to(entityValue: string): any;
|
||||
}
|
||||
|
||||
export function createEncryptedTextTransformer(): EncryptedTextTransformer {
|
||||
return {
|
||||
// Database -> Entity
|
||||
from(dbValue) {
|
||||
return decrypt(dbValue);
|
||||
},
|
||||
|
||||
// Entity -> Database
|
||||
to(entityValue) {
|
||||
return encrypt(entityValue);
|
||||
},
|
||||
};
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
|
||||
import { createEncryptedTextTransformer } from "../encryptedTextTransformer";
|
||||
|
||||
@Entity("archives")
|
||||
export class ArchiveEntry {
|
||||
|
@ -8,7 +9,11 @@ export class ArchiveEntry {
|
|||
|
||||
@Column() guild_id: string;
|
||||
|
||||
@Column() body: string;
|
||||
@Column({
|
||||
type: "mediumtext",
|
||||
transformer: createEncryptedTextTransformer(),
|
||||
})
|
||||
body: string;
|
||||
|
||||
@Column() created_at: string;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue