feat(image-service): standalone processor

This commit is contained in:
2026-02-22 21:59:14 +01:00
parent 4f6d62a85c
commit 21c0c778f9
11 changed files with 812 additions and 136 deletions

View File

@@ -1,48 +1,55 @@
import * as fs from 'node:fs';
import * as path from 'node:path';
import * as https from 'node:https';
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/';
import { fileURLToPath } from "node:url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const MODELS_DIR = path.join(__dirname, "..", "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'
"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;
}
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);
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 });
}
if (!fs.existsSync(MODELS_DIR)) {
fs.mkdirSync(MODELS_DIR, { recursive: true });
}
for (const model of models) {
await downloadModel(model);
}
for (const model of models) {
await downloadModel(model);
}
console.log('All models downloaded successfully!');
console.log("All models downloaded successfully!");
}
main().catch(console.error);