Files
Dushnilin bb1de1fd83 Merge branch 'temp-upstream-rebrand' into main
Resolves merge conflicts:
- install.sh, build.sh, .github/workflows/build.yml: Reverted to Dushnilin's versions to avoid installing SourceForge mirrors.
- fe-app-tachyon: Resolved type, formatting and copyOutbound conflicts, keeping both Dushnilin's custom features and ushan0v's frontend performance optimizations.
- backend: Kept Dushnilin's ucode refactorings, Telegram bot integration, and release repository URL (Dushnilin/tachyon) while merging updates.uc cache format v8 & persistent cache format v7.
- tests: Merged tests from both branches, preserving ucode -L wrappers for local test execution.
2026-07-14 08:01:45 +03:00

114 lines
3.1 KiB
JavaScript
Raw Permalink 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.
import 'dotenv/config';
import chokidar from 'chokidar';
import SFTPClient from 'ssh2-sftp-client';
import path from 'path';
import fs from 'fs';
import glob from 'fast-glob';
const sftp = new SFTPClient();
const config = {
host: process.env.SFTP_HOST,
port: Number(process.env.SFTP_PORT || 22),
username: process.env.SFTP_USER,
...(process.env.SFTP_PRIVATE_KEY
? { privateKey: fs.readFileSync(process.env.SFTP_PRIVATE_KEY) }
: { password: process.env.SFTP_PASS }),
};
const syncDirs = [
{
local: path.resolve(
process.env.LOCAL_DIR_FE ??
'../luci-app-tachyon/htdocs/luci-static/resources/view/tachyon',
),
remote:
process.env.REMOTE_DIR_FE ?? '/www/luci-static/resources/view/tachyon',
},
{
local: path.resolve(
process.env.LOCAL_DIR_BIN ?? '../tachyon/files/usr/bin/',
),
remote: process.env.REMOTE_DIR_BIN ?? '/usr/bin/',
},
{
local: path.resolve(
process.env.LOCAL_DIR_LIB ?? '../tachyon/files/usr/lib/',
),
remote: process.env.REMOTE_DIR_LIB ?? '/usr/lib/tachyon/',
},
{
local: path.resolve(
process.env.LOCAL_DIR_INIT ?? '../tachyon/files/etc/init.d/',
),
remote: process.env.REMOTE_DIR_INIT ?? '/etc/init.d/',
},
];
async function uploadFile(filePath, baseDir, remoteBase) {
const relativePath = path.relative(baseDir, filePath);
const remotePath = path.posix.join(remoteBase, relativePath);
console.log(`↑ Uploading: ${relativePath} -> ${remotePath}`);
try {
await sftp.fastPut(filePath, remotePath);
console.log(`✓ Uploaded: ${relativePath}`);
} catch (err) {
console.error(`✗ Failed: ${relativePath}: ${err.message}`);
}
}
async function deleteFile(filePath, baseDir, remoteBase) {
const relativePath = path.relative(baseDir, filePath);
const remotePath = path.posix.join(remoteBase, relativePath);
console.log(`⨯ Removing: ${relativePath}`);
try {
await sftp.delete(remotePath);
console.log(`✓ Removed: ${relativePath}`);
} catch (err) {
console.warn(`⚠ Could not delete ${relativePath}: ${err.message}`);
}
}
async function uploadAllFiles() {
for (const { local, remote } of syncDirs) {
console.log(`📂 Uploading all from ${local}`);
const files = await glob(`${local}/**/*`, { onlyFiles: true });
for (const file of files) {
await uploadFile(file, local, remote);
}
}
console.log('✅ Initial upload complete!');
}
async function main() {
await sftp.connect(config);
console.log(`🔌 Connected to ${config.host}`);
await uploadAllFiles();
for (const { local, remote } of syncDirs) {
chokidar
.watch(local, { ignoreInitial: true })
.on('all', async (event, filePath) => {
if (event === 'add' || event === 'change') {
await uploadFile(filePath, local, remote);
} else if (event === 'unlink') {
await deleteFile(filePath, local, remote);
}
});
}
process.on('SIGINT', async () => {
console.log('👋 Disconnecting...');
await sftp.end();
process.exit();
});
}
main().catch((err) => {
process.exitCode = 1;
console.error('💥 Fatal:', err);
});