This commit is contained in:
@ -154,6 +154,7 @@ mtune
|
|||||||
musl-libc
|
musl-libc
|
||||||
nana
|
nana
|
||||||
ncrypt
|
ncrypt
|
||||||
|
nlohmann
|
||||||
nlohmann_json
|
nlohmann_json
|
||||||
nmakeprg
|
nmakeprg
|
||||||
nominmax
|
nominmax
|
||||||
|
@ -21,12 +21,14 @@
|
|||||||
*/
|
*/
|
||||||
#include "ui/handlers.hpp"
|
#include "ui/handlers.hpp"
|
||||||
|
|
||||||
|
#include "app_config.hpp"
|
||||||
#include "events/event_system.hpp"
|
#include "events/event_system.hpp"
|
||||||
#include "rpc/common.hpp"
|
#include "rpc/common.hpp"
|
||||||
#include "types/repertory.hpp"
|
#include "types/repertory.hpp"
|
||||||
#include "utils/base64.hpp"
|
|
||||||
#include "utils/error_utils.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 {
|
namespace repertory::ui {
|
||||||
handlers::handlers(mgmt_app_config *config, httplib::Server *server)
|
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;
|
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();
|
event_system::instance().start();
|
||||||
|
|
||||||
static std::atomic<httplib::Server *> this_server{server_};
|
static std::atomic<httplib::Server *> this_server{server_};
|
||||||
|
@ -1,13 +1,42 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:collection/collection.dart';
|
import 'package:collection/collection.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
import 'package:repertory/errors/duplicate_mount_exception.dart';
|
import 'package:repertory/errors/duplicate_mount_exception.dart';
|
||||||
import 'package:repertory/types/mount_config.dart';
|
import 'package:repertory/types/mount_config.dart';
|
||||||
|
|
||||||
class MountList with ChangeNotifier {
|
class MountList with ChangeNotifier {
|
||||||
final List<MountConfig> _items = [MountConfig(name: "test")];
|
MountList() {
|
||||||
|
_fetch();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<MountConfig> _items = [];
|
||||||
|
|
||||||
UnmodifiableListView get items => UnmodifiableListView(_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) {
|
void add(MountConfig config) {
|
||||||
var item = _items.firstWhereOrNull((cfg) => cfg.name == config.name);
|
var item = _items.firstWhereOrNull((cfg) => cfg.name == config.name);
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
@ -16,6 +45,7 @@ class MountList with ChangeNotifier {
|
|||||||
|
|
||||||
_items.add(config);
|
_items.add(config);
|
||||||
_items.sort((a, b) => a.name.compareTo(b.name));
|
_items.sort((a, b) => a.name.compareTo(b.name));
|
||||||
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,12 @@
|
|||||||
class MountConfig {
|
class MountConfig {
|
||||||
final String _name;
|
final String _name;
|
||||||
MountConfig({required name}) : _name = name;
|
final String _type;
|
||||||
|
MountConfig({required name, required type}) : _name = name, _type = type;
|
||||||
|
|
||||||
String get name => _name;
|
String get name => _name;
|
||||||
|
String get type => _type;
|
||||||
|
|
||||||
|
factory MountConfig.fromJson(String type, String name) {
|
||||||
|
return MountConfig(name: name, type: type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ class MountWidget extends StatelessWidget {
|
|||||||
child: Container(
|
child: Container(
|
||||||
height: 40,
|
height: 40,
|
||||||
color: Colors.blue,
|
color: Colors.blue,
|
||||||
child: Text(mountConfig.name),
|
child: Text('${mountConfig.type} ${mountConfig.name}'),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -5,10 +5,10 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: async
|
name: async
|
||||||
sha256: d2872f9c19731c2e5f10444b14686eb7cc85c76274bd6c16e1816bff9a3bab63
|
sha256: "758e6d74e971c3e5aceb4110bfd6698efc7f501675bcfe0c775459a8140750eb"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.12.0"
|
version: "2.13.0"
|
||||||
boolean_selector:
|
boolean_selector:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -53,10 +53,10 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: fake_async
|
name: fake_async
|
||||||
sha256: "6a95e56b2449df2273fd8c45a662d6947ce1ebb7aafe80e550a3f68297f3cacc"
|
sha256: "5368f224a74523e8d2e7399ea1638b37aecfca824a3cc4dfdf77bf1fa905ac44"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.3.2"
|
version: "1.3.3"
|
||||||
flutter:
|
flutter:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description: flutter
|
description: flutter
|
||||||
@ -75,14 +75,30 @@ packages:
|
|||||||
description: flutter
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
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:
|
leak_tracker:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: leak_tracker
|
name: leak_tracker
|
||||||
sha256: c35baad643ba394b40aac41080300150a4f08fd0fd6a10378f8f7c6bc161acec
|
sha256: "6bb818ecbdffe216e81182c2f0714a2e62b593f4a4f13098713ff1685dfb6ab0"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "10.0.8"
|
version: "10.0.9"
|
||||||
leak_tracker_flutter_testing:
|
leak_tracker_flutter_testing:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -208,6 +224,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.7.4"
|
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:
|
vector_math:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -220,10 +244,18 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: vm_service
|
name: vm_service
|
||||||
sha256: "0968250880a6c5fe7edc067ed0a13d4bae1577fe2771dcf3010d52c4a9d3ca14"
|
sha256: ddfa8d30d89985b96407efce8acbdd124701f96741f2d981ca860662f1c0dc02
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "14.3.1"
|
version: "15.0.0"
|
||||||
|
web:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: web
|
||||||
|
sha256: "868d88a33d8a87b18ffc05f9f030ba328ffefba92d6c127917a2ba740f9cfe4a"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "1.1.1"
|
||||||
sdks:
|
sdks:
|
||||||
dart: ">=3.7.0 <4.0.0"
|
dart: ">=3.7.0 <4.0.0"
|
||||||
flutter: ">=3.18.0-18.0.pre.54"
|
flutter: ">=3.18.0-18.0.pre.54"
|
||||||
|
@ -35,6 +35,7 @@ dependencies:
|
|||||||
# Use with the CupertinoIcons class for iOS style icons.
|
# Use with the CupertinoIcons class for iOS style icons.
|
||||||
cupertino_icons: ^1.0.8
|
cupertino_icons: ^1.0.8
|
||||||
collection: ^1.19.1
|
collection: ^1.19.1
|
||||||
|
http: ^1.3.0
|
||||||
provider: ^6.1.2
|
provider: ^6.1.2
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
|
Reference in New Issue
Block a user