-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin-config.js
More file actions
71 lines (63 loc) · 1.73 KB
/
admin-config.js
File metadata and controls
71 lines (63 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const fs = require('fs');
const path = require('path');
const ADMIN_CONFIG_PATH = path.join(__dirname, 'admin-config.json');
async function loadAdminConfig() {
try {
if (!fs.existsSync(ADMIN_CONFIG_PATH)) {
return null;
}
const data = fs.readFileSync(ADMIN_CONFIG_PATH, 'utf8');
return JSON.parse(data);
} catch (error) {
console.error('[ADMIN_CONFIG] 設定読み込みエラー:', error.message);
return null;
}
}
async function saveAdminConfig(config) {
try {
const configToSave = {
...config,
lastUpdated: config.lastUpdated || new Date().toISOString()
};
fs.writeFileSync(ADMIN_CONFIG_PATH, JSON.stringify(configToSave, null, 2), 'utf8');
return true;
} catch (error) {
console.error('[ADMIN_CONFIG] 設定保存エラー:', error.message);
return false;
}
}
/**
* プロキシURLのパスワード部分をマスクする
* @param {string} proxyUrl - プロキシURL
* @returns {string} マスクされたプロキシURL
*/
function maskProxyUrl(proxyUrl) {
if (!proxyUrl || typeof proxyUrl !== 'string') {
return '';
}
try {
const url = new URL(proxyUrl);
if (url.password) {
url.password = '****';
return url.toString();
}
return proxyUrl;
} catch (error) {
const atIndex = proxyUrl.indexOf('@');
if (atIndex > 0) {
const beforeAt = proxyUrl.substring(0, atIndex);
const afterAt = proxyUrl.substring(atIndex);
const colonIndex = beforeAt.indexOf(':');
if (colonIndex > 0) {
const user = beforeAt.substring(0, colonIndex);
return `${user}:****${afterAt}`;
}
}
return proxyUrl;
}
}
module.exports = {
loadAdminConfig,
saveAdminConfig,
maskProxyUrl
};