feat: 主题切换 + 浅色模式适配,SFTP/批量命令/Webhook/仪表盘全面升级
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
package com.sshmanager.service;
|
||||
|
||||
import com.sshmanager.entity.Connection;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
/**
|
||||
* In-memory registry for quick-connect (ephemeral) SSH connections.
|
||||
* Entries are NOT persisted to the database and are cleaned up
|
||||
* when the WebSocket session closes.
|
||||
*/
|
||||
@Component
|
||||
public class QuickConnectionRegistry {
|
||||
|
||||
private final AtomicLong idGen = new AtomicLong(10_000_000);
|
||||
private final Map<Long, Entry> entries = new ConcurrentHashMap<>();
|
||||
|
||||
public Connection create(String host, String username, int port, Long userId) {
|
||||
long id = idGen.incrementAndGet();
|
||||
Connection conn = new Connection();
|
||||
conn.setId(id);
|
||||
conn.setUserId(userId);
|
||||
conn.setName(host + "-quick");
|
||||
conn.setHost(host);
|
||||
conn.setPort(port);
|
||||
conn.setUsername(username);
|
||||
conn.setAuthType(Connection.AuthType.PASSWORD);
|
||||
conn.setEncryptedPassword(null);
|
||||
conn.setCreatedAt(Instant.now());
|
||||
conn.setUpdatedAt(Instant.now());
|
||||
entries.put(id, new Entry(conn));
|
||||
return conn;
|
||||
}
|
||||
|
||||
public Connection get(Long id) {
|
||||
Entry entry = entries.get(id);
|
||||
return entry != null ? entry.connection : null;
|
||||
}
|
||||
|
||||
public void remove(Long id) {
|
||||
entries.remove(id);
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return entries.size();
|
||||
}
|
||||
|
||||
private static class Entry {
|
||||
final Connection connection;
|
||||
final long createdAt = System.currentTimeMillis();
|
||||
|
||||
Entry(Connection connection) {
|
||||
this.connection = connection;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user