Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
josancamon19 committed Nov 8, 2024
2 parents de6d5dc + bb69a14 commit 77328fc
Show file tree
Hide file tree
Showing 53 changed files with 2,103 additions and 117 deletions.
72 changes: 70 additions & 2 deletions app/lib/backend/http/api/apps.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:convert';
import 'dart:developer';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:friend_private/backend/http/shared.dart';
Expand All @@ -8,9 +9,12 @@ import 'package:friend_private/backend/schema/app.dart';
import 'package:friend_private/env/env.dart';
import 'package:instabug_flutter/instabug_flutter.dart';

import 'package:http/http.dart' as http;
import 'package:path/path.dart';

Future<List<App>> retrieveApps() async {
var response = await makeApiCall(
url: '${Env.apiBaseUrl}v2/plugins',
url: '${Env.apiBaseUrl}v3/plugins',
headers: {},
body: '',
method: 'GET',
Expand Down Expand Up @@ -67,7 +71,7 @@ Future<void> reviewApp(String appId, double score, {String review = ''}) async {

Future<String> getAppMarkdown(String appMarkdownPath) async {
var response = await makeApiCall(
url: 'https://raw.githubusercontent.com/BasedHardware/Omi/main$appMarkdownPath',
url: appMarkdownPath,
method: 'GET',
headers: {},
body: '',
Expand Down Expand Up @@ -133,3 +137,67 @@ Future<double> getAppMoneyMade(String pluginId) async {
return 0;
}
}

Future<bool> submitAppServer(File file, Map<String, dynamic> appData) async {
var request = http.MultipartRequest(
'POST',
Uri.parse('${Env.apiBaseUrl}v3/plugins'),
);
request.files.add(await http.MultipartFile.fromPath('file', file.path, filename: basename(file.path)));
request.headers.addAll({'Authorization': await getAuthHeader()});
request.fields.addAll({'plugin_data': jsonEncode(appData)});
print(jsonEncode(appData));
try {
var streamedResponse = await request.send();
var response = await http.Response.fromStream(streamedResponse);

if (response.statusCode == 200) {
debugPrint('submitAppServer Response body: ${jsonDecode(response.body)}');
return true;
} else {
debugPrint('Failed to submit app. Status code: ${response.statusCode}');
return false;
}
} catch (e) {
debugPrint('An error occurred submitAppServer: $e');
return false;
}
}

Future<List<Category>> getAppCategories() async {
var response = await makeApiCall(
url: '${Env.apiBaseUrl}v1/plugin-categories',
headers: {},
body: '',
method: 'GET',
);
try {
if (response == null || response.statusCode != 200) return [];
log('getAppCategories: ${response.body}');
var res = jsonDecode(response.body);
return Category.fromJsonList(res);
} catch (e, stackTrace) {
debugPrint(e.toString());
CrashReporting.reportHandledCrash(e, stackTrace);
return [];
}
}

Future<List<TriggerEvent>> getTriggerEventsServer() async {
var response = await makeApiCall(
url: '${Env.apiBaseUrl}v1/plugin-triggers',
headers: {},
body: '',
method: 'GET',
);
try {
if (response == null || response.statusCode != 200) return [];
log('getTriggerEvents: ${response.body}');
var res = jsonDecode(response.body);
return TriggerEvent.fromJsonList(res);
} catch (e, stackTrace) {
debugPrint(e.toString());
CrashReporting.reportHandledCrash(e, stackTrace);
return [];
}
}
4 changes: 4 additions & 0 deletions app/lib/backend/preferences.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ class SharedPreferencesUtil {

set showSummarizeConfirmation(bool value) => saveBool('showSummarizeConfirmation', value);

bool get showSubmitAppConfirmation => getBool('showSubmitAppConfirmation') ?? true;

set showSubmitAppConfirmation(bool value) => saveBool('showSubmitAppConfirmation', value);

String get recordingsLanguage => getString('recordingsLanguage') ?? 'en';

set recordingsLanguage(String value) => saveString('recordingsLanguage', value);
Expand Down
65 changes: 64 additions & 1 deletion app/lib/backend/schema/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ class App {
String description;
String image;
Set<String> capabilities;
bool private;

String? memoryPrompt;
String? chatPrompt;
Expand Down Expand Up @@ -172,6 +173,7 @@ class App {
required this.ratingCount,
required this.enabled,
required this.deleted,
this.private = false,
});

String? getRatingAvg() => ratingAvg?.toStringAsFixed(1);
Expand Down Expand Up @@ -203,10 +205,17 @@ class App {
deleted: json['deleted'] ?? false,
enabled: json['enabled'] ?? false,
installs: json['installs'] ?? 0,
private: json['private'] ?? json['id'].toString().contains('private'),
);
}

String getImageUrl() => 'https://raw.githubusercontent.com/BasedHardware/Omi/main$image';
String getImageUrl() {
if (image.startsWith('http')) {
return image;
} else {
return 'https://raw.githubusercontent.com/BasedHardware/Omi/main$image';
}
}

Map<String, dynamic> toJson() {
return {
Expand All @@ -231,3 +240,57 @@ class App {

static List<App> fromJsonList(List<dynamic> jsonList) => jsonList.map((e) => App.fromJson(e)).toList();
}

class Category {
String title;
String id;
Category({
required this.title,
required this.id,
});

factory Category.fromJson(Map<String, dynamic> json) {
return Category(
title: json['title'],
id: json['id'],
);
}

toJson() {
return {
'title': title,
'id': id,
};
}

static List<Category> fromJsonList(List<dynamic> jsonList) {
return jsonList.map((e) => Category.fromJson(e)).toList();
}
}

class TriggerEvent {
String title;
String id;
TriggerEvent({
required this.title,
required this.id,
});

factory TriggerEvent.fromJson(Map<String, dynamic> json) {
return TriggerEvent(
title: json['title'],
id: json['id'],
);
}

toJson() {
return {
'title': title,
'id': id,
};
}

static List<TriggerEvent> fromJsonList(List<dynamic> jsonList) {
return jsonList.map((e) => TriggerEvent.fromJson(e)).toList();
}
}
6 changes: 6 additions & 0 deletions app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:friend_private/env/prod_env.dart';
import 'package:friend_private/firebase_options_dev.dart' as dev;
import 'package:friend_private/firebase_options_prod.dart' as prod;
import 'package:friend_private/flavors.dart';
import 'package:friend_private/pages/apps/providers/add_app_provider.dart';
import 'package:friend_private/pages/home/page.dart';
import 'package:friend_private/pages/memory_detail/memory_detail_provider.dart';
import 'package:friend_private/pages/onboarding/wrapper.dart';
Expand Down Expand Up @@ -190,6 +191,11 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
),
ChangeNotifierProvider(create: (context) => CalenderProvider()),
ChangeNotifierProvider(create: (context) => DeveloperModeProvider()),
ChangeNotifierProxyProvider<AppProvider, AddAppProvider>(
create: (context) => AddAppProvider(),
update: (BuildContext context, value, AddAppProvider? previous) =>
(previous?..setAppProvider(value)) ?? AddAppProvider(),
),
],
builder: (context, child) {
return WithForegroundTask(
Expand Down
Loading

0 comments on commit 77328fc

Please sign in to comment.