Skip to content

Commit

Permalink
Version 0.14.1 Beta
Browse files Browse the repository at this point in the history
  • Loading branch information
redsolver committed Jun 6, 2023
1 parent 1b547cc commit ab5a3da
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 13 deletions.
60 changes: 58 additions & 2 deletions lib/page/settings/portal_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ class _PortalAuthSettingsPageState extends State<PortalAuthSettingsPage> {
SizedBox(
height: 8,
),
Row(
Wrap(
runSpacing: 10,
children: [
ElevatedButton(
onPressed: () async {
Expand Down Expand Up @@ -402,6 +403,8 @@ class _PortalAuthSettingsPageState extends State<PortalAuthSettingsPage> {
context.pop();
context.pop();
setState(() {});

quotaService.update();
} catch (e, st) {
context.pop();
showErrorDialog(context, e, st);
Expand Down Expand Up @@ -604,11 +607,19 @@ class _PortalAuthSettingsPageState extends State<PortalAuthSettingsPage> {
);
if (dialogRes == true) {
showLoadingDialog(context, 'Adding Sia Store...');
String workerApiUrl = workerApiUrlCtrl.text;
if (workerApiUrl.endsWith('/')) {
workerApiUrl =
workerApiUrl.substring(0, workerApiUrl.length - 1);
}
if (Uri.parse(workerApiUrl).path.length < 3) {
workerApiUrl += '/api/worker';
}

mySky.portalAccounts['_local'] = {
'store': {
'sia': {
'workerApiUrl': workerApiUrlCtrl.text,
'workerApiUrl': workerApiUrl,
'apiPassword': apiPasswordCtrl.text,
'downloadUrl': downloadUrlCtrl.text,
}
Expand Down Expand Up @@ -638,6 +649,8 @@ class _PortalAuthSettingsPageState extends State<PortalAuthSettingsPage> {

context.pop();
setState(() {});

quotaService.update();
}
} catch (e, st) {
showErrorDialog(context, e, st);
Expand All @@ -658,6 +671,49 @@ class _PortalAuthSettingsPageState extends State<PortalAuthSettingsPage> {
'Advanced',
style: titleTextStyle,
),
if (s5Node.store != null)
Padding(
padding: const EdgeInsets.only(top: 6),
child: Text(
'Important: If a local store is configured, all new files and metadata are uploaded to the local store.',
),
),
SizedBox(
height: 6,
),
Row(
children: [
ElevatedButton(
onPressed: () {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('Storage Services JSON'),
content: SizedBox(
width: dialogWidth,
height: dialogHeight,
child: SingleChildScrollView(
reverse: true,
child: SelectableText(
const JsonEncoder.withIndent(' ').convert(
mySky.portalAccounts,
),
style: const TextStyle(
fontFamily: 'monospace',
fontSize: 16,
),
),
),
),
),
);
},
child: Text(
'View full JSON',
),
),
],
),
SizedBox(
height: 12,
),
Expand Down
43 changes: 38 additions & 5 deletions lib/service/mysky.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ import 'package:lib5/storage_service.dart';
import 'package:lib5/util.dart';
import 'package:vup/service/base.dart';
import 'package:http/http.dart' as http;
import 'package:vup/service/s5_api_provider.dart';

class MySkyService extends VupService {
late final CryptoImplementation crypto;
late S5APIProviderWithRemoteUpload api;
late VupS5ApiProvider api;

late S5UserIdentity identity;

Expand All @@ -45,11 +46,24 @@ class MySkyService extends VupService {
's5-deleted-cids',
);

api = S5NodeAPIProviderWithRemoteUpload(s5Node, deletedCIDs: deletedCIDs);
api = VupS5ApiProvider(s5Node, deletedCIDs: deletedCIDs);
}

late Map portalAccounts;

List<String> get fileUploadServiceOrder =>
(portalAccounts['fileUploadServiceOrder'] ??
portalAccounts['uploadPortalOrder'])
?.cast<String>();

List<String> get metadataUploadServiceOrder =>
(portalAccounts['metadataUploadServiceOrder'] ??
portalAccounts['uploadPortalOrder'])
?.cast<String>();

List<String> get allUploadServices =>
(fileUploadServiceOrder + metadataUploadServiceOrder).toSet().toList();

Future<void> loadPortalAccounts() async {
final res = await hiddenDB.getJSON(
portalAccountsPath,
Expand Down Expand Up @@ -119,6 +133,16 @@ class MySkyService extends VupService {
await loadPortalAccounts();
}

void initS5Store() async {
try {
await s5Node.store!.init();
// TODO Configurable
s5Node.exposeStore = true;
} catch (e, st) {
logger.catched(e, st);
}
}

Future<void> setupPortalAccounts() async {
if (!dataBox.containsKey('portal_accounts')) {
return;
Expand All @@ -139,9 +163,8 @@ class MySkyService extends VupService {
node: s5Node,
);
s5Node.store = stores.values.first;
await s5Node.store!.init();
// TODO Configurable
s5Node.exposeStore = true;

initS5Store();
}
continue;
}
Expand Down Expand Up @@ -178,6 +201,7 @@ class MySkyService extends VupService {
for (final uc in storageServiceConfigs) {
connectToPortalNodes(uc);
}
refreshPortalAccounts();
}

void connectToPortalNodes(StorageServiceConfig pc) async {
Expand Down Expand Up @@ -210,6 +234,15 @@ class MySkyService extends VupService {

final isLoggedIn = Observable<bool?>(initialValue: null);

// TODO Apply changes
Future<void> refreshPortalAccounts() async {
try {
await loadPortalAccounts();
} catch (e, st) {
logger.catched(e, st);
}
}

Future<void> autoLogin() async {
info('autoLogin');
final authPayload = await loadAuthPayload();
Expand Down
5 changes: 5 additions & 0 deletions lib/service/pinning_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ class PinningService extends VupService {
}
}
}
if (s5Node.store != null) {
if (await s5Node.store!.contains(cid.hash)) {
await s5Node.store!.delete(cid.hash);
}
}
}
}
}
20 changes: 20 additions & 0 deletions lib/service/s5_api_provider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'dart:typed_data';

import 'package:hive/hive.dart';
import 'package:lib5/lib5.dart';
import 'package:s5_server/api.dart';
import 'package:s5_server/node.dart';

class VupS5ApiProvider extends S5NodeAPIProviderWithRemoteUpload {
VupS5ApiProvider(S5Node node, {required Box<Uint8List> deletedCIDs})
: super(node, deletedCIDs: deletedCIDs);

@override
Future<CID> uploadRawFile(Uint8List data) async {
if (node.store != null) {
return node.uploadRawFile(data);
} else {
return super.uploadRawFile(data);
}
}
}
3 changes: 2 additions & 1 deletion lib/view/active_queue_tasks.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:vup/app.dart';
import 'package:vup/queue/mdl.dart';
import 'package:vup/queue/sync.dart';
import 'package:vup/view/queue_task_manager.dart';

Expand Down Expand Up @@ -38,7 +39,7 @@ class _ActiveQueueTasksViewState extends State<ActiveQueueTasksView> {
Padding(
padding: const EdgeInsets.all(2.0),
child: Text(
'${task is SyncQueueTask ? 'Sync' : task.toString()} ${task.id}',
'${task is SyncQueueTask ? 'Sync' : task is MediaDownloadQueueTask ? 'Download' : task.toString()} ${task.id}',
),
),
if (task.progress > 0)
Expand Down
2 changes: 1 addition & 1 deletion lib/view/sidebar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ MimeType=x-scheme-handler/vup;
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
for (final key in mySky.portalAccounts['uploadPortalOrder'])
for (final key in mySky.allUploadServices)
QuotaWidget(context: context, portal: key),
if (quotaService.accountInfos.length < 2)
Padding(
Expand Down
2 changes: 1 addition & 1 deletion lib/widget/user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class _UserWidgetState extends State<UserWidget> {
overflow: TextOverflow.ellipsis,
),
Text(
'v0.14.0 Beta',
'v0.14.1 Beta',
// profile!.location ?? '',
overflow: TextOverflow.ellipsis,
),
Expand Down
2 changes: 1 addition & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1548,7 +1548,7 @@ packages:
description:
path: "."
ref: HEAD
resolved-ref: "891205e50145aa2900bb46724c899aaea1a0ce38"
resolved-ref: eeb1f8cee2d01a17dc2c0a7c5cdcf8729abae6e8
url: "https://github.com/s5-dev/S5.git"
source: git
version: "0.11.3"
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 0.14.0+1400
version: 0.14.1+1401

environment:
sdk: ">=2.13.0 <3.0.0"
Expand Down
2 changes: 1 addition & 1 deletion windows/runner/Runner.rc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ IDI_APP_ICON ICON "resources\\app_icon.ico"
#ifdef FLUTTER_BUILD_NAME
#define VERSION_AS_STRING #FLUTTER_BUILD_NAME
#else
#define VERSION_AS_STRING "0.14.0"
#define VERSION_AS_STRING "0.14.1"
#endif

VS_VERSION_INFO VERSIONINFO
Expand Down

0 comments on commit ab5a3da

Please sign in to comment.