Skip to content

Commit

Permalink
Merge branch 'usb-firmware' of github.com:kevvz/Omi into usb-firmware
Browse files Browse the repository at this point in the history
  • Loading branch information
kevvz committed Oct 8, 2024
2 parents 1517a24 + d21f90d commit 1ef35b4
Show file tree
Hide file tree
Showing 73 changed files with 3,430 additions and 2,291 deletions.
3 changes: 2 additions & 1 deletion Friend/firmware/firmware_v1.0/src/sdcard.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ int get_offset()
fs_close(&read_file);
uint32_t *offset_ptr = (uint32_t*)buf;
printk("get offset is %d\n",offset_ptr[0]);
fs_close(&read_file);

return offset_ptr[0];
}
}
108 changes: 37 additions & 71 deletions app/lib/backend/http/api/memories.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,20 @@ import 'dart:io';

import 'package:flutter/material.dart';
import 'package:friend_private/backend/http/shared.dart';
import 'package:friend_private/backend/schema/geolocation.dart';
import 'package:friend_private/backend/schema/memory.dart';
import 'package:friend_private/backend/schema/structured.dart';
import 'package:friend_private/backend/schema/transcript_segment.dart';
import 'package:friend_private/env/env.dart';
import 'package:http/http.dart' as http;
import 'package:instabug_flutter/instabug_flutter.dart';
import 'package:path/path.dart';
import 'package:tuple/tuple.dart';

