<commit_before>const config = require('../config');
const admin = require("firebase-admin");

admin.initializeApp({
    credential: admin.credential.cert({
      projectId: config.FIREBASE_PROJECT_ID,
      clientEmail: config.FIREBASE_CLIENT_EMAIL,
      privateKey: config.FIREBASE_PRIVATE_KEY,
    }),
    storageBucket: config.FIREBASE_STORAGE_BUCKET,
    databaseURL: config.FIREBASE_DATABASE_URL
  });

const firestore = admin.firestore();

class FirebaseClient {
    addWatchSession(userId, movieData) {
        const watchReference = firestore.collection('session');
        const now = new Date();
        return watchReference.add({
            userId,
            torrentUrl: movieData.movie,
            image: movieData.image,
            title: `${movieData.title} (${movieData.qty})`,
            custom: movieData.custom || false,
            date: now.getTime()
        }).then(result => {
            return {
                id: result.id,
                url: `${config.BASE_URL}/watch/${result.id}`
            };
        });
    }

    addUser(profile) {
        firestore.doc(`users/${profile.userId}`)
            .set(profile)
            .then(result => {
                console.log(`User ${profile.displayName} saved`);
            });
    }

    subscribeToSerial(userId, serialId) {
        firestore.doc(`subscribe/${serialId}`)
            .update({[userId]: true})
            .then(result => {
                console.log(`User ${userId} register as ${serialId} subscriber`);
            });
    }

    getFirestore() {
        return firestore;<commit_msg>fix write logic<commit_after>const config = require('../config');
const admin = require("firebase-admin");

admin.initializeApp({
    credential: admin.credential.cert({
      projectId: config.FIREBASE_PROJECT_ID,
      clientEmail: config.FIREBASE_CLIENT_EMAIL,
      privateKey: config.FIREBASE_PRIVATE_KEY,
    }),
    storageBucket: config.FIREBASE_STORAGE_BUCKET,
    databaseURL: config.FIREBASE_DATABASE_URL
  });

const firestore = admin.firestore();

class FirebaseClient {
    addWatchSession(userId, movieData) {
        const watchReference = firestore.collection('session');
        const now = new Date();
        return watchReference.add({
            userId,
            torrentUrl: movieData.movie,
            image: movieData.image,
            title: `${movieData.title} (${movieData.qty})`,
            custom: movieData.custom || false,
            date: now.getTime()
        }).then(result => {
            return {
                id: result.id,
                url: `${config.BASE_URL}/watch/${result.id}`
            };
        });
    }

    addUser(profile) {
        firestore.doc(`users/${profile.userId}`)
            .set(profile)
            .then(result => {
                console.log(`User ${profile.displayName} saved`);
            });
    }

    subscribeToSerial(userId, serialId) {
        const serialSubscriptionPath = `subscribe/${serialId}`;
        firestore.doc(serialSubscriptionPath)
            .get()
            .then(snapshot => {
                if (snapshot.exists) {
                    return firestore.doc(serialSubscriptionPath)
                        .set({[userId]: true})
                } else {
                    return firestore.doc(serialSubscriptionPath)
                        .update({[userId]: true})
                }
            })
            .then(result => {
                console.log(`User ${userId} register as ${serialId} subscriber`);
            });
    }

    getFirestore() {
        return firestore;
{'fraction_non_alphanumeric': 0.12751116071428573, 'fraction_numerical': 0.0, 'mean_word_length': 1.955482275350371, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7523592', 'n_tokens_mistral': 993, 'n_tokens_neox': 1000, 'n_words': 167}