Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: temporary directory web #700

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions app/lib/screens/app_onboarding/preview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,17 @@ class Preview {
// delete study subscription and progress
if (containsQueryPair('cmd', 'reset')) {
if (selectedStudyObjectId != null) {
final StudySubject subject = await SupabaseQuery.getById<StudySubject>(
selectedStudyObjectId!,
selectedColumns: [
'*',
'study!study_subject_studyId_fkey(*)',
'subject_progress(*)',
],
ibrahimozkn marked this conversation as resolved.
Show resolved Hide resolved
);
subject.delete();
final List<StudySubject> subjects =
await SupabaseQuery.getAll<StudySubject>();

final List<StudySubject> subjectsToDelete = subjects
.where((subject) =>
subject.userId == Supabase.instance.client.auth.currentUser!.id,)
.toList();

subjectsToDelete.forEach((subject) async {
await subject.delete();
});
ibrahimozkn marked this conversation as resolved.
Show resolved Hide resolved
deleteActiveStudyReference();
selectedStudyObjectId = '';
}
Expand Down
11 changes: 7 additions & 4 deletions app/lib/util/debug_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,13 @@ class DebugScreen {
}

static Future<void> _deleteCacheDir() async {
final cacheDir = await getTemporaryDirectory();

if (cacheDir.existsSync()) {
cacheDir.deleteSync(recursive: true);
try {
final cacheDir = await getTemporaryDirectory();
if (cacheDir.existsSync()) {
cacheDir.deleteSync(recursive: true);
}
} catch (e) {
StudyULogger.error(e);
}
}

Expand Down
27 changes: 22 additions & 5 deletions app/lib/util/temporary_storage_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,25 @@ class TemporaryStorageHandler {
}

static Future<Directory> _getMultimodalTempDirectory() async {
final tempAppData = await getTemporaryDirectory();
final multimodalTempDirectory =
Directory("${tempAppData.path}/multimodal-temp");
await multimodalTempDirectory.create(recursive: true);
return multimodalTempDirectory;
try {
final tempAppData = await getTemporaryDirectory();
final multimodalTempDirectory =
Directory("${tempAppData.path}/multimodal-temp");

if (!await multimodalTempDirectory.exists()) {
await multimodalTempDirectory.create(recursive: true);
}

return multimodalTempDirectory;
} catch (e) {
StudyULogger.error("Failed to create multimodal temp directory: $e");

final fallbackDirectory =
Directory("${Directory.systemTemp.path}/multimodal-temp-fallback");

await fallbackDirectory.create(recursive: true);
return fallbackDirectory;
}
}

static Future<Directory> _getMultimodalUploadDirectory() async {
Expand Down Expand Up @@ -66,6 +80,7 @@ class TemporaryStorageHandler {

Future<FutureBlobFile> getStagingAudio() async {
final temporaryMultimodalDirectory = await _getMultimodalTempDirectory();

final fileName = _buildFileName();
final localFilePath = path.join(
temporaryMultimodalDirectory.path,
Expand All @@ -75,6 +90,7 @@ class TemporaryStorageHandler {
TemporaryStorageHandler._audioFileType,
].join(),
);

final futureBlobId =
[fileName, TemporaryStorageHandler._audioFileType].join();
return FutureBlobFile(localFilePath, futureBlobId);
Expand All @@ -91,6 +107,7 @@ class TemporaryStorageHandler {
TemporaryStorageHandler._imageFileType,
].join(),
);

final futureBlobId =
[fileName, TemporaryStorageHandler._imageFileType].join();
return FutureBlobFile(localFilePath, futureBlobId);
Expand Down
Loading