import * as fs from 'node:fs'; import * as path from 'node:path'; import * as https from 'node:https'; const MODELS_DIR = path.join(process.cwd(), 'models'); const BASE_URL = 'https://raw.githubusercontent.com/vladmandic/face-api/master/model/'; const models = [ 'tiny_face_detector_model-weights_manifest.json', 'tiny_face_detector_model-shard1' ]; async function downloadModel(filename: string) { const destPath = path.join(MODELS_DIR, filename); if (fs.existsSync(destPath)) { console.log(`Model ${filename} already exists.`); return; } return new Promise((resolve, reject) => { console.log(`Downloading ${filename}...`); const file = fs.createWriteStream(destPath); https.get(BASE_URL + filename, (response) => { response.pipe(file); file.on('finish', () => { file.close(); resolve(true); }); }).on('error', (err) => { fs.unlinkSync(destPath); reject(err); }); }); } async function main() { if (!fs.existsSync(MODELS_DIR)) { fs.mkdirSync(MODELS_DIR, { recursive: true }); } for (const model of models) { await downloadModel(model); } console.log('All models downloaded successfully!'); } main().catch(console.error);