Compare commits
3 Commits
576e2b68fc
...
v0.3.0
| Author | SHA1 | Date | |
|---|---|---|---|
| ff0652b992 | |||
| a3fc5e2940 | |||
| 6ec569f6e6 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -5,6 +5,8 @@
|
||||
# Логи
|
||||
logs/
|
||||
*.log
|
||||
out.txt
|
||||
.build_timing
|
||||
|
||||
# Выходные файлы
|
||||
output/
|
||||
|
||||
@@ -15,6 +15,7 @@ pub struct AccessConfig {
|
||||
pub smb_url: Option<String>,
|
||||
pub smb_user: Option<String>,
|
||||
pub smb_pass: Option<String>,
|
||||
pub smb_domain: Option<String>,
|
||||
pub synology_path: Option<String>,
|
||||
}
|
||||
|
||||
@@ -45,6 +46,7 @@ impl AccessConfig {
|
||||
smb_url,
|
||||
smb_user: env::var(format!("{}_SMB_USER", prefix)).ok(),
|
||||
smb_pass: env::var(format!("{}_SMB_PASS", prefix)).ok(),
|
||||
smb_domain: env::var(format!("{}_SMB_DOMAIN", prefix)).ok(),
|
||||
synology_path,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -13,16 +13,31 @@ fn smb_url_to_unc(url_str: &str) -> Result<UncPath> {
|
||||
let host = url
|
||||
.host_str()
|
||||
.ok_or_else(|| anyhow!("No host in SMB URL"))?;
|
||||
let path_segments: Vec<&str> = url.path().trim_matches('/').split('/').collect();
|
||||
let share = path_segments.first().cloned().unwrap_or("IPC$");
|
||||
|
||||
// Берём сырой путь
|
||||
let raw_path = url.path().trim_start_matches('/');
|
||||
// Декодируем каждый сегмент с помощью urlencoding (уже есть в зависимостях)
|
||||
let decoded_segments: Vec<String> = raw_path
|
||||
.split('/')
|
||||
.filter(|s| !s.is_empty())
|
||||
.map(|s| {
|
||||
urlencoding::decode(s)
|
||||
.unwrap_or_else(|_| s.to_string().into())
|
||||
.into_owned()
|
||||
})
|
||||
.collect();
|
||||
|
||||
if decoded_segments.is_empty() {
|
||||
return Err(anyhow!("No path segments in SMB URL"));
|
||||
}
|
||||
|
||||
let share = &decoded_segments[0];
|
||||
let base = UncPath::from_str(&format!("\\\\{}\\{}", host, share))
|
||||
.map_err(|e| anyhow!("Invalid UNC: {}", e))?;
|
||||
let mut full = base.clone();
|
||||
for &segment in path_segments.iter().skip(1) {
|
||||
if !segment.is_empty() {
|
||||
for segment in decoded_segments.iter().skip(1) {
|
||||
full = full.with_path(segment);
|
||||
}
|
||||
}
|
||||
Ok(full)
|
||||
}
|
||||
|
||||
@@ -71,7 +86,11 @@ impl FileAccess for LocalFileAccess {
|
||||
|
||||
async fn read_file(&self, filename: &str) -> Result<Vec<u8>> {
|
||||
let path = self.full_path(filename);
|
||||
tokio::fs::read(&path).await.map_err(Into::into)
|
||||
log::debug!("LocalFileAccess reading file: {}", path);
|
||||
tokio::fs::read(&path).await.map_err(|e| {
|
||||
log::error!("Failed to read local file {}: {}", path, e);
|
||||
anyhow::anyhow!(e)
|
||||
})
|
||||
}
|
||||
|
||||
async fn write_file(&self, filename: &str, data: &[u8]) -> Result<()> {
|
||||
@@ -92,6 +111,7 @@ pub struct SmbAccessConfig {
|
||||
pub url: String,
|
||||
pub user: Option<String>,
|
||||
pub password: Option<String>,
|
||||
pub domain: Option<String>,
|
||||
}
|
||||
|
||||
pub struct SmbFileAccess {
|
||||
@@ -107,39 +127,54 @@ impl SmbFileAccess {
|
||||
let base_unc = smb_url_to_unc(&self.config.url)?;
|
||||
let client = Client::new(ClientConfig::default());
|
||||
|
||||
if let (Some(user), Some(pass)) = (&self.config.user, &self.config.password) {
|
||||
client.share_connect(&base_unc, user, pass.clone()).await?;
|
||||
} else {
|
||||
let (user, pass) = match (&self.config.user, &self.config.password) {
|
||||
(Some(u), Some(p)) => (u.clone(), p.clone()),
|
||||
_ => {
|
||||
client.share_connect(&base_unc, "", "".to_string()).await?;
|
||||
return Ok((client, base_unc));
|
||||
}
|
||||
};
|
||||
|
||||
// Если задан домен, добавляем его к имени пользователя: DOMAIN\username
|
||||
let full_user = match &self.config.domain {
|
||||
Some(d) if !d.is_empty() => format!("{}\\{}", d, user),
|
||||
_ => user,
|
||||
};
|
||||
|
||||
client.share_connect(&base_unc, &full_user, pass).await?;
|
||||
Ok((client, base_unc))
|
||||
}
|
||||
|
||||
fn full_unc_path(&self, base: &UncPath, filename: &str) -> UncPath {
|
||||
let segments: Vec<&str> = filename.split('/').filter(|s| !s.is_empty()).collect();
|
||||
let mut path = base.clone();
|
||||
for seg in segments {
|
||||
path = path.with_path(seg);
|
||||
}
|
||||
path
|
||||
/// Построить полный UNC путь к файлу, гарантируя один слеш между базой и именем
|
||||
fn make_file_unc(base: &UncPath, filename: &str) -> Result<UncPath> {
|
||||
let base_str = base.to_string();
|
||||
let clean_base = base_str.trim_end_matches('\\');
|
||||
// Заменяем все прямые слеши на обратные для UNC
|
||||
let sanitized = filename.replace('/', "\\");
|
||||
let clean_filename = sanitized.trim_start_matches('\\');
|
||||
let full = format!("{}\\{}", clean_base, clean_filename);
|
||||
UncPath::from_str(&full).map_err(|e| anyhow!("Invalid file UNC: {}", e))
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl FileAccess for SmbFileAccess {
|
||||
async fn list_files(&self) -> Result<Vec<String>> {
|
||||
// SMB list directory пока не реализован в текущем API,
|
||||
// оставим заглушку для будущей доработки
|
||||
// Заглушка
|
||||
Ok(Vec::new())
|
||||
}
|
||||
|
||||
async fn read_file(&self, filename: &str) -> Result<Vec<u8>> {
|
||||
let (client, base_unc) = self.connect().await?;
|
||||
let file_path = self.full_unc_path(&base_unc, filename);
|
||||
let file_path = Self::make_file_unc(&base_unc, filename)?;
|
||||
log::info!("SMB reading file: {:?}", file_path);
|
||||
|
||||
let args =
|
||||
FileCreateArgs::make_open_existing(FileAccessMask::new().with_generic_read(true));
|
||||
let resource = client.create_file(&file_path, &args).await?;
|
||||
let resource = client.create_file(&file_path, &args).await.map_err(|e| {
|
||||
log::error!("Failed to open SMB file {:?}: {}", file_path, e);
|
||||
anyhow::anyhow!("Failed to open SMB file: {}", e)
|
||||
})?;
|
||||
let file = resource.unwrap_file();
|
||||
|
||||
let file_size = file.get_len().await? as usize;
|
||||
@@ -153,11 +188,20 @@ impl FileAccess for SmbFileAccess {
|
||||
|
||||
async fn write_file(&self, filename: &str, data: &[u8]) -> Result<()> {
|
||||
let (client, base_unc) = self.connect().await?;
|
||||
let file_path = self.full_unc_path(&base_unc, filename);
|
||||
let file_path = Self::make_file_unc(&base_unc, filename)?;
|
||||
log::info!("SMB writing file: {:?}", file_path);
|
||||
|
||||
let args =
|
||||
let access_mask = FileAccessMask::new()
|
||||
.with_generic_write(true)
|
||||
.with_generic_read(true);
|
||||
let mut args =
|
||||
FileCreateArgs::make_overwrite(FileAttributes::default(), CreateOptions::default());
|
||||
let resource = client.create_file(&file_path, &args).await?;
|
||||
args.desired_access = access_mask;
|
||||
|
||||
let resource = client.create_file(&file_path, &args).await.map_err(|e| {
|
||||
log::error!("Failed to create SMB file {:?}: {}", file_path, e);
|
||||
anyhow::anyhow!("Failed to create SMB file: {}", e)
|
||||
})?;
|
||||
let remote_file = resource.unwrap_file();
|
||||
|
||||
remote_file.write_at(data, 0).await?;
|
||||
@@ -165,9 +209,12 @@ impl FileAccess for SmbFileAccess {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn delete_file(&self, _filename: &str) -> Result<()> {
|
||||
// Удаление будет добавлено позже
|
||||
Err(anyhow!("Delete not yet implemented for SMB"))
|
||||
async fn delete_file(&self, filename: &str) -> Result<()> {
|
||||
log::warn!(
|
||||
"SMB delete not supported – file left at source: {}",
|
||||
filename
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,14 +28,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Tabs -->
|
||||
<div class="tabs">
|
||||
<button class="tab-btn active" data-tab="jobs">Задания</button>
|
||||
<button class="tab-btn" data-tab="videos">Видео</button>
|
||||
</div>
|
||||
|
||||
<!-- Tab: Задания (оригинальный интерфейс полностью сохранён) -->
|
||||
<div id="tab-jobs" class="tab-content active">
|
||||
<!-- Action Bar -->
|
||||
<div class="action-bar">
|
||||
<button class="btn btn-primary" onclick="generateJobs()">
|
||||
<i class="fas fa-play"></i> Generate New Jobs
|
||||
@@ -55,8 +48,10 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Stats Grid -->
|
||||
<div class="stats-grid" id="statsGrid"></div>
|
||||
|
||||
<!-- Filter Bar -->
|
||||
<div class="filter-bar">
|
||||
<div class="search-wrapper">
|
||||
<i class="fas fa-search"></i>
|
||||
@@ -70,6 +65,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Table -->
|
||||
<div class="table-container">
|
||||
<table id="jobsTable">
|
||||
<thead>
|
||||
@@ -89,11 +85,13 @@
|
||||
<th data-column="uid" onclick="sortTable('uid')">
|
||||
UID <i class="fas fa-sort"></i>
|
||||
</th>
|
||||
<th>Preview</th>
|
||||
<th>Move</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="jobsTableBody">
|
||||
<tr>
|
||||
<td colspan="5">
|
||||
<td colspan="7">
|
||||
<div class="empty-state">
|
||||
<i class="fas fa-spinner fa-spin"></i>
|
||||
<p>Loading jobs...</p>
|
||||
@@ -105,19 +103,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Tab: Видео -->
|
||||
<div id="tab-videos" class="tab-content">
|
||||
<div class="action-bar">
|
||||
<button class="btn btn-primary" onclick="loadVideos()">
|
||||
<i class="fas fa-sync-alt"></i> Обновить список
|
||||
</button>
|
||||
<div class="status-message" id="videosStatusMessage">
|
||||
<span>Видео не загружены</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="video-list" id="videoList"></div>
|
||||
</div>
|
||||
|
||||
<!-- Video Player Modal -->
|
||||
<div id="playerModal" class="modal">
|
||||
<div class="modal-content">
|
||||
@@ -125,7 +110,6 @@
|
||||
<video id="videoPlayer" controls style="width:100%; max-height:70vh;"></video>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// ========== ОРИГИНАЛЬНЫЙ КОД (Задания) ==========
|
||||
@@ -228,23 +212,33 @@
|
||||
function renderJobs(jobs) {
|
||||
const tbody = document.getElementById('jobsTableBody');
|
||||
if (jobs.length === 0) {
|
||||
tbody.innerHTML = '<tr><td colspan="5"><div class="empty-state"><i class="fas fa-inbox"></i><p>No jobs found</p></div></td></tr>';
|
||||
tbody.innerHTML = '<tr><td colspan="7"><div class="empty-state"><i class="fas fa-inbox"></i><p>No jobs found</p></div></td></tr>';
|
||||
return;
|
||||
}
|
||||
tbody.innerHTML = jobs.map(job => {
|
||||
const stateClass = getStateClass(job.state);
|
||||
const created = formatDateTime(job.created_at);
|
||||
const updated = formatDateTime(job.updated_at);
|
||||
const previewBtn = job.state === 'finished'
|
||||
? `<button class="btn btn-outline btn-sm" onclick="playVideo('${escapeHtml(job.outfile_name)}')"><i class="fas fa-play"></i></button>`
|
||||
: '';
|
||||
// Заглушка‑иконка, обновится асинхронно
|
||||
const moveIcon = job.state === 'finished'
|
||||
? `<span class="move-icon" data-file="${escapeHtml(job.outfile_name)}"><i class="fas fa-spinner fa-spin"></i></span>`
|
||||
: '';
|
||||
return `<tr>
|
||||
<td><div class="job-filename" title="${escapeHtml(job.outfile_name)}">${escapeHtml(job.outfile_name)}</div></td>
|
||||
<td><span class="badge ${stateClass}">${escapeHtml(job.state)}</span></td>
|
||||
<td class="datetime">${created}</td>
|
||||
<td class="datetime">${updated}</td>
|
||||
<td class="uid" title="${escapeHtml(job.uid)}">${job.uid.substring(0, 10)}...</td>
|
||||
<td>${previewBtn}</td>
|
||||
<td>${moveIcon}</td>
|
||||
</tr>`;
|
||||
}).join('');
|
||||
// Запускаем проверку статусов после рендера
|
||||
updateMoveStatuses();
|
||||
}
|
||||
|
||||
function escapeHtml(text) { if (!text) return ''; const div = document.createElement('div'); div.textContent = text; return div.innerHTML; }
|
||||
function getStateClass(state) {
|
||||
const classes = { 'finished': 'badge-finished', 'started': 'badge-started', 'processing': 'badge-processing', 'queued': 'badge-queued', 'error': 'badge-error', 'pending': 'badge-pending' };
|
||||
@@ -277,66 +271,98 @@
|
||||
filteredJobs = allJobs.filter(job => job.outfile_name.toLowerCase().includes(filter) || job.uid.toLowerCase().includes(filter));
|
||||
sortAndRender();
|
||||
}
|
||||
async function generateJobs() { /* ... тот же код ... */ }
|
||||
async function stopAllJobs() { /* ... тот же код ... */ }
|
||||
async function cleanupJobs() { /* ... тот же код ... */ }
|
||||
function setStatus(type, message) { /* ... тот же код ... */ }
|
||||
function startAutoRefresh() { /* ... тот же код ... */ }
|
||||
function stopAutoRefresh() { /* ... тот же код ... */ }
|
||||
function resetCountdown() { /* ... тот же код ... */ }
|
||||
|
||||
// Скопируйте оригинальные реализации generateJobs, stopAllJobs, cleanupJobs, setStatus, startAutoRefresh, stopAutoRefresh, resetCountdown (они у вас уже были)
|
||||
// Я не стал дублировать весь код, чтобы не загромождать ответ. Просто вставьте их из вашего предыдущего файла.
|
||||
// Оригинальные реализации generateJobs, stopAllJobs, cleanupJobs, setStatus, startAutoRefresh, stopAutoRefresh, resetCountdown
|
||||
async function generateJobs() {
|
||||
setStatus('loading', 'Generating jobs...');
|
||||
try {
|
||||
const response = await fetch('/api/generate', { method: 'POST' });
|
||||
if (response.ok) {
|
||||
setStatus('success', 'Job generation started');
|
||||
setTimeout(() => refreshJobs(), 5000);
|
||||
} else {
|
||||
const text = await response.text();
|
||||
setStatus('error', `Error: ${text}`);
|
||||
}
|
||||
} catch (err) {
|
||||
setStatus('error', `Error: ${err}`);
|
||||
}
|
||||
}
|
||||
|
||||
// ========== НОВЫЙ КОД: Вкладки ==========
|
||||
document.querySelectorAll('.tab-btn').forEach(btn => {
|
||||
btn.addEventListener('click', () => {
|
||||
document.querySelectorAll('.tab-btn').forEach(b => b.classList.remove('active'));
|
||||
document.querySelectorAll('.tab-content').forEach(c => c.classList.remove('active'));
|
||||
btn.classList.add('active');
|
||||
document.getElementById('tab-' + btn.dataset.tab).classList.add('active');
|
||||
if (btn.dataset.tab === 'videos') loadVideos();
|
||||
});
|
||||
});
|
||||
async function stopAllJobs() {
|
||||
if (!confirm('Are you sure you want to stop all active jobs?')) return;
|
||||
setStatus('loading', 'Stopping all jobs...');
|
||||
try {
|
||||
const response = await fetch('/api/jobs/stop-all', { method: 'POST' });
|
||||
if (response.ok) {
|
||||
setStatus('success', 'All jobs stopped');
|
||||
refreshJobs();
|
||||
} else {
|
||||
const text = await response.text();
|
||||
setStatus('error', `Error: ${text}`);
|
||||
}
|
||||
} catch (err) {
|
||||
setStatus('error', `Error: ${err}`);
|
||||
}
|
||||
}
|
||||
|
||||
async function cleanupJobs() {
|
||||
setStatus('loading', 'Cleaning up finished jobs...');
|
||||
try {
|
||||
const response = await fetch('/api/cleanup', { method: 'POST' });
|
||||
if (response.ok) {
|
||||
setStatus('success', 'Cleanup completed');
|
||||
await refreshJobs();
|
||||
} else {
|
||||
const text = await response.text();
|
||||
setStatus('error', `Error: ${text}`);
|
||||
}
|
||||
} catch (err) {
|
||||
setStatus('error', `Error: ${err}`);
|
||||
}
|
||||
}
|
||||
|
||||
function setStatus(type, message) {
|
||||
const el = document.getElementById('statusMessage');
|
||||
const icons = {
|
||||
loading: '<span class="spinner"></span>',
|
||||
success: '<i class="fas fa-check-circle" style="color: var(--accent-success);"></i>',
|
||||
error: '<i class="fas fa-times-circle" style="color: var(--accent-danger);"></i>'
|
||||
};
|
||||
el.innerHTML = `${icons[type] || ''} <span>${message}</span>`;
|
||||
}
|
||||
|
||||
function startAutoRefresh() {
|
||||
stopAutoRefresh();
|
||||
autoRefreshTimer = setInterval(() => { refreshJobs(); resetCountdown(); }, 60000);
|
||||
countdownTimer = setInterval(() => {
|
||||
countdownValue--;
|
||||
document.getElementById('refreshCountdown').textContent = countdownValue;
|
||||
if (countdownValue <= 0) countdownValue = 60;
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
function stopAutoRefresh() {
|
||||
if (autoRefreshTimer) clearInterval(autoRefreshTimer);
|
||||
if (countdownTimer) clearInterval(countdownTimer);
|
||||
}
|
||||
|
||||
function resetCountdown() {
|
||||
countdownValue = 60;
|
||||
document.getElementById('refreshCountdown').textContent = countdownValue;
|
||||
}
|
||||
|
||||
// ========== НОВЫЙ КОД: Видео ==========
|
||||
async function loadVideos() {
|
||||
try {
|
||||
const response = await fetch('/api/videos');
|
||||
if (!response.ok) throw new Error(await response.text());
|
||||
const videos = await response.json();
|
||||
renderVideoList(videos);
|
||||
document.getElementById('videosStatusMessage').innerHTML = `<span>Найдено файлов: ${videos.length}</span>`;
|
||||
} catch (e) {
|
||||
document.getElementById('videosStatusMessage').innerHTML = `<span style="color:red;">Ошибка: ${e.message}</span>`;
|
||||
}
|
||||
}
|
||||
|
||||
function renderVideoList(videos) {
|
||||
const container = document.getElementById('videoList');
|
||||
if (videos.length === 0) {
|
||||
container.innerHTML = '<p>Видеофайлы не найдены.</p>';
|
||||
return;
|
||||
}
|
||||
container.innerHTML = videos.map(name => `
|
||||
<div class="video-item">
|
||||
<span class="video-name" title="${name}">${name}</span>
|
||||
<button class="btn btn-outline btn-sm" onclick="playVideo('${name}')"><i class="fas fa-play"></i> Смотреть</button>
|
||||
<button class="btn btn-primary btn-sm" onclick="moveVideo('${name}')"><i class="fas fa-share"></i> Перенести</button>
|
||||
</div>
|
||||
`).join('');
|
||||
}
|
||||
|
||||
function playVideo(filename) {
|
||||
const player = document.getElementById('videoPlayer');
|
||||
player.src = '/api/videos/' + encodeURIComponent(filename);
|
||||
document.getElementById('playerModal').style.display = 'flex';
|
||||
document.getElementById('playerModal').classList.add('active');
|
||||
}
|
||||
function closePlayer() {
|
||||
const player = document.getElementById('videoPlayer');
|
||||
player.pause();
|
||||
player.src = '';
|
||||
document.getElementById('playerModal').style.display = 'none';
|
||||
document.getElementById('playerModal').classList.remove('active');
|
||||
}
|
||||
|
||||
async function moveVideo(filename) {
|
||||
@@ -345,12 +371,32 @@
|
||||
const response = await fetch('/api/videos/' + encodeURIComponent(filename) + '/move?remove=true', { method: 'POST' });
|
||||
if (!response.ok) throw new Error(await response.text());
|
||||
alert('Файл успешно перемещён.');
|
||||
loadVideos();
|
||||
refreshJobs(); // обновим список, возможно, файл исчезнет
|
||||
} catch (e) {
|
||||
alert('Ошибка перемещения: ' + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
async function updateMoveStatuses() {
|
||||
const icons = document.querySelectorAll('.move-icon');
|
||||
for (const icon of icons) {
|
||||
const filename = icon.dataset.file;
|
||||
try {
|
||||
const resp = await fetch('/api/videos/' + encodeURIComponent(filename) + '/status');
|
||||
const status = await resp.json();
|
||||
const exists = status.exists_in_dest;
|
||||
const subfolder = status.subfolder;
|
||||
if (exists) {
|
||||
icon.innerHTML = `<i class="fas fa-check-circle" style="color: var(--accent-success);" title="Already in ${subfolder}"></i>`;
|
||||
} else {
|
||||
icon.innerHTML = `<button class="btn btn-primary btn-sm" onclick="moveVideo('${escapeHtml(filename)}')"><i class="fas fa-share"></i></button>`;
|
||||
}
|
||||
} catch (e) {
|
||||
icon.innerHTML = `<i class="fas fa-question-circle" title="Status unknown"></i>`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ========== ИНИЦИАЛИЗАЦИЯ ==========
|
||||
initTheme();
|
||||
refreshJobs();
|
||||
|
||||
@@ -553,3 +553,47 @@ tr:hover {
|
||||
margin-left: 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Модальное окно плеера */
|
||||
.modal {
|
||||
display: none;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
background: rgba(0, 0, 0, 0.8);
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.modal.active {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
background: var(--bg-secondary);
|
||||
border-radius: 12px;
|
||||
padding: 20px;
|
||||
max-width: 90vw;
|
||||
box-shadow: var(--shadow-lg);
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.modal .close {
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
right: 16px;
|
||||
font-size: 28px;
|
||||
color: var(--text-primary);
|
||||
cursor: pointer;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
/* Кнопки в таблице (уменьшенный размер) */
|
||||
.btn-sm {
|
||||
padding: 4px 8px;
|
||||
font-size: 12px;
|
||||
gap: 4px;
|
||||
}
|
||||
60
src/web.rs
60
src/web.rs
@@ -121,6 +121,7 @@ pub async fn run_web_server(config: Config) -> anyhow::Result<()> {
|
||||
.route("/api/videos", get(list_videos))
|
||||
.route("/api/videos/{filename}", get(stream_video))
|
||||
.route("/api/videos/{filename}/move", post(move_video))
|
||||
.route("/api/videos/{filename}/status", get(get_video_status))
|
||||
.layer(TraceLayer::new_for_http())
|
||||
.with_state(state);
|
||||
|
||||
@@ -144,12 +145,15 @@ async fn create_file_access(
|
||||
let url = access_config.smb_url.as_ref().unwrap().clone();
|
||||
let user = access_config.smb_user.clone();
|
||||
let password = access_config.smb_pass.clone();
|
||||
let domain = access_config.smb_domain.clone();
|
||||
let smb_config = SmbAccessConfig {
|
||||
url,
|
||||
user,
|
||||
password,
|
||||
domain,
|
||||
};
|
||||
Ok(Arc::new(SmbFileAccess::new(smb_config)))
|
||||
let access: Arc<dyn FileAccess> = Arc::new(SmbFileAccess::new(smb_config));
|
||||
Ok(access)
|
||||
}
|
||||
AccessType::Synology => {
|
||||
let mut client = SynologyClient::new(&nas_config.nas_fqdn);
|
||||
@@ -305,6 +309,7 @@ async fn stream_video(
|
||||
State(state): State<AppState>,
|
||||
headers: axum::http::HeaderMap,
|
||||
) -> Result<impl IntoResponse, AppError> {
|
||||
log::info!("Stream video requested: {}", filename);
|
||||
let file_data = state
|
||||
.source_access
|
||||
.read_file(&filename)
|
||||
@@ -357,26 +362,48 @@ async fn move_video(
|
||||
.source_access
|
||||
.read_file(&filename)
|
||||
.await
|
||||
.map_err(|e| AppError(StatusCode::NOT_FOUND, e.to_string()))?;
|
||||
.map_err(|e| AppError(StatusCode::NOT_FOUND, format!("File not found: {}", e)))?;
|
||||
|
||||
// Определяем целевую подпапку по имени файла
|
||||
let subfolder = if filename.contains("_Today") {
|
||||
"Today"
|
||||
} else if filename.contains("_Tomorrow") {
|
||||
"Tomorrow"
|
||||
} else {
|
||||
"Data"
|
||||
};
|
||||
let dest_filename = format!("{}/{}", subfolder, filename);
|
||||
|
||||
// Проверяем, существует ли уже файл в целевой папке
|
||||
if state.dest_access.read_file(&dest_filename).await.is_ok() {
|
||||
return Ok((
|
||||
StatusCode::OK,
|
||||
format!("File {} already exists in {} folder.", filename, subfolder),
|
||||
));
|
||||
}
|
||||
|
||||
// Запись
|
||||
state
|
||||
.dest_access
|
||||
.write_file(&filename, &data)
|
||||
.write_file(&dest_filename, &data)
|
||||
.await
|
||||
.map_err(|e| AppError(StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?;
|
||||
|
||||
let mut message = format!(
|
||||
"File {} moved successfully to {} folder.",
|
||||
filename, subfolder
|
||||
);
|
||||
|
||||
if remove {
|
||||
state
|
||||
.source_access
|
||||
.delete_file(&filename)
|
||||
.await
|
||||
.map_err(|e| AppError(StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?;
|
||||
message.push_str(" Please delete the source file manually if needed.");
|
||||
}
|
||||
|
||||
Ok((
|
||||
StatusCode::OK,
|
||||
format!("File {} moved successfully", filename),
|
||||
))
|
||||
Ok((StatusCode::OK, message))
|
||||
}
|
||||
|
||||
// Шрифты Font Awesome
|
||||
@@ -401,6 +428,25 @@ async fn fa_brands_woff2() -> impl IntoResponse {
|
||||
)
|
||||
}
|
||||
|
||||
async fn get_video_status(
|
||||
Path(filename): Path<String>,
|
||||
State(state): State<AppState>,
|
||||
) -> Result<Json<serde_json::Value>, AppError> {
|
||||
let subfolder = if filename.contains("_Today") {
|
||||
"Today"
|
||||
} else if filename.contains("_Tomorrow") {
|
||||
"Tomorrow"
|
||||
} else {
|
||||
"Data"
|
||||
};
|
||||
let dest_filename = format!("{}/{}", subfolder, filename);
|
||||
let exists = state.dest_access.read_file(&dest_filename).await.is_ok();
|
||||
Ok(Json(serde_json::json!({
|
||||
"exists_in_dest": exists,
|
||||
"subfolder": subfolder
|
||||
})))
|
||||
}
|
||||
|
||||
struct AppError(StatusCode, String);
|
||||
|
||||
impl IntoResponse for AppError {
|
||||
|
||||
Reference in New Issue
Block a user