refactor services structure

This commit is contained in:
Maze Winther 2026-01-31 22:19:11 +01:00
parent 7878c8bb7b
commit f820d9a894
12 changed files with 779 additions and 778 deletions

File diff suppressed because it is too large Load Diff

View File

@ -17,7 +17,7 @@ import type {
TranscriptionLanguage, TranscriptionLanguage,
TranscriptionProgress, TranscriptionProgress,
} from "@/types/transcription"; } from "@/types/transcription";
import { transcriptionService } from "@/services/transcription"; import { transcriptionService } from "@/services/transcription/service";
import { decodeAudioToFloat32 } from "@/lib/media/audio"; import { decodeAudioToFloat32 } from "@/lib/media/audio";
import { buildCaptionChunks } from "@/lib/transcription/caption"; import { buildCaptionChunks } from "@/lib/transcription/caption";
import { Spinner } from "@/components/ui/spinner"; import { Spinner } from "@/components/ui/spinner";

View File

@ -3,7 +3,7 @@
import { createContext, useContext, useEffect, useRef, useState } from "react"; import { createContext, useContext, useEffect, useRef, useState } from "react";
import { toast } from "sonner"; import { toast } from "sonner";
import { useEditor } from "@/hooks/use-editor"; import { useEditor } from "@/hooks/use-editor";
import { storageService } from "@/services/storage/storage-service"; import { storageService } from "@/services/storage/service";
interface StorageContextType { interface StorageContextType {
isInitialized: boolean; isInitialized: boolean;

View File

@ -1,8 +1,8 @@
import type { EditorCore } from "@/core"; import type { EditorCore } from "@/core";
import type { MediaAsset } from "@/types/assets"; import type { MediaAsset } from "@/types/assets";
import { storageService } from "@/services/storage/storage-service"; import { storageService } from "@/services/storage/service";
import { generateUUID } from "@/utils/id"; import { generateUUID } from "@/utils/id";
import { videoCache } from "@/services/media/video-cache"; import { videoCache } from "@/services/video-cache/service";
import { hasMediaId } from "@/lib/timeline/element-utils"; import { hasMediaId } from "@/lib/timeline/element-utils";
export class MediaManager { export class MediaManager {

View File

@ -8,7 +8,7 @@ import type {
TTimelineViewState, TTimelineViewState,
} from "@/types/project"; } from "@/types/project";
import type { ExportOptions, ExportResult } from "@/types/export"; import type { ExportOptions, ExportResult } from "@/types/export";
import { storageService } from "@/services/storage/storage-service"; import { storageService } from "@/services/storage/service";
import { toast } from "sonner"; import { toast } from "sonner";
import { generateUUID } from "@/utils/id"; import { generateUUID } from "@/utils/id";
import { UpdateProjectSettingsCommand } from "@/lib/commands/project"; import { UpdateProjectSettingsCommand } from "@/lib/commands/project";

View File

@ -1,6 +1,6 @@
import type { EditorCore } from "@/core"; import type { EditorCore } from "@/core";
import type { TimelineTrack, TScene } from "@/types/timeline"; import type { TimelineTrack, TScene } from "@/types/timeline";
import { storageService } from "@/services/storage/storage-service"; import { storageService } from "@/services/storage/service";
import { import {
getMainScene, getMainScene,
ensureMainScene, ensureMainScene,

View File

@ -2,7 +2,7 @@ import { Command } from "@/lib/commands/base-command";
import { EditorCore } from "@/core"; import { EditorCore } from "@/core";
import type { MediaAsset } from "@/types/assets"; import type { MediaAsset } from "@/types/assets";
import { generateUUID } from "@/utils/id"; import { generateUUID } from "@/utils/id";
import { storageService } from "@/services/storage/storage-service"; import { storageService } from "@/services/storage/service";
export class AddMediaAssetCommand extends Command { export class AddMediaAssetCommand extends Command {
private assetId: string; private assetId: string;

View File

@ -1,8 +1,8 @@
import { Command } from "@/lib/commands/base-command"; import { Command } from "@/lib/commands/base-command";
import { EditorCore } from "@/core"; import { EditorCore } from "@/core";
import type { MediaAsset } from "@/types/assets"; import type { MediaAsset } from "@/types/assets";
import { storageService } from "@/services/storage/storage-service"; import { storageService } from "@/services/storage/service";
import { videoCache } from "@/services/media/video-cache"; import { videoCache } from "@/services/video-cache/service";
import { hasMediaId } from "@/lib/timeline/element-utils"; import { hasMediaId } from "@/lib/timeline/element-utils";
import type { TimelineTrack } from "@/types/timeline"; import type { TimelineTrack } from "@/types/timeline";

View File

@ -333,12 +333,9 @@ class StorageService {
]); ]);
} }
// Utility methods
async clearAllData(): Promise<void> { async clearAllData(): Promise<void> {
// Clear all projects
await this.projectsAdapter.clear(); await this.projectsAdapter.clear();
// project-specific media and timelines cleaned up when projects are deleted
// Note: Project-specific media and timelines will be cleaned up when projects are deleted
} }
async getStorageInfo(): Promise<{ async getStorageInfo(): Promise<{
@ -392,7 +389,6 @@ class StorageService {
try { try {
const currentData = await this.loadSavedSounds(); const currentData = await this.loadSavedSounds();
// Check if sound is already saved
if (currentData.sounds.some((sound) => sound.id === soundEffect.id)) { if (currentData.sounds.some((sound) => sound.id === soundEffect.id)) {
return; // Already saved return; // Already saved
} }
@ -456,7 +452,6 @@ class StorageService {
} }
} }
// Check browser support
isOPFSSupported(): boolean { isOPFSSupported(): boolean {
return OPFSAdapter.isSupported(); return OPFSAdapter.isSupported();
} }
@ -470,6 +465,5 @@ class StorageService {
} }
} }
// Export singleton instance
export const storageService = new StorageService(); export const storageService = new StorageService();
export { StorageService }; export { StorageService };

View File

@ -1,4 +1,5 @@
import type { import type {
TranscriptionLanguage,
TranscriptionResult, TranscriptionResult,
TranscriptionProgress, TranscriptionProgress,
TranscriptionModelId, TranscriptionModelId,
@ -8,7 +9,6 @@ import {
TRANSCRIPTION_MODELS, TRANSCRIPTION_MODELS,
} from "@/constants/transcription-constants"; } from "@/constants/transcription-constants";
import type { WorkerMessage, WorkerResponse } from "./worker"; import type { WorkerMessage, WorkerResponse } from "./worker";
import type { LanguageCode } from "@/types/language";
type ProgressCallback = (progress: TranscriptionProgress) => void; type ProgressCallback = (progress: TranscriptionProgress) => void;
@ -20,12 +20,12 @@ class TranscriptionService {
async transcribe({ async transcribe({
audioData, audioData,
language, language = "auto",
modelId = DEFAULT_TRANSCRIPTION_MODEL, modelId = DEFAULT_TRANSCRIPTION_MODEL,
onProgress, onProgress,
}: { }: {
audioData: Float32Array; audioData: Float32Array;
language?: LanguageCode; language?: TranscriptionLanguage;
modelId?: TranscriptionModelId; modelId?: TranscriptionModelId;
onProgress?: ProgressCallback; onProgress?: ProgressCallback;
}): Promise<TranscriptionResult> { }): Promise<TranscriptionResult> {

View File

@ -15,6 +15,7 @@ interface VideoSinkData {
prefetching: boolean; prefetching: boolean;
prefetchPromise: Promise<void> | null; prefetchPromise: Promise<void> | null;
} }
export class VideoCache { export class VideoCache {
private sinks = new Map<string, VideoSinkData>(); private sinks = new Map<string, VideoSinkData>();
private initPromises = new Map<string, Promise<void>>(); private initPromises = new Map<string, Promise<void>>();
@ -311,4 +312,5 @@ export class VideoCache {
}; };
} }
} }
export const videoCache = new VideoCache(); export const videoCache = new VideoCache();

View File

@ -1,6 +1,6 @@
import { create } from "zustand"; import { create } from "zustand";
import type { SoundEffect, SavedSound } from "@/types/sounds"; import type { SoundEffect, SavedSound } from "@/types/sounds";
import { storageService } from "@/services/storage/storage-service"; import { storageService } from "@/services/storage/service";
import { toast } from "sonner"; import { toast } from "sonner";
import { EditorCore } from "@/core"; import { EditorCore } from "@/core";
import { buildLibraryAudioElement } from "@/lib/timeline/element-utils"; import { buildLibraryAudioElement } from "@/lib/timeline/element-utils";