chore: switch to react-router v7

This commit is contained in:
Aarnav Tale
2024-12-31 10:30:14 +05:30
parent 39504e2487
commit aa9872a45b
101 changed files with 3825 additions and 6796 deletions
+38 -36
View File
@@ -1,14 +1,14 @@
import { readdir, readFile } from 'node:fs/promises'
import { platform } from 'node:os'
import { join, resolve } from 'node:path'
import { kill } from 'node:process'
import { readdir, readFile } from 'node:fs/promises';
import { platform } from 'node:os';
import { join, resolve } from 'node:path';
import { kill } from 'node:process';
import log from '~/utils/log'
import log from '~/utils/log';
import { createIntegration } from './integration'
import { createIntegration } from './integration';
interface Context {
pid: number | undefined
pid: number | undefined;
}
export default createIntegration<Context>({
@@ -18,62 +18,64 @@ export default createIntegration<Context>({
},
isAvailable: async (context) => {
if (platform() !== 'linux') {
log.error('INTG', '/proc is only available on Linux')
return false
log.error('INTG', '/proc is only available on Linux');
return false;
}
log.debug('INTG', 'Checking /proc for Headscale process')
const dir = resolve('/proc')
log.debug('INTG', 'Checking /proc for Headscale process');
const dir = resolve('/proc');
try {
const subdirs = await readdir(dir)
const subdirs = await readdir(dir);
const promises = subdirs.map(async (dir) => {
const pid = Number.parseInt(dir, 10)
const pid = Number.parseInt(dir, 10);
if (Number.isNaN(pid)) {
return
return;
}
const path = join('/proc', dir, 'cmdline')
const path = join('/proc', dir, 'cmdline');
try {
log.debug('INTG', 'Reading %s', path)
const data = await readFile(path, 'utf8')
log.debug('INTG', 'Reading %s', path);
const data = await readFile(path, 'utf8');
if (data.includes('headscale')) {
return pid
return pid;
}
} catch (error) {
log.error('INTG', 'Failed to read %s: %s', path, error)
log.error('INTG', 'Failed to read %s: %s', path, error);
}
})
});
const results = await Promise.allSettled(promises)
const pids = []
const results = await Promise.allSettled(promises);
const pids = [];
for (const result of results) {
if (result.status === 'fulfilled' && result.value) {
pids.push(result.value)
pids.push(result.value);
}
}
log.debug('INTG', 'Found Headscale processes: %o', pids)
log.debug('INTG', 'Found Headscale processes: %o', pids);
if (pids.length > 1) {
log.error('INTG', 'Found %d Headscale processes: %s',
log.error(
'INTG',
'Found %d Headscale processes: %s',
pids.length,
pids.join(', '),
)
return false
);
return false;
}
if (pids.length === 0) {
log.error('INTG', 'Could not find Headscale process')
return false
log.error('INTG', 'Could not find Headscale process');
return false;
}
context.pid = pids[0]
log.info('INTG', 'Found Headscale process with PID: %d', context.pid)
return true
context.pid = pids[0];
log.info('INTG', 'Found Headscale process with PID: %d', context.pid);
return true;
} catch {
log.error('INTG', 'Failed to read /proc')
return false
log.error('INTG', 'Failed to read /proc');
return false;
}
}
})
},
});