vdi-cloud/terminal/kiosk-shell/src/desktop_service.cpp

76 lines
2.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "desktop_service.h"
#include "desktop_store.h"
namespace vdi {
void DesktopService::login(const QString& username, const QString& password, AuthCallback callback) {
// 本地演示认证:账号与密码非空即通过。
// 正式版本替换为 /api/v1/terminal/session/login(SN+用户身份校验)。
AuthResult result;
if (username.trimmed().isEmpty() || password.isEmpty()) {
result.ok = false;
result.message = QStringLiteral("请输入用户名和密码");
} else {
result.ok = true;
result.displayName = username.trimmed();
currentUser_ = username.trimmed();
}
if (callback) {
callback(result);
}
}
void DesktopService::listDesktops(DesktopListCallback callback) {
// 桌面与连接参数来自本地连接配置(现场可配);
// 正式版本替换为 /api/v1/terminal/session/desktops(按用户绑定返回)。
std::vector<DesktopInfo> desktops = DesktopStore::load();
if (callback) {
callback(std::move(desktops), QString());
}
}
void DesktopService::createTicket(const QString& desktopId, TicketCallback callback) {
// 本地演示票据:由连接配置构造。
// 正式版本替换为 /api/v1/terminal/session/connect-ticket(短期一次性票据)。
ConnectionTicket ticket;
ticket.desktopId = desktopId;
QString error;
listDesktops([&ticket, &error, desktopId](std::vector<DesktopInfo> list, const QString& err) {
if (!err.isEmpty()) {
error = err;
return;
}
for (const DesktopInfo& d : list) {
if (d.id != desktopId) {
continue;
}
if (d.state != DesktopState::kAvailable) {
error = QStringLiteral("桌面 %1 尚未配置连接地址,请先在“设置”中完成配置")
.arg(d.name);
return;
}
ticket.endpoint = d.endpoint;
ticket.app = d.app;
ticket.width = d.width;
ticket.height = d.height;
ticket.fps = d.fps;
return;
}
if (error.isEmpty() && ticket.endpoint.isEmpty()) {
error = QStringLiteral("桌面不存在");
}
});
if (callback) {
callback(ticket, error);
}
}
void DesktopService::logout() {
currentUser_.clear();
}
} // namespace vdi