diff --git a/src/utils/PlatformServiceMixin.ts b/src/utils/PlatformServiceMixin.ts index cb718625..c457fd81 100644 --- a/src/utils/PlatformServiceMixin.ts +++ b/src/utils/PlatformServiceMixin.ts @@ -47,6 +47,7 @@ import type { import { MASTER_SETTINGS_KEY, type Settings } from "@/db/tables/settings"; import { logger } from "@/utils/logger"; import { Contact } from "@/db/tables/contacts"; +import { Temp } from "@/db/tables/temp"; import { QueryExecResult, DatabaseExecResult } from "@/interfaces/database"; import { generateInsertStatement, @@ -954,6 +955,41 @@ export const PlatformServiceMixin = { } }, + // ================================================= + // TEMP TABLE METHODS (for temporary storage) + // ================================================= + + /** + * Get temporary data by ID - $getTemp() + * Retrieves temporary data from the temp table + * @param id Temporary storage ID + * @returns Promise Temporary data or null if not found + */ + async $getTemp(id: string): Promise { + try { + return await this.$first("SELECT * FROM temp WHERE id = ?", [id]); + } catch (error) { + logger.error("[PlatformServiceMixin] Error getting temp data:", error); + return null; + } + }, + + /** + * Delete temporary data by ID - $deleteTemp() + * Removes temporary data from the temp table + * @param id Temporary storage ID + * @returns Promise Success status + */ + async $deleteTemp(id: string): Promise { + try { + await this.$dbExec("DELETE FROM temp WHERE id = ?", [id]); + return true; + } catch (error) { + logger.error("[PlatformServiceMixin] Error deleting temp data:", error); + return false; + } + }, + /** * Generic entity insertion - $insertEntity() * Eliminates verbose INSERT patterns for any entity @@ -1261,6 +1297,8 @@ export interface IPlatformServiceMixin { did: string, settings: Partial, ): Promise; + $getTemp(id: string): Promise; + $deleteTemp(id: string): Promise; // Logging methods $log(message: string, level?: string): Promise; @@ -1381,6 +1419,8 @@ declare module "@vue/runtime-core" { did: string, settings: Partial, ): Promise; + $getTemp(id: string): Promise; + $deleteTemp(id: string): Promise; // Logging methods $log(message: string, level?: string): Promise; diff --git a/src/views/SharedPhotoView.vue b/src/views/SharedPhotoView.vue index e82cf553..6b4bec29 100644 --- a/src/views/SharedPhotoView.vue +++ b/src/views/SharedPhotoView.vue @@ -28,7 +28,7 @@ Migration Status: ✅ Complete Enhanced Triple Migration Pattern - Phase 1: Database Migration (PlatformServiceMixin) ✅ - - Phase 2: SQL Abstraction ($dbQuery, $dbExec, $accountSettings, $updateSettings) ✅ + - Phase 2: SQL Abstraction ($getTemp, $deleteTemp, $accountSettings, $updateSettings) ✅ - Phase 3: Notification Migration (3 constants, helper methods) ✅ - Phase 4: Template Streamlining (Simple template) ✅ @@ -119,7 +119,7 @@ import { import { accessToken } from "../libs/crypto"; import { base64ToBlob, SHARED_PHOTO_BASE64_KEY } from "../libs/util"; import { logger } from "../utils/logger"; -import { Temp } from "@/db/tables/temp"; + import { PlatformServiceMixin } from "@/utils/PlatformServiceMixin"; import { createNotifyHelpers, TIMEOUTS } from "@/utils/notify"; import { @@ -178,17 +178,13 @@ export default class SharedPhotoView extends Vue { const settings = await this.$accountSettings(); this.activeDid = settings.activeDid; - const temp = await this.$first("SELECT * FROM temp WHERE id = ?", [ - SHARED_PHOTO_BASE64_KEY, - ]); + const temp = await this.$getTemp(SHARED_PHOTO_BASE64_KEY); const imageB64 = temp?.blobB64 as string; if (temp) { this.imageBlob = base64ToBlob(imageB64); // clear the temp image - await this.$dbExec("DELETE FROM temp WHERE id = ?", [ - SHARED_PHOTO_BASE64_KEY, - ]); + await this.$deleteTemp(SHARED_PHOTO_BASE64_KEY); this.imageFileName = this.$route.query["fileName"] as string; } else {