Future<bool> migrateMemoriesToBackend(List<dynamic> memories) async {
Future<CreateMemoryResponse?> processInProgressMemory() async {
var response = await makeApiCall(
url: '${Env.apiBaseUrl}v1/migration/memories',
headers: {'Content-Type': 'application/json'},
method: 'POST',
body: jsonEncode(memories),
);
debugPrint('migrateMemoriesToBackend: ${response?.body}');
return response?.statusCode == 200;
}

Future<CreateMemoryResponse?> createMemoryServer({
required DateTime startedAt,
required DateTime finishedAt,
required List<TranscriptSegment> transcriptSegments,
Geolocation? geolocation,
List<Tuple2<String, String>> photos = const [],
bool triggerIntegrations = true,
String? language,
File? audioFile,
String? source,
String? processingMemoryId,
}) async {
var response = await makeApiCall(
url: '${Env.apiBaseUrl}v1/memories?trigger_integrations=$triggerIntegrations&source=$source',
url: '${Env.apiBaseUrl}v2/memories',
headers: {},
method: 'POST',
body: jsonEncode({
'started_at': startedAt.toUtc().toIso8601String(),
'finished_at': finishedAt.toUtc().toIso8601String(),
'transcript_segments': transcriptSegments.map((segment) => segment.toJson()).toList(),
'geolocation': geolocation?.toJson(),
'photos': photos.map((photo) => {'base64': photo.item1, 'description': photo.item2}).toList(),
'source': transcriptSegments.isNotEmpty ? 'friend' : 'openglass',
'language': language, // maybe determine auto?
'processing_memory_id': processingMemoryId,
// 'audio_base64_url': audioFile != null ? await wavToBase64Url(audioFile.path) : null,
}),
body: jsonEncode({}),
);
if (response == null) return null;
debugPrint('createMemoryServer: ${response.body}');
Expand All @@ -64,40 +30,28 @@ Future<CreateMemoryResponse?> createMemoryServer({
level: NonFatalExceptionLevel.info,
userAttributes: {
'response': response.body,
'transcriptSegments': TranscriptSegment.segmentsAsString(transcriptSegments),
},
);
}
return null;
}

Future<List<ServerMemory>> getMemories({int limit = 50, int offset = 0}) async {
Future<List<ServerMemory>> getMemories({int limit = 50, int offset = 0, List<MemoryStatus> statuses = const []}) async {
var response = await makeApiCall(
url: '${Env.apiBaseUrl}v1/memories?limit=$limit&offset=$offset', headers: {}, method: 'GET', body: '');
url:
'${Env.apiBaseUrl}v1/memories?limit=$limit&offset=$offset&statuses=${statuses.map((val) => val.toString().split(".").last).join(",")}',
headers: {},
method: 'GET',
body: '');
if (response == null) return [];
if (response.statusCode == 200) {
// decode body bytes to utf8 string and then parse json so as to avoid utf8 char issues
var body = utf8.decode(response.bodyBytes);
var memories = (jsonDecode(body) as List<dynamic>).map((memory) => ServerMemory.fromJson(memory)).toList();
debugPrint('getMemories length: ${memories.length}');
return memories;
}
return [];
}

Future<List<ServerProcessingMemory>> getProcessingMemories(
{List<String> filterIds = const [], int limit = 5, int offset = 0}) async {
var url = '${Env.apiBaseUrl}v1/processing-memories?filter_ids=${filterIds.join(",")}&limit=$limit&offset=$offset';
var response = await makeApiCall(url: url, headers: {}, method: 'GET', body: '');
if (response == null) return [];
if (response.statusCode == 200) {
// decode body bytes to utf8 string and then parse json so as to avoid utf8 char issues
var body = utf8.decode(response.bodyBytes);
var memories =
(jsonDecode(body)["result"] as List<dynamic>).map((memory) => ServerProcessingMemory.fromJson(memory)).toList();
return memories;
} else {
debugPrint("[API-Error] $url - ${response.statusCode}");
debugPrint('getMemories error ${response.statusCode}');
}
return [];
}
Expand Down Expand Up @@ -144,21 +98,6 @@ Future<ServerMemory?> getMemoryById(String memoryId) async {
return null;
}

Future<ServerProcessingMemory?> getProcessingMemoryById(String id) async {
var response = await makeApiCall(
url: '${Env.apiBaseUrl}v1/processing-memories/$id',
headers: {},
method: 'GET',
body: '',
);
if (response == null) return null;
debugPrint('getProcessingMemoryById: ${response.body}');
if (response.statusCode == 200) {
return ServerProcessingMemory.fromJson(jsonDecode(response.body));
}
return null;
}

Future<List<MemoryPhoto>> getMemoryPhotos(String memoryId) async {
var response = await makeApiCall(
url: '${Env.apiBaseUrl}v1/memories/$memoryId/photos',
Expand Down Expand Up @@ -312,3 +251,30 @@ Future<List<ServerMemory>> sendStorageToBackend(File file, String sdCardDateTime
return [];
}
}

Future<bool> syncLocalFiles(List<File> files) async {
var request = http.MultipartRequest(
'POST',
Uri.parse('${Env.apiBaseUrl}v1/sync-local-files'),
);
for (var file in files) {
request.files.add(await http.MultipartFile.fromPath('files', file.path, filename: basename(file.path)));
}
request.headers.addAll({'Authorization': await getAuthHeader()});

try {
var streamedResponse = await request.send();
var response = await http.Response.fromStream(streamedResponse);

if (response.statusCode == 200) {
debugPrint('syncLocalFile Response body: ${jsonDecode(response.body)}');
return true;
} else {
debugPrint('Failed to upload sample. Status code: ${response.statusCode}');
throw Exception('Failed to upload sample. Status code: ${response.statusCode}');
}
} catch (e) {
debugPrint('An error occurred uploadSample: $e');
throw Exception('An error occurred uploadSample: $e');
}
}
68 changes: 0 additions & 68 deletions app/lib/backend/http/api/processing_memories.dart

This file was deleted.

20 changes: 20 additions & 0 deletions app/lib/backend/http/api/users.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,28 @@ import 'dart:convert';
import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:friend_private/backend/http/shared.dart';
import 'package:friend_private/backend/schema/geolocation.dart';
import 'package:friend_private/backend/schema/person.dart';
import 'package:friend_private/env/env.dart';
import 'package:instabug_flutter/instabug_flutter.dart';

Future<bool> updateUserGeolocation({required Geolocation geolocation}) async {
var response = await makeApiCall(
url: '${Env.apiBaseUrl}v1/users/geolocation',
headers: {},
method: 'PATCH',
body: jsonEncode(geolocation.toJson()),
);
if (response == null) return false;
if (response.statusCode == 200) return true;
CrashReporting.reportHandledCrash(
Exception('Failed to update user geolocation'),
StackTrace.current,
level: NonFatalExceptionLevel.info,
userAttributes: {'response': response.body},
);
return false;
}

Future<bool> deleteAccount() async {
var response = await makeApiCall(
Expand Down
17 changes: 14 additions & 3 deletions app/lib/backend/preferences.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import 'dart:convert';

import 'package:collection/collection.dart';
import 'package:flutter/foundation.dart';
import 'package:friend_private/backend/schema/bt_device/bt_device.dart';
import 'package:friend_private/backend/schema/memory.dart';
import 'package:friend_private/backend/schema/message.dart';
import 'package:friend_private/backend/schema/bt_device/bt_device.dart';
import 'package:friend_private/backend/schema/person.dart';
import 'package:friend_private/backend/schema/plugin.dart';
import 'package:friend_private/backend/schema/transcript_segment.dart';
import 'package:friend_private/services/wals.dart';
import 'package:shared_preferences/shared_preferences.dart';

class SharedPreferencesUtil {
Expand Down Expand Up @@ -383,9 +385,9 @@ class SharedPreferencesUtil {

String get calendarId => getString('calendarId') ?? '';

set calendarType(String value) => saveString('calendarType', value); // auto, manual
set calendarType(String value) => saveString('calendarType2', value); // auto, manual (only for now)

String get calendarType => getString('calendarType') ?? 'auto';
String get calendarType => getString('calendarType2') ?? 'manual';

bool get firstTranscriptMade => getBool('firstTranscriptMade') ?? false;

Expand Down Expand Up @@ -419,4 +421,13 @@ class SharedPreferencesUtil {

bool get locationPermissionRequested => getBool('locationPermissionRequested') ?? false;

set wals(List<Wal> wals) {
final List<String> value = wals.map((e) => jsonEncode(e.toJson())).toList();
saveStringList('v3/wals', value);
}

List<Wal> get wals {
final List<String> value = getStringList('v3/wals') ?? [];
return Wal.fromJsonList(value.map((e) => jsonDecode(e)).toList());
}
}
Loading

0 comments on commit 1ef35b4

Please sign in to comment.