feat: update app structure and improve user experience; refactor media handling and enhance NAS integration

This commit is contained in:
bobbert committed 2026-04-15 01:06:05 +01:00
1 parent 4006cd93f1
commit ac9e4aee43
23 files changed
+1229 -643

No files matched your search

+66 -29
View File
@@ -1,7 +1,7 @@
const BACKEND_URL = process.env.BACKEND_URL || 'http://localhost:3001';
async function main() {
console.log('\n--- NAS Backend API Test ---');
console.log('\n--- NAS REST backend test ---');
console.log(`Backend: ${BACKEND_URL}\n`);
console.log('[1] Health check...');
@@ -9,38 +9,31 @@ async function main() {
const res = await fetch(`${BACKEND_URL}/api/health`);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data = await res.json();
console.log(` Status: ${data.status}, connections: ${data.activeConnections}, photo dir: ${data.defaultPhotoDir}\n`);
console.log(` Status: ${data.status}, activeSessions: ${data.activeSessions}, mode: ${data.nasMode}\n`);
} catch (err) {
console.log(` Failed: ${err.message}`);
console.log(' Start the backend first: cd ServerFiles && node server.js\n');
console.log(' Start the backend first: cd ServerFiles && npm start\n');
process.exit(1);
}
const host = process.env.NAS_HOST;
const host = process.env.NAS_HOST || '127.0.0.1';
const port = parseInt(process.env.NAS_PORT || '22', 10);
const username = process.env.NAS_USER;
const password = process.env.NAS_PASS;
const folder = process.env.NAS_FOLDER || '/home/user/photos';
if (!host || !username || !password) {
console.log('[2-4] Skipped — set NAS_HOST, NAS_USER, NAS_PASS to run connection tests.\n');
console.log('--- Tests complete (partial) ---\n');
return;
}
const username = process.env.NAS_USER || 'demo';
const password = process.env.NAS_PASS || 'demo';
let connectionToken = null;
console.log(`[2] SFTP connect to ${host}:${port}...`);
console.log(`[2] POST /api/nas/sessions (${host}, ${username})...`);
try {
const res = await fetch(`${BACKEND_URL}/api/sftp/connect`, {
const res = await fetch(`${BACKEND_URL}/api/nas/sessions`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ host, port, username, password }),
});
if (!res.ok) throw new Error(`HTTP ${res.status}: ${await res.text()}`);
const data = await res.json();
if (!data.success) throw new Error(data.error || 'Connect failed');
if (!data.success) throw new Error(data.error || 'Session failed');
connectionToken = data.connectionToken;
console.log(` Connected.\n`);
console.log(' Session OK.\n');
} catch (err) {
console.log(` Failed: ${err.message}\n`);
process.exit(1);
@@ -51,29 +44,73 @@ async function main() {
Authorization: `Bearer ${connectionToken}`,
};
console.log(`[3] List directory "${folder}"...`);
console.log('[3] GET /api/nas/media (list)...');
try {
const res = await fetch(`${BACKEND_URL}/api/sftp/list`, {
method: 'POST',
headers: authHeaders,
body: JSON.stringify({ path: folder }),
const res = await fetch(`${BACKEND_URL}/api/nas/media?limit=10&include=metadata`, {
headers: { Authorization: `Bearer ${connectionToken}` },
});
if (!res.ok) throw new Error(`HTTP ${res.status}: ${await res.text()}`);
const data = await res.json();
console.log(` Found ${data.count || 0} items in ${data.path}`);
(data.files || []).slice(0, 5).forEach((f, i) => {
console.log(` ${i + 1}. ${f.name} ${f.isDirectory ? '(dir)' : `(${f.size} bytes)`}`);
});
console.log();
console.log(` total=${data.total}, returned=${(data.items || []).length}\n`);
} catch (err) {
console.log(` Failed: ${err.message}\n`);
}
console.log('[4] Disconnect...');
console.log('[4] POST /api/nas/media (tiny PNG create)...');
let createdId = null;
try {
const res = await fetch(`${BACKEND_URL}/api/sftp/disconnect`, {
const onePxPng =
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==';
const res = await fetch(`${BACKEND_URL}/api/nas/media`, {
method: 'POST',
headers: authHeaders,
body: JSON.stringify({
filename: 'test-pixel.png',
mimeType: 'image/png',
base64: onePxPng,
metadata: { DateTimeOriginal: '2020:01:01 12:00:00', test: true },
}),
});
if (!res.ok) throw new Error(`HTTP ${res.status}: ${await res.text()}`);
const data = await res.json();
createdId = data.id;
console.log(` Created id=${createdId}\n`);
} catch (err) {
console.log(` Failed: ${err.message}\n`);
}
if (createdId) {
console.log('[5] GET /api/nas/media/:id ...');
try {
const res = await fetch(
`${BACKEND_URL}/api/nas/media/${encodeURIComponent(createdId)}?include=metadata`,
{ headers: { Authorization: `Bearer ${connectionToken}` } }
);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data = await res.json();
console.log(` filename=${data.filename}, byteLength=${data.byteLength}\n`);
} catch (err) {
console.log(` Failed: ${err.message}\n`);
}
console.log('[6] DELETE /api/nas/media/:id ...');
try {
const res = await fetch(`${BACKEND_URL}/api/nas/media/${encodeURIComponent(createdId)}`, {
method: 'DELETE',
headers: { Authorization: `Bearer ${connectionToken}` },
});
if (!res.ok && res.status !== 204) throw new Error(`HTTP ${res.status}`);
console.log(' Deleted.\n');
} catch (err) {
console.log(` Failed: ${err.message}\n`);
}
}
console.log('[7] DELETE /api/nas/sessions/current ...');
try {
const res = await fetch(`${BACKEND_URL}/api/nas/sessions/current`, {
method: 'DELETE',
headers: { Authorization: `Bearer ${connectionToken}` },
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data = await res.json();