Click here to Skip to main content
15,170,984 members
Home / Discussions / JavaScript
   

JavaScript

 
AnswerRe: Cannot figure out what code lines does mean ... Pin
Member 1501261727-Mar-21 1:03
MemberMember 1501261727-Mar-21 1:03 
AnswerRe: Cannot figure out what code lines does mean ... Pin
Peter_in_278027-Mar-21 1:54
professionalPeter_in_278027-Mar-21 1:54 
GeneralRe: Cannot figure out what code lines does mean ... Pin
Member 1501261727-Mar-21 22:40
MemberMember 1501261727-Mar-21 22:40 
GeneralRe: Cannot figure out what code lines does mean ... Pin
Member 150126178-Apr-21 23:49
MemberMember 150126178-Apr-21 23:49 
AnswerRe: Cannot figure out what code lines does mean ... Pin
Richard Deeming28-Mar-21 23:29
mveRichard Deeming28-Mar-21 23:29 
GeneralRe: Cannot figure out what code lines does mean ... Pin
Member 150126178-Apr-21 23:49
MemberMember 150126178-Apr-21 23:49 
QuestionRedirect with (Page Visibility API) Pin
ab smine19-Mar-21 11:38
Memberab smine19-Mar-21 11:38 
QuestionNode-Schedule Module Can't Cron Job Scheduled Long Time Pin
Barış KAHRAMAN19-Mar-21 11:02
MemberBarış KAHRAMAN19-Mar-21 11:02 
I used node-schedule module to cron a job executed only once at particular time. I also use callable function to trigger Cloud Function and to get client-side data. The big trouble is that all things are fine to cron a single task until 15 minutes. But, on the other hand it doesn't do the task scheduled further time more than 15 minutes. What may occur after 15 minutes to cancel task? I used Firebase Quickstart code and I add only schedule-job module into the code. I didn't changed anything other than getting scheduling time values from client-side. I really need help for this issue. The cloud function script is below.

Thank you.

<pre>/* eslint-disable max-len */
"use strict";

const functions = require("firebase-functions");
const sanitizer = require("./sanitizer");
const admin = require("firebase-admin");
const schedule = require("node-schedule");
admin.initializeApp();
// [START messageFunctionTrigger]
// Saves a message to the Firebase Realtime Database but sanitizes the text by removing swearwords.
exports.addMessage = functions.https.onCall((data, context) => {
  // [START_EXCLUDE]
  // [START readMessageData]
  // Message text passed from the client.
  const text = data.text;
  // [END readMessageData]
  // [START messageHttpsErrors]
  // Checking attribute.
  if (!(typeof text === "string") || text.length === 0) {
    // Throwing an HttpsError so that the client gets the error details.
    throw new functions.https.HttpsError("invalid-argument", "The function must be called with " +
        "one arguments \"text\" containing the message text to add.");
  }
  // Checking that the user is authenticated.
  if (!context.auth) {
    // Throwing an HttpsError so that the client gets the error details.
    throw new functions.https.HttpsError("failed-precondition", "The function must be called " +
        "while authenticated.");
  }
  // [END messageHttpsErrors]

  // [START authIntegration]
  // Authentication / user information is automatically added to the request.
  const uid = context.auth.uid;
  const name = context.auth.token.name || null;
  const picture = context.auth.token.picture || null;
  const email = context.auth.token.email || null;
  // [END authIntegration]

  // [START returnMessageAsync]
  // Saving the new message to the Realtime Database.

  const dateWithTimeZone = (timeZone, year, month, day, hour, minute, second) => {
    const date = new Date(Date.UTC(year, month, day, hour, minute, second));

    const utcDate = new Date(date.toLocaleString("en-US", {timeZone: "UTC"}));
    const tzDate = new Date(date.toLocaleString("en-US", {timeZone: timeZone}));
    const offset = utcDate.getTime() - tzDate.getTime();

    date.setTime( date.getTime() + offset );

    return date;
  };

  const sanitizedMessage = sanitizer.sanitizeText(text); // Sanitize the message.

  const dataFuture = [uid, name, picture, email, sanitizedMessage];

  new Promise(function() {
    schedule.scheduleJob(dateWithTimeZone("Europe/Istanbul",
        data.year, data.month, data.day, data.hour,
        data.minute, data.second), function(data) {
      const theuid = data[0];
      const thename = data[1];
      const thepicture = data[2];
      const theemail = data[3];
      return admin.database().ref("/messages").push({
        text: data[4],
        author: {theuid, thename, thepicture, theemail},
      }).then(() => {
        console.log("New Message written");
        // Returning the sanitized message to the client.
        return {text: data[4]};
      })
      // [END returnMessageAsync]
          .catch((error) => {
            // Re-throwing the error as an HttpsError so that the client gets the error details.
            throw new functions.https.HttpsError("unknown", error.message, error);
          });
    }.bind(null, dataFuture));

  // [END_EXCLUDE]
  });

  return {text: "done"};
// [END messageFunctionTrigger]
});

