MCPcopy Create free account
hub / github.com/GlobalTechInfo/MEGA-MD / hasValidSession

Function hasValidSession

index.js:114–150  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

112 return sessionPath;
113}
114function hasValidSession() {
115 try {
116 const credsPath = path.join(__dirname, 'session', 'creds.json');
117 if (!existsSync(credsPath))
118 return false;
119 const fileContent = fs.readFileSync(credsPath, 'utf8');
120 if (!fileContent || fileContent.trim().length === 0) {
121 printLog('warning', 'creds.json exists but is empty');
122 return false;
123 }
124 try {
125 const creds = JSON.parse(fileContent);
126 if (!creds.noiseKey || !creds.signedIdentityKey || !creds.signedPreKey) {
127 printLog('warning', 'creds.json is missing required fields');
128 return false;
129 }
130 if (creds.registered === false) {
131 printLog('warning', 'Session not registered. Clearing for fresh pairing...');
132 try {
133 rmSync(path.join(__dirname, 'session'), { recursive: true, force: true });
134 }
135 catch (_e) { /* ignore */ }
136 return false;
137 }
138 printLog('success', 'Valid and registered session credentials found');
139 return true;
140 }
141 catch (_parseError) {
142 printLog('warning', 'creds.json contains invalid JSON');
143 return false;
144 }
145 }
146 catch (error) {
147 printLog('error', `Error checking session validity: ${error.message}`);
148 return false;
149 }
150}
151async function initializeSession() {
152 ensureSessionDirectory();
153 const txt = config.sessionId;

Callers 1

initializeSessionFunction · 0.85

Calls 1

printLogFunction · 0.90

Tested by

no test coverage detected