25 lines
762 B
JavaScript
25 lines
762 B
JavaScript
'use strict';
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const txtPath = path.join(__dirname, '..', 'proxies.txt');
|
|
const jsonPath = path.join(__dirname, '..', 'proxies.json');
|
|
|
|
if (fs.existsSync(jsonPath)) {
|
|
process.stdout.write('migrate: proxies.json already exists. Skipping.\n');
|
|
process.exit(0);
|
|
}
|
|
|
|
if (!fs.existsSync(txtPath)) {
|
|
process.stdout.write('migrate: no proxies.txt found. Nothing to migrate.\n');
|
|
process.exit(0);
|
|
}
|
|
|
|
const { ProxyRegistry } = require('../src/proxy/registry');
|
|
|
|
const reg = new ProxyRegistry({ persistPath: jsonPath, txtPath, log: (l, m) => process.stdout.write(` [${l}] ${m}\n`) });
|
|
const n = reg.loadFromTxt(txtPath);
|
|
reg.save();
|
|
process.stdout.write(`migrate: imported ${n} proxies → ${jsonPath}\n`);
|