-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit-counter.js
More file actions
34 lines (29 loc) · 1.08 KB
/
Copy pathinit-counter.js
File metadata and controls
34 lines (29 loc) · 1.08 KB
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
33
34
#!/usr/bin/env node
import admin from 'firebase-admin';
import fs from 'fs';
// Get service account key
const serviceAccountPath = process.env.GOOGLE_APPLICATION_CREDENTIALS ||
`${process.env.HOME}/.config/gcloud/legacy_credentials/aarush1822@gmail.com/adc.json`;
let serviceAccount;
try {
serviceAccount = JSON.parse(fs.readFileSync(serviceAccountPath, 'utf8'));
} catch (e) {
console.error('Error: Could not find service account key.');
console.log('Visit: https://console.firebase.google.com/project/zairok/settings/serviceaccounts/adminsdk');
console.log('Download JSON and set GOOGLE_APPLICATION_CREDENTIALS env var, or place at:');
console.log(serviceAccountPath);
process.exit(1);
}
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: 'https://zairok-default-rtdb.firebaseio.com',
});
const db = admin.database();
// Initialize counter
db.ref('downloads').set(50).then(() => {
console.log('✅ Download counter initialized to 50');
process.exit(0);
}).catch(err => {
console.error('❌ Error:', err.message);
process.exit(1);
});