Compare commits
4 Commits
d06b965dc1
...
e446757f7e
Author | SHA1 | Date | |
---|---|---|---|
e446757f7e | |||
513bc09944 | |||
a79e696315 | |||
26dbda290e |
@ -154,6 +154,7 @@ mtune
|
||||
musl-libc
|
||||
nana
|
||||
ncrypt
|
||||
nlohmann
|
||||
nlohmann_json
|
||||
nmakeprg
|
||||
nominmax
|
||||
|
@ -21,12 +21,14 @@
|
||||
*/
|
||||
#include "ui/handlers.hpp"
|
||||
|
||||
#include "app_config.hpp"
|
||||
#include "events/event_system.hpp"
|
||||
#include "rpc/common.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
#include "utils/base64.hpp"
|
||||
#include "utils/error_utils.hpp"
|
||||
#include "utils/string.hpp"
|
||||
#include "utils/file.hpp"
|
||||
#include "utils/path.hpp"
|
||||
#include <spdlog/fmt/bundled/base.h>
|
||||
|
||||
namespace repertory::ui {
|
||||
handlers::handlers(mgmt_app_config *config, httplib::Server *server)
|
||||
@ -69,6 +71,42 @@ handlers::handlers(mgmt_app_config *config, httplib::Server *server)
|
||||
res.status = http_error_codes::internal_error;
|
||||
});
|
||||
|
||||
server->Get("/api/v1/mount_list", [](auto && /* req */, auto &&res) {
|
||||
auto data_dir =
|
||||
utils::file::directory{app_config::get_root_data_directory()};
|
||||
|
||||
nlohmann::json result;
|
||||
|
||||
auto encrypt_dir = data_dir.get_directory("encrypt");
|
||||
if (encrypt_dir && encrypt_dir->get_file("config.json")) {
|
||||
result["encrypt"].emplace_back("encrypt");
|
||||
}
|
||||
|
||||
const auto process_dir = [&data_dir, &result](std::string_view name) {
|
||||
auto name_dir = data_dir.get_directory(name);
|
||||
if (not name_dir) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const auto &dir : name_dir->get_directories()) {
|
||||
if (not dir->get_file("config.json")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
result[name].emplace_back(
|
||||
utils::path::strip_to_file_name(dir->get_path()));
|
||||
}
|
||||
};
|
||||
|
||||
process_dir("remote");
|
||||
process_dir("s3");
|
||||
process_dir("sia");
|
||||
|
||||
fmt::println("{}", result.dump());
|
||||
res.set_content(result.dump(), "application/json");
|
||||
res.status = http_error_codes::ok;
|
||||
});
|
||||
|
||||
event_system::instance().start();
|
||||
|
||||
static std::atomic<httplib::Server *> this_server{server_};
|
||||
|
2
web/repertory/.cspell/words.txt
Normal file
2
web/repertory/.cspell/words.txt
Normal file
@ -0,0 +1,2 @@
|
||||
cupertino
|
||||
cupertinoicons
|
1
web/repertory/.gitignore
vendored
1
web/repertory/.gitignore
vendored
@ -43,3 +43,4 @@ app.*.map.json
|
||||
/android/app/debug
|
||||
/android/app/profile
|
||||
/android/app/release
|
||||
.flutter-companion
|
||||
|
@ -1 +1 @@
|
||||
const String APP_TITLE = "Repertory Management Portal";
|
||||
const String app_title = "Repertory Management Portal";
|
||||
|
6
web/repertory/lib/errors/duplicate_mount_exception.dart
Normal file
6
web/repertory/lib/errors/duplicate_mount_exception.dart
Normal file
@ -0,0 +1,6 @@
|
||||
class DuplicateMountException implements Exception {
|
||||
final String _name;
|
||||
const DuplicateMountException({required name}) : _name = name, super();
|
||||
|
||||
String get name => _name;
|
||||
}
|
@ -1,6 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'constants.dart' as constants;
|
||||
import 'package:repertory/constants.dart' as constants;
|
||||
import 'package:repertory/models/mount_list.dart';
|
||||
import 'package:repertory/widgets/mount_list_widget.dart';
|
||||
|
||||
void main() {
|
||||
runApp(const MyApp());
|
||||
@ -12,11 +15,11 @@ class MyApp extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: constants.APP_TITLE,
|
||||
title: constants.app_title,
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepOrange),
|
||||
),
|
||||
home: const MyHomePage(title: 'Flutter Demo Home Page'),
|
||||
home: const MyHomePage(title: constants.app_title),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -38,11 +41,9 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
),
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[const Text('TODO-Everything')],
|
||||
),
|
||||
body: ChangeNotifierProvider(
|
||||
create: (context) => MountList(),
|
||||
child: MountListWidget(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -0,0 +1,55 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:repertory/errors/duplicate_mount_exception.dart';
|
||||
import 'package:repertory/types/mount_config.dart';
|
||||
|
||||
class MountList with ChangeNotifier {
|
||||
MountList() {
|
||||
_fetch();
|
||||
}
|
||||
|
||||
List<MountConfig> _items = [];
|
||||
|
||||
UnmodifiableListView get items => UnmodifiableListView(_items);
|
||||
|
||||
Future<void> _fetch() async {
|
||||
final response = await http.get(
|
||||
Uri.parse('${Uri.base.origin}/api/v1/mount_list'),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
List<MountConfig> items = [];
|
||||
|
||||
var data = jsonDecode(response.body);
|
||||
data.forEach((key, value) {
|
||||
items.addAll(
|
||||
value.map((name) => MountConfig.fromJson(key, name)).toList(),
|
||||
);
|
||||
});
|
||||
items.sort((a, b) => a.name.compareTo(b.name));
|
||||
_items = items;
|
||||
|
||||
notifyListeners();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void add(MountConfig config) {
|
||||
var item = _items.firstWhereOrNull((cfg) => cfg.name == config.name);
|
||||
if (item != null) {
|
||||
throw DuplicateMountException(name: config.name);
|
||||
}
|
||||
|
||||
_items.add(config);
|
||||
_items.sort((a, b) => a.name.compareTo(b.name));
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void remove(String name) {
|
||||
_items.removeWhere((item) => item.name == name);
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
class MountConfig {
|
||||
final String _name;
|
||||
final String _type;
|
||||
MountConfig({required name, required type}) : _name = name, _type = type;
|
||||
|
||||
String get name => _name;
|
||||
String get type => _type;
|
||||
|
||||
factory MountConfig.fromJson(String type, String name) {
|
||||
return MountConfig(name: name, type: type);
|
||||
}
|
||||
}
|
27
web/repertory/lib/widgets/mount_list_widget.dart
Normal file
27
web/repertory/lib/widgets/mount_list_widget.dart
Normal file
@ -0,0 +1,27 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:repertory/models/mount_list.dart';
|
||||
import 'package:repertory/widgets/mount_widget.dart';
|
||||
|
||||
class MountListWidget extends StatefulWidget {
|
||||
const MountListWidget({super.key});
|
||||
|
||||
@override
|
||||
State<MountListWidget> createState() => _MountListWidgetState();
|
||||
}
|
||||
|
||||
class _MountListWidgetState extends State<MountListWidget> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Consumer<MountList>(
|
||||
builder: (context, mountList, widget) {
|
||||
return ListView.builder(
|
||||
itemBuilder: (context, idx) {
|
||||
return MountWidget(mountConfig: mountList.items[idx]);
|
||||
},
|
||||
itemCount: mountList.items.length,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
18
web/repertory/lib/widgets/mount_widget.dart
Normal file
18
web/repertory/lib/widgets/mount_widget.dart
Normal file
@ -0,0 +1,18 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:repertory/types/mount_config.dart';
|
||||
|
||||
class MountWidget extends StatelessWidget {
|
||||
final MountConfig mountConfig;
|
||||
const MountWidget({super.key, required this.mountConfig});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Card(
|
||||
child: Container(
|
||||
height: 40,
|
||||
color: Colors.blue,
|
||||
child: Text('${mountConfig.type} ${mountConfig.name}'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -34,7 +34,7 @@ packages:
|
||||
source: hosted
|
||||
version: "1.1.2"
|
||||
collection:
|
||||
dependency: transitive
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: collection
|
||||
sha256: "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76"
|
||||
@ -75,6 +75,22 @@ packages:
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
http:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: http
|
||||
sha256: fe7ab022b76f3034adc518fb6ea04a82387620e19977665ea18d30a1cf43442f
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.3.0"
|
||||
http_parser:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: http_parser
|
||||
sha256: "178d74305e7866013777bab2c3d8726205dc5a4dd935297175b19a23a2e66571"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.1.2"
|
||||
leak_tracker:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -131,6 +147,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.16.0"
|
||||
nested:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: nested
|
||||
sha256: "03bac4c528c64c95c722ec99280375a6f2fc708eec17c7b3f07253b626cd2a20"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.0"
|
||||
path:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -139,6 +163,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.9.1"
|
||||
provider:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: provider
|
||||
sha256: c8a055ee5ce3fd98d6fc872478b03823ffdb448699c6ebdbbc71d59b596fd48c
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.1.2"
|
||||
sky_engine:
|
||||
dependency: transitive
|
||||
description: flutter
|
||||
@ -192,6 +224,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.7.4"
|
||||
typed_data:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: typed_data
|
||||
sha256: f9049c039ebfeb4cf7a7104a675823cd72dba8297f264b6637062516699fa006
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.4.0"
|
||||
vector_math:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -208,6 +248,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "15.0.0"
|
||||
web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: web
|
||||
sha256: "868d88a33d8a87b18ffc05f9f030ba328ffefba92d6c127917a2ba740f9cfe4a"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.1"
|
||||
sdks:
|
||||
dart: ">=3.7.0 <4.0.0"
|
||||
flutter: ">=3.18.0-18.0.pre.54"
|
||||
|
@ -1,5 +1,5 @@
|
||||
name: repertory
|
||||
description: "A new Flutter project."
|
||||
description: "Repertory Management Portal"
|
||||
# The following line prevents the package from being accidentally published to
|
||||
# pub.dev using `flutter pub publish`. This is preferred for private packages.
|
||||
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
||||
@ -34,6 +34,9 @@ dependencies:
|
||||
# The following adds the Cupertino Icons font to your application.
|
||||
# Use with the CupertinoIcons class for iOS style icons.
|
||||
cupertino_icons: ^1.0.8
|
||||
collection: ^1.19.1
|
||||
http: ^1.3.0
|
||||
provider: ^6.1.2
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
Loading…
x
Reference in New Issue
Block a user