File size: 1,033 Bytes
cc771fe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
 * This script initializes the data directory and required JSON files
 * Run this before starting the Docker container to ensure proper file permissions
 */

const fs = require('fs');
const path = require('path');

// Define the data directory path
const dataDir = path.join(__dirname, '..', 'data');

// Create the data directory if it doesn't exist
if (!fs.existsSync(dataDir)) {
  console.log(`Creating data directory: ${dataDir}`);
  fs.mkdirSync(dataDir, { recursive: true });
}

// Initialize data.json if it doesn't exist
const dataJsonPath = path.join(dataDir, 'data.json');
if (!fs.existsSync(dataJsonPath)) {
  console.log(`Creating empty data.json file: ${dataJsonPath}`);
  fs.writeFileSync(dataJsonPath, '{}', 'utf8');
}

// Initialize ips.json if it doesn't exist
const ipsJsonPath = path.join(dataDir, 'ips.json');
if (!fs.existsSync(ipsJsonPath)) {
  console.log(`Creating empty ips.json file: ${ipsJsonPath}`);
  fs.writeFileSync(ipsJsonPath, '{}', 'utf8');
}

console.log('Data files initialized successfully');