cpp
This commit is contained in:
41
server.js
41
server.js
@@ -1,6 +1,7 @@
|
||||
const fastify = require('fastify')({ logger: true });
|
||||
const path = require('path');
|
||||
const { animeMetadata } = require('./src/metadata/anilist');
|
||||
const { spawn } = require('child_process');
|
||||
const fs = require('fs');
|
||||
|
||||
const { initDatabase } = require('./src/shared/database');
|
||||
const { loadExtensions } = require('./src/shared/extensions');
|
||||
@@ -35,6 +36,41 @@ fastify.register(booksRoutes, { prefix: '/api' });
|
||||
fastify.register(proxyRoutes, { prefix: '/api' });
|
||||
fastify.register(extensionsRoutes, { prefix: '/api' });
|
||||
|
||||
function startCppScraper() {
|
||||
const exePath = path.join(
|
||||
__dirname,
|
||||
'src',
|
||||
'metadata',
|
||||
process.platform === 'win32' ? 'anilist.exe' : 'anilist'
|
||||
);
|
||||
const dllPath = path.join(__dirname, 'src', 'metadata', 'binaries');
|
||||
|
||||
if (!fs.existsSync(exePath)) {
|
||||
console.error(`❌ C++ Error: Could not find executable at: ${exePath}`);
|
||||
console.error(" Did you compile it? (g++ src/metadata/anilist.cpp -o src/metadata/anilist.exe ...)");
|
||||
return;
|
||||
}
|
||||
|
||||
const env = { ...process.env };
|
||||
env.PATH = `${dllPath};${env.PATH}`;
|
||||
|
||||
console.log("⚡ Starting WaifuBoard Scraper Engine (C++)...");
|
||||
|
||||
const scraper = spawn(exePath, [], {
|
||||
stdio: 'inherit',
|
||||
cwd: __dirname,
|
||||
env: env
|
||||
});
|
||||
|
||||
scraper.on('error', (err) => {
|
||||
console.error('❌ Failed to spawn C++ process:', err);
|
||||
});
|
||||
|
||||
scraper.on('close', (code) => {
|
||||
console.log(`✅ Scraper process finished with code ${code}`);
|
||||
});
|
||||
}
|
||||
|
||||
const start = async () => {
|
||||
try {
|
||||
initDatabase();
|
||||
@@ -43,7 +79,8 @@ const start = async () => {
|
||||
await fastify.listen({ port: 3000, host: '0.0.0.0' });
|
||||
console.log(`Server running at http://localhost:3000`);
|
||||
|
||||
animeMetadata();
|
||||
startCppScraper();
|
||||
|
||||
} catch (err) {
|
||||
fastify.log.error(err);
|
||||
process.exit(1);
|
||||
|
||||
Reference in New Issue
Block a user