Skip to content

Commit ea68c3f

Browse files
committed
Function: Image Generation History
1 parent 58758c6 commit ea68c3f

File tree

4 files changed

+47
-14
lines changed

4 files changed

+47
-14
lines changed

src/services/database-integration.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { SettingsService } from './settings-service';
33
import { Conversation, Message, ConversationFolder, MessageContent, MessageContentType, FileJsonData } from '../types/chat';
44
import { v4 as uuidv4 } from 'uuid';
55
import { FileData } from '../types/file';
6+
import { ImageGenerationResult } from '../types/image';
67

78
const SYSTEM_MESSAGE_CONTENT: MessageContent[] = [
89
{
@@ -350,6 +351,17 @@ export class DatabaseIntegrationService {
350351
};
351352
}
352353

354+
public async saveImageGenerationResult(imageResult: ImageGenerationResult){
355+
try {
356+
const resultID = await this.dbService.saveImageGenerationResult(imageResult);
357+
return resultID;
358+
} catch (error) {
359+
console.error('Error getting files:', error);
360+
return null;
361+
}
362+
}
363+
364+
353365
public async saveFile(fileData: FileJsonData, arrayBuffer: ArrayBuffer): Promise<string> {
354366
const fileId = uuidv4();
355367
const file: FileData = {

src/services/database.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ import { Conversation, Message, ConversationFolder } from '../types/chat';
33
import { v4 as uuidv4 } from 'uuid';
44
import { UserSettings } from '../types/settings';
55
import { FileData } from '../types/file';
6+
import { ImageGenerationResult } from '../types/image';
67

78
// database.ts
89
export class DatabaseService {
910
private db: IDBDatabase | null = null;
1011
private readonly DB_NAME = 'tensorblock_db';
11-
private readonly DB_VERSION = 3; // Increase version to trigger upgrade
12+
private readonly DB_VERSION = 4; // Increase version to trigger upgrade
1213
private readonly ENCRYPTION_KEY = 'your-secure-encryption-key'; // In production, use a secure key management system
1314

1415
private isInitialized: boolean = false;
@@ -70,6 +71,12 @@ export class DatabaseService {
7071
chatStore.createIndex('messageId', 'messageId');
7172
}
7273

74+
// Create image generation results store
75+
if (!db.objectStoreNames.contains('imageGenerationResults')) {
76+
db.createObjectStore('imageGenerationResults', {
77+
keyPath: 'imageResultId'
78+
});
79+
}
7380
// Create API settings store
7481
if (!db.objectStoreNames.contains('apiSettings')) {
7582
db.createObjectStore('apiSettings', {
@@ -547,6 +554,19 @@ export class DatabaseService {
547554
});
548555
}
549556

557+
public async saveImageGenerationResult(imageGenerationResult: ImageGenerationResult): Promise<string> {
558+
return new Promise((resolve, reject) => {
559+
if (!this.db) throw new Error('Database not initialized');
560+
561+
const transaction = this.db.transaction('imageGenerationResults', 'readwrite');
562+
const store = transaction.objectStore('imageGenerationResults');
563+
const request = store.add(imageGenerationResult);
564+
565+
request.onsuccess = () => resolve(request.result as string);
566+
request.onerror = () => reject(request.error);
567+
});
568+
}
569+
550570
/**
551571
* Get all files from the database
552572
* @returns List of files

src/types/chat.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,3 @@ export interface ConversationFolder{
5353
updatedAt: Date;
5454
colorFlag: string;
5555
}
56-
57-
export interface ImageGenerationResult {
58-
id: string;
59-
prompt: string;
60-
negativePrompt: string;
61-
seed: string;
62-
number: number;
63-
status: string;
64-
aspectRatio: string;
65-
provider: string;
66-
model: string;
67-
images: MessageContent[];
68-
}

src/types/image.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { MessageContent } from "./chat";
2+
3+
export interface ImageGenerationResult {
4+
imageResultId: string;
5+
prompt: string;
6+
negativePrompt: string;
7+
seed: string;
8+
number: number;
9+
status: string;
10+
aspectRatio: string;
11+
provider: string;
12+
model: string;
13+
images: MessageContent[];
14+
}

0 commit comments

Comments
 (0)