Compare commits
No commits in common. "9841c3f29ca28784f1c300323fb65ba6d4411f9e" and "4f69ec5f1069a53bb05f509e39284c8a4bc38bb5" have entirely different histories.
9841c3f29c
...
4f69ec5f10
@ -74,8 +74,6 @@ private:
|
|||||||
[[nodiscard]] auto data_directory_exists(provider_type prov,
|
[[nodiscard]] auto data_directory_exists(provider_type prov,
|
||||||
std::string_view name) const -> bool;
|
std::string_view name) const -> bool;
|
||||||
|
|
||||||
void handle_get_available_locations(httplib::Response &res) const;
|
|
||||||
|
|
||||||
void handle_get_mount(const httplib::Request &req,
|
void handle_get_mount(const httplib::Request &req,
|
||||||
httplib::Response &res) const;
|
httplib::Response &res) const;
|
||||||
|
|
||||||
|
@ -168,10 +168,6 @@ handlers::handlers(mgmt_app_config *config, httplib::Server *server)
|
|||||||
: http_error_codes::internal_error;
|
: http_error_codes::internal_error;
|
||||||
});
|
});
|
||||||
|
|
||||||
server->Get("/api/v1/locations", [this](auto && /* req */, auto &&res) {
|
|
||||||
handle_get_available_locations(res);
|
|
||||||
});
|
|
||||||
|
|
||||||
server->Get("/api/v1/mount",
|
server->Get("/api/v1/mount",
|
||||||
[this](auto &&req, auto &&res) { handle_get_mount(req, res); });
|
[this](auto &&req, auto &&res) { handle_get_mount(req, res); });
|
||||||
|
|
||||||
@ -298,35 +294,6 @@ auto handlers::data_directory_exists(provider_type prov,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void handlers::handle_get_available_locations(httplib::Response &res) const {
|
|
||||||
#if defined(_WIN32)
|
|
||||||
constexpr const std::array<std::string_view, 26U> letters{
|
|
||||||
"A:", "B:", "C:", "D:", "E:", "F:", "G:", "H:", "I:",
|
|
||||||
"J:", "K:", "L:", "M:", "N:", "O:", "P:", "Q:", "R:",
|
|
||||||
"S:", "T:", "U:", "V:", "W:", "X:", "Y:", "Z:",
|
|
||||||
};
|
|
||||||
|
|
||||||
auto available = std::accumulate(
|
|
||||||
letters.begin(), letters.end(), std::vector<std::string_view>(),
|
|
||||||
[](auto &&vec, auto &&letter) -> std::vector<std::string_view> {
|
|
||||||
if (utils::file::directory{utils::path::combine(letter, {"\\"})}
|
|
||||||
.exists()) {
|
|
||||||
return vec;
|
|
||||||
}
|
|
||||||
|
|
||||||
vec.emplace_back(letter);
|
|
||||||
return vec;
|
|
||||||
});
|
|
||||||
|
|
||||||
res.set_content(nlohmann::json(available).dump(), "application/json");
|
|
||||||
#else // !defined(_WIN32)
|
|
||||||
res.set_content(nlohmann::json(std::vector<std::string_view>()).dump(),
|
|
||||||
"application/json");
|
|
||||||
#endif // defined(_WIN32)
|
|
||||||
|
|
||||||
res.status = http_error_codes::ok;
|
|
||||||
}
|
|
||||||
|
|
||||||
void handlers::handle_get_mount(const httplib::Request &req,
|
void handlers::handle_get_mount(const httplib::Request &req,
|
||||||
httplib::Response &res) const {
|
httplib::Response &res) const {
|
||||||
REPERTORY_USES_FUNCTION_NAME();
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
|
@ -101,32 +101,6 @@ class Mount with ChangeNotifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<String>> getAvailableLocations() async {
|
|
||||||
try {
|
|
||||||
final auth = await _auth.createAuth();
|
|
||||||
final response = await http.get(
|
|
||||||
Uri.parse(
|
|
||||||
Uri.encodeFull('${getBaseUri()}/api/v1/locations?auth=$auth'),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (response.statusCode == 401) {
|
|
||||||
_auth.logoff();
|
|
||||||
return <String>[];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (response.statusCode != 200) {
|
|
||||||
return <String>[];
|
|
||||||
}
|
|
||||||
|
|
||||||
return (jsonDecode(response.body) as List).cast<String>();
|
|
||||||
} catch (e) {
|
|
||||||
debugPrint('$e');
|
|
||||||
}
|
|
||||||
|
|
||||||
return <String>[];
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<String?> getMountLocation() async {
|
Future<String?> getMountLocation() async {
|
||||||
try {
|
try {
|
||||||
final auth = await _auth.createAuth();
|
final auth = await _auth.createAuth();
|
||||||
|
@ -149,67 +149,39 @@ class _MountWidgetState extends State<MountWidget> {
|
|||||||
return location;
|
return location;
|
||||||
}
|
}
|
||||||
|
|
||||||
final available = await mount.getAvailableLocations();
|
|
||||||
|
|
||||||
String? currentLocation;
|
String? currentLocation;
|
||||||
return await showDialog(
|
return await showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
return StatefulBuilder(
|
return AlertDialog(
|
||||||
builder: (context, setState) {
|
actions: [
|
||||||
return AlertDialog(
|
TextButton(
|
||||||
actions: [
|
child: const Text('Cancel'),
|
||||||
TextButton(
|
onPressed: () => Navigator.of(context).pop(null),
|
||||||
child: const Text('Cancel'),
|
),
|
||||||
onPressed: () => Navigator.of(context).pop(null),
|
TextButton(
|
||||||
),
|
child: const Text('OK'),
|
||||||
TextButton(
|
onPressed: () {
|
||||||
child: const Text('OK'),
|
final result = getSettingValidators('Path').firstWhereOrNull(
|
||||||
onPressed: () {
|
(validator) => !validator(currentLocation ?? ''),
|
||||||
final result = getSettingValidators(
|
);
|
||||||
'Path',
|
if (result != null) {
|
||||||
).firstWhereOrNull(
|
return displayErrorMessage(
|
||||||
(validator) => !validator(currentLocation ?? ''),
|
context,
|
||||||
);
|
"Mount location is not valid",
|
||||||
if (result != null) {
|
);
|
||||||
return displayErrorMessage(
|
}
|
||||||
context,
|
Navigator.of(context).pop(currentLocation);
|
||||||
"Mount location is not valid",
|
},
|
||||||
);
|
),
|
||||||
}
|
],
|
||||||
Navigator.of(context).pop(currentLocation);
|
content: TextField(
|
||||||
},
|
autofocus: true,
|
||||||
),
|
controller: TextEditingController(text: currentLocation),
|
||||||
],
|
inputFormatters: [FilteringTextInputFormatter.deny(RegExp(r'\s'))],
|
||||||
content:
|
onChanged: (value) => currentLocation = value,
|
||||||
available.isEmpty
|
),
|
||||||
? TextField(
|
title: const Text('Set Mount Location'),
|
||||||
autofocus: true,
|
|
||||||
controller: TextEditingController(
|
|
||||||
text: currentLocation,
|
|
||||||
),
|
|
||||||
inputFormatters: [
|
|
||||||
FilteringTextInputFormatter.deny(RegExp(r'\s')),
|
|
||||||
],
|
|
||||||
onChanged:
|
|
||||||
(value) => setState(() => currentLocation = value),
|
|
||||||
)
|
|
||||||
: DropdownButton<String>(
|
|
||||||
hint: const Text("Select drive"),
|
|
||||||
value: currentLocation,
|
|
||||||
onChanged:
|
|
||||||
(value) => setState(() => currentLocation = value),
|
|
||||||
items:
|
|
||||||
available.map<DropdownMenuItem<String>>((item) {
|
|
||||||
return DropdownMenuItem<String>(
|
|
||||||
value: item,
|
|
||||||
child: Text(item),
|
|
||||||
);
|
|
||||||
}).toList(),
|
|
||||||
),
|
|
||||||
title: const Text('Set Mount Location'),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user