QuestionCalculation in javascript Pin
Krasimir Dermendzhiev16-Mar-21 4:31
MemberKrasimir Dermendzhiev16-Mar-21 4:31 
AnswerRe: Calculation in javascript Pin
Richard Deeming16-Mar-21 5:39
mveRichard Deeming16-Mar-21 5:39 
GeneralRe: Calculation in javascript Pin
Krasimir Dermendzhiev16-Mar-21 22:36
MemberKrasimir Dermendzhiev16-Mar-21 22:36 
GeneralRe: Calculation in javascript Pin
Krasimir Dermendzhiev30-Mar-21 5:22
MemberKrasimir Dermendzhiev30-Mar-21 5:22 
QuestionJavascript CSP and CORS problem? How can I send Cookies with AJAX in CORS? Pin
Member 1510027614-Mar-21 22:50
MemberMember 1510027614-Mar-21 22:50 
AnswerRe: Javascript CSP and CORS problem? How can I send Cookies with AJAX in CORS? Pin
Richard Deeming14-Mar-21 23:39
mveRichard Deeming14-Mar-21 23:39 
GeneralRe: Javascript CSP and CORS problem? How can I send Cookies with AJAX in CORS? Pin
Member 1510027615-Mar-21 0:11
MemberMember 1510027615-Mar-21 0:11 
GeneralRe: Javascript CSP and CORS problem? How can I send Cookies with AJAX in CORS? Pin
Richard Deeming15-Mar-21 0:29
mveRichard Deeming15-Mar-21 0:29 
GeneralRe: Javascript CSP and CORS problem? How can I send Cookies with AJAX in CORS? Pin
Member 1510027615-Mar-21 8:56
MemberMember 1510027615-Mar-21 8:56 
GeneralRe: Javascript CSP and CORS problem? How can I send Cookies with AJAX in CORS? Pin
Richard Deeming15-Mar-21 23:31
mveRichard Deeming15-Mar-21 23:31 
GeneralRe: Javascript CSP and CORS problem? How can I send Cookies with AJAX in CORS? Pin
Member 1510027616-Mar-21 7:49
MemberMember 1510027616-Mar-21 7:49 
Questionif statement not working Pin
chizzy4211-Mar-21 8:53
Memberchizzy4211-Mar-21 8:53 
AnswerRe: if statement not working Pin
NotTodayYo11-Mar-21 9:24
MemberNotTodayYo11-Mar-21 9:24 
AnswerRe: if statement not working Pin
W Balboos, GHB11-Mar-21 9:45
mveW Balboos, GHB11-Mar-21 9:45 
GeneralRe: if statement not working Pin
chizzy4213-Mar-21 5:03
Memberchizzy4213-Mar-21 5:03 
GeneralRe: if statement not working Pin
Member 1510027615-Mar-21 9:15
MemberMember 1510027615-Mar-21 9:15 
GeneralRe: if statement not working Pin
chizzy4217-Mar-21 3:28
Memberchizzy4217-Mar-21 3:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.