Vue Draggable Next missing template or render function

I’m trying to use Vue Draggable Next for a Vue 3 example page.

I’ve followed guide in the repo. After failing to import Vue Draggable Next component, I’ve started using https://unpkg.com/[email protected]/dist/vue-draggable-next.global.js instead of https://cdnjs.cloudflare.com/ajax/libs/Vue.Draggable/4.0.0/vuedraggable.umd.min.js.

My HTML code is shown in this JSFiddle:

<!DOCTYPE html>
<html>
  <head>
    <script src="https://unpkg.com/vue@3"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/Sortable/1.14.0/Sortable.min.js"></script>
    <script src="https://unpkg.com/[email protected]/dist/vue-draggable-next.global.js"></script>
  </head>
  <body>
    <div id="app">
      <ul>
        <li v-for="item in bbcourses" :key="item.id">
          <div style="border: 1px #000 solid">{{ item.name }}</div>
        </li>
      </ul>
      <ul>
        <li
          v-for="item in pcourses"
          :key="item.id"
          style="border: 1px #000 solid"
        >
          {{ item.name }}
        </li>
      </ul>
      <draggable
        :list="pcourses"
        group="people"
        @start="log"
        @end="log"
        itemKey="id"
        @change="log"
      >
        <div
          v-for="element in list"
          :key="element.name"
          style="border: 1px #000 solid"
        >
          {{ element.name }}{{ element.id }}
        </div>
      </draggable>
    </div>

    <script>
      const app = Vue.createApp({
        data() {
          return {
            drag: false,
            message: "Hello Vue!",
            bbcourses: [
              { id: 1, name: "First course" },
              { id: 2, name: "Second course" },
            ],
            pcourses: [
              { id: 1, name: "First course" },
              { id: 2, name: "Second course" },
            ],
          };
        },
        methods: {
          log(event) {
            console.log(event);
          },
        },
      });
      app.component("draggable", VueDraggableNext);
      app.mount("#app");
    </script>
  </body>
</html>

Provide error: "[Vue warn]: Component is missing template or render function." and doesn’t show the draggable list.

Issue regarding Base64 being different in Windows and MacOS?

I have a website where user upload image, using JavaScript I am converting the image into base64 string..

var ctx = canvas.getContext('2d');

ctx.canvas.width = dimensions.width;

ctx.canvas.height = dimensions.height;

var img = document.getElementsByClassName('croppr-image')[0]; 
       
ctx.drawImage(img, dimensions.x, dimensions.y, dimensions.width, dimensions.height, 0, 0, dimensions.width, dimensions.height);

var base64 = canvas.toDataURL("image/png");

I am using asp.net with c# as my backend service where I again convert this base64 string to image to save it on my server.

 byte[] bytes = Convert.FromBase64String(text);

Now my question is, on android phone this worked perfect but when using iphone to upload image (taken from iphone camara) Asp.net c# throws an error “Invalid base64 length”!!

I don’t understand why??

Typescript callbacks not passing types down when nested

I’m using Nextjs for a project and I’ve created the following interface to decorate other functions:

import type { NextApiRequest, NextApiResponse, NextApiHandler } from 'next';

interface ApiHandlerDecorator<T, S> {
  <Request extends NextApiRequest, Response extends NextApiResponse>(
    handler: (
      request: Request & T,
      response: Response | NextApiResponse<S>
    ) => ReturnType<NextApiHandler>
  ): (
    request: Request & T,
    response: Response | NextApiResponse<S>
  ) => ReturnType<NextApiHandler>;
}

export default ApiHandlerDecorator;

I have two decorators:

import { verify } from 'jsonwebtoken';

import type { ApiHandlerDecorator } from './interfaces';

import {
  BadRequestError,
  ExpiredCredentialsError,
  InvalidCredentialsError,
  MissingCredentialsError,
  UnexpectedError,
} from './pages/api/errors';

type AuthorizationValidationErrors =
  | MissingCredentialsError
  | InvalidCredentialsError
  | ExpiredCredentialsError
  | UnexpectedError
  | BadRequestError
  | undefined;

const authorizationValidation: ApiHandlerDecorator<
  { headers: { authorization: string } },
  AuthorizationValidationErrors
> = (handler) => async (request, response) => {
  const {
    headers: { authorization },
  } = request;

  let statusCode = 401;
  let json: AuthorizationValidationErrors = new MissingCredentialsError(
    'Missing authorization header'
  );

  if (authorization) {
    try {
      const decodedJwt = verify(authorization, process.env.SECRET_KEY);

      if (
        decodedJwt &&
        typeof decodedJwt === 'object' &&
        'roomId' in decodedJwt &&
        'playerId' in decodedJwt
      ) {
        await handler(
          { ...request, ...{ headers: { authorization } } },
          response
        );
      } else {
        statusCode = 400;
        json = new BadRequestError(
          'Malformed authorization. Missing roomId and playerId.'
        );
      }
    } catch ({ name: errorName }) {
      if (errorName === 'JsonWebTokenError') {
        statusCode = 401;
        json = new InvalidCredentialsError(
          'Invalid authorization. Authorization not signed.'
        );
      } else if (errorName === 'TokenExpiredError') {
        statusCode = 403;
        json = new ExpiredCredentialsError(
          'Expired authorization. Refresh authorization.'
        );
      } else {
        statusCode = 500;
        json = new UnexpectedError(
          'Unexpected error while processing authorization'
        );
      }
    }
  } else {
    response.status(statusCode).json(json);
  }
};

export default authorizationValidation;

and

import type { ApiHandlerDecorator } from './interfaces';

import { decode } from 'jsonwebtoken';
import { BadRequestError, MissingCredentialsError } from './pages/api/errors';

type RoomAndPlayerIdInjectionErrors =
  | BadRequestError
  | MissingCredentialsError
  | undefined;

const roomAndPlayerIdInjection: ApiHandlerDecorator<
  { roomId: string; playerId: string },
  RoomAndPlayerIdInjectionErrors
> = (handler) => async (request, response) => {
  const {
    headers: { authorization },
  } = request;

  if (authorization) {
    const decodedJwt = decode(authorization);

    if (
      decodedJwt &&
      typeof decodedJwt === 'object' &&
      'roomId' in decodedJwt &&
      'playerId' in decodedJwt
    ) {
      await handler(
        {
          ...request,
          roomId: decodedJwt.roomId,
          playerId: decodedJwt.playerId,
        },
        response
      );
    } else {
      response
        .status(400)
        .json(
          new BadRequestError(
            'Malformed authorization. Missing roomId and playerId.'
          )
        );
    }
  } else {
    response
      .status(401)
      .json(
        new MissingCredentialsError(
          'Missing authorization. Authorization header not provided.'
        )
      );
  }
};

export default roomAndPlayerIdInjection;

When I decorate a function like this:

const handler = authorizationValidation(
  roomAndPlayerIdInjection(async (request, response) => {
    // request.headers.authorization is string | undefined
  });
);

If I change call order and do:

const handler = roomAndPlayerIdInjection(
  authorizationValidation(async (request, response) => {
    // request.roomId and request.playerId is undefined
  });
);

But, when I do:

type Handler = typeof handler;

The Handler request parameter is perfectly typed.

Playground with working example

Is this a problem with Typescript or Next.js? Am I doing something wrong? Should I be using experimental decorators instead?

openssl-nodejs always return error while genrating key and CSR

I’m using openssl-nodejs package to use openssl commands to generate CSR and Private key.
We are successfully generating the CSR and Private key files with below code. However, it’s always returning the error response.

async function generateCsr(){
let subject = '';
let password = 'DummyPassword';

subject = `/CN=y1212.website.com/OU=Dp-PD/O=Dummy org/L=mars/C=DJ/[email protected]`;

openssl(
    [
        'req',
        '-sha256',
        '-newkey',
        'rsa:2048',
        '-keyout',
        'y1212.website.com-privkey.pem',
        '-out',
        'y1212.website.com.csr',
        '-subj',
        `${subject}`,
        '-passout',
        `pass:${password}`
    ], function (err, buffer) {
            if (err) console.log('OpenSSL error: ' + err); // RETURNS ERROR DESPITE OF GENERATING CORRECT FIELS
            console.log("string", buffer.toString()); // THIS IS NULL
});
}

generateCsr();

Output:

OpenSSL process ends with code 0
OpenSSL error: Generating a 2048 bit RSA private key
writing new private key to 'openssl/y1212.website.com-privkey.pem'

Question: Why it is always returning the error despite of generating the correct CSR and Private keys. Due to this, we are unable to handle error handling. How can we resolve this issue?

Move white rook in javascript (chess game)

I am making a chess game with html and javascript. The fact is that only the
black and white pawn pieces work for me, and I want to advance, starting with the
white rook. And the case is that it does not work for me, any suggestion?Hello, I am
making a chess game with html and javascript. The fact is that only the black and
white pawn pieces work for me, and I want to advance, starting with the white rook.
And the case is that it does not work for me, any suggestion?

-------------------------------

var movementPrevious=false;
var boxPrevious;
function movePiece(box1,box2){
   var temp;
   if(document.getElementById(box2).textContent=="."){
      temp=document.getElementById(box2).textContent;
      document.getElementById(box2).textContent=document.getElementById(box1).textContent;
      document.getElementById(box1).textContent=temp;
   }
}

function movementWhitePawn(box){
   var row=box.substring(1,3);
   var col=box.substring(0,1);
   var novabox;

   novabox=col+(parseInt(row)+1);
   if(document.getElementById(novabox).textContent=="")
      document.getElementById(novabox).textContent=".";
   if(parseInt(row)==2){
      novabox=col+(parseInt(row)+2);
      if(document.getElementById(novabox).textContent=="")
         document.getElementById(novabox).textContent="."; 
    }
}

function movementWhiteTower(box){
   var row=box.substring(1,3);
   var col=box.substring(0,1);
   var novabox;

   novabox=col+(parseInt(row)+2);
   if(document.getElementById(novabox).textContent=="")
      document.getElementById(novabox).textContent=".";
   if(parseInt(row)==2){
      novabox=col+(parseInt(row)+3);
      if(document.getElementById(novabox).textContent=="")
         document.getElementById(novabox).textContent="."; 
    }
}

function movementBlackPawn(box){
   var row=box.substring(1,4);
   var col=box.substring(0,1);
   var novabox;
   novabox=col+(parseInt(row)-1);
   if(document.getElementById(novabox).textContent=="")
      document.getElementById(novabox).textContent=".";
   if(parseInt(row)==7){
      novabox=col+(parseInt(row)-2);
      if(document.getElementById(novabox).textContent=="")
         document.getElementById(novabox).textContent=".";      
   }
}

function cleaningCounter(){
   var resume_table = document.getElementById("board");
      for (var i = 0, row; row = resume_table.rows[i]; i++) {
      for (var j = 0, col; col = row.cells[j]; j++) {
        if(row.cells[j].textContent==".")
         row.cells[j].textContent="";
      }
    }
}

function movement(box) {
   if(movementPrevious ==false){
    switch(document.getElementById(box).textContent){
        case"♙":
           movementWhitePawn(box);
            boxPrevious=box;
            movementPrevious =true;
            break;
        case "♟":
           movementBlackPawn(box);
            boxPrevious=box;
            movementPrevious =true;
            break;
        case "♖":
           movementWhiteTower(box);
           boxPrevious=box;
            movementPrevious =true;
           break;
        case "♜":
           boxPrevious=box;
            movementPrevious =true;
           break;
        case "♗":
           boxPrevious=box;
            movementPrevious =true;
           break;
        case "♝":
           boxPrevious=box;
            movementPrevious =true;
           break;
        case "♘":
           boxPrevious=box;
            movementPrevious =true;
           break;
        case "♞":
           boxPrevious=box;
            movementPrevious =true;
           break;
        case "♕":
           boxPrevious=box;
            movementPrevious =true;
           break;
        case "♛":
           boxPrevious=box;
            movementPrevious =true;
           break;
        case "♔":
           boxPrevious=box;
            movementPrevious =true;
           break;
        case "♚":
            boxPrevious=box;
            movementPrevious =true;
           break;
        case "":
            boxPrevious=box;
            movementPrevious =true;
    }
}
else {
   movePiece(boxPrevious,box);
   movementPrevious =false;
   cleaningCounter();
   boxPrevious="";

   }
}
<!DOCTYPE html>
<html>
    <head>
        <title> Chess </title>
        <meta charset="UTF-8">
        <script src="chess.js"></script>

        <style>
            .chess-board { border-spacing: 0; border-collapse: collapse; }
            .chess-board th { padding: .5em; }
            .chess-board th + th { border-bottom: 1px solid #000; }
            .chess-board th:first-child,
            .chess-board td:last-child { border-right: 1px solid #000; }
            .chess-board tr:last-child td { border-bottom: 1px solid; }
            .chess-board th:empty { border: none; }
            .chess-board td { width: 2.5em; height: 2.5em; text-align: center; font-size: 32px; line-height: 0;}
            .chess-board .light { background: #ff9d00; }
            .chess-board .dark { background: #ff0000; }

                       
        </style>
    </head>
    <body>
        <table>
            <tr>
                <td>
                    <h2>Chess</h2>
                    <table class="chess-board" id="board">
                        <tbody>
                            <tr>
                                <th></th>
                                <th>a</th>
                                <th>b</th>
                                <th>c</th>
                                <th>d</th>
                                <th>e</th>
                                <th>f</th>
                                <th>g</th>
                                <th>h</th>
                            </tr>
                            <tr>
                                <th>8</th>
                                <td id="18" class="light" onclick="movement('18');">♜</td>
                                <td id="28" class="dark" onclick="movement('28');">♞</td>
                                <td id="38" class="light" onclick="movement('38');">♝</td>
                                <td id="48" class="dark" onclick="movement('48');">♛</td>
                                <td id="58" class="light" onclick="movement('58');">♚</td>
                                <td id="68" class="dark" onclick="movement('68');">♝</td>
                                <td id="78" class="light" onclick="movement('78');">♞</td>
                                <td id="88" class="dark" onclick="movement('88');">♜</td>
                            </tr>
                            <tr>
                                <th>7</th>
                                <td id="17" class="dark" onclick="movement('17');">♟</td>
                                <td id="27" class="light" onclick="movement('27');">♟</td>
                                <td id="37" class="dark" onclick="movement('37');">♟</td>
                                <td id="47" class="light" onclick="movement('47');">♟</td>
                                <td id="57" class="dark" onclick="movement('57');">♟</td>
                                <td id="67" class="light" onclick="movement('67');">♟</td>
                                <td id="77" class="dark" onclick="movement('77');">♟</td>
                                <td id="87" class="light" onclick="movement('87');">♟</td>
                            </tr>
                            <tr>
                                <th>6</th>
                                <td id="16" class="light" onclick="movement('16');"></td>
                                <td id="26" class="dark" onclick="movement('26');"></td>
                                <td id="36" class="light" onclick="movement('36');"></td>
                                <td id="46" class="dark" onclick="movement('46');"></td>
                                <td id="56" class="light" onclick="movement('56');"></td>
                                <td id="66" class="dark" onclick="movement('66');"></td>
                                <td id="76" class="light" onclick="movement('76');"></td>
                                <td id="86" class="dark" onclick="movement('86');"></td>
                            </tr>
                            <tr>
                                <th>5</th>
                                <td id="15" class="dark" onclick="movement('15');"></td>
                                <td id="25" class="light" onclick="movement('25');"></td>
                                <td id="35" class="dark" onclick="movement('35');"></td>
                                <td id="45" class="light" onclick="movement('45');"></td>
                                <td id="55" class="dark" onclick="movement('55');"></td>
                                <td id="65" class="light" onclick="movement('65');"></td>
                                <td id="75" class="dark" onclick="movement('75');"></td>
                                <td id="85" class="light" onclick="movement('85');"></td>
                            </tr>
                            <tr>
                                <th>4</th>
                                <td id="14" class="light" onclick="movement('14');"></td>
                                <td id="24" class="dark" onclick="movement('24');"></td>
                                <td id="34" class="light" onclick="movement('34');"></td>
                                <td id="44" class="dark" onclick="movement('44');">♖</td>
                                <td id="54" class="light" onclick="movement('54');"></td>
                                <td id="64" class="dark" onclick="movement('64');"></td>
                                <td id="74" class="light" onclick="movement('74');"></td>
                                <td id="75" class="dark" onclick="movement('75');"></td>
                            </tr>
                            <tr>
                                <th>3</th>
                                <td  id="13" class="dark" onclick="movement('13');"></td>
                                <td  id="23" class="light" onclick="movement('23');"></td>
                                <td  id="33" class="dark" onclick="movement('33');"></td>
                                <td  id="43" class="light" onclick="movement('43');"></td>
                                <td  id="53" class="dark" onclick="movement('53');"></td>
                                <td  id="63" class="light" onclick="movement('63');"></td>
                                <td  id="73" class="dark" onclick="movement('73');"></td>
                                <td  id="83" class="light" onclick="movement('83');"></td>
                            </tr>
                            <tr>
                                <th>2</th>
                                <td  id="12" class="light" onclick="movement('12');">♙</td>
                                <td  id="22" class="dark" onclick="movement('22');">♙</td>
                                <td  id="32" class="light" onclick="movement('32');">♙</td>
                                <td  id="42" class="dark" onclick="movement('42');">♙</td>
                                <td  id="52" class="light" onclick="movement('52');">♙</td>
                                <td  id="62" class="dark" onclick="movement('62');">♙</td>
                                <td  id="72" class="light" onclick="movement('72');">♙</td>
                                <td  id="82" class="dark" onclick="movement('82');">♙</td>
                            </tr>
                            <tr>
                                <th>1</th>
                                <td  id="11" class="dark" onclick="movement('11');"></td>
                                <td  id="21" class="light" onclick="movement('21');">♘</td>
                                <td  id="31" class="dark" onclick="movement('31');">♗</td>
                                <td  id="41" class="light" onclick="movement('41');">♕</td>
                                <td  id="51" class="dark" onclick="movement('51');">♔</td>
                                <td  id="61" class="light" onclick="movement('61');">♗</td>
                                <td  id="71" class="dark" onclick="movement('71');">♘</td>
                                <td  id="81" class="light" onclick="movement('81');">♖</td>
                            </tr>
                        </tbody>
                    </table>
                </td>
                 
                
    </body>
</html>

How do I prevent the Google API from being used by others?

I’m going to make a project using the Google translate api and I’m thinking of uploading this project to a server and just sharing it with my friends. But unfortunately the Api Key that I will use in the project can be accessed clearly in the JavaScript file. This is a very bad situation. To prevent this, I have limited the Google Cloud Api and as far as I understand it is only allowed to be used on the links I allow. It cannot be used on other links. Now my main question is, is this method enough to protect Api from malicious people? Do I need to do anything else? Thank you in advance for your answers.

I am getting a partial output on using React

so I am creating a Private Route but I am getting a partial output means all the content is not visible on the screen and I am getting a warning : You rendered descendant <Routes> (or called useRoutes()) at "/homepage" (under <Route path="/homepage">) but the parent route path has no trailing "*". and when I change path from ‘/homepage’ to ‘/homepage/* I still get partial output but without any warning..

this is the output without any content..

enter image description here

PrivateRoute.js

import React from 'react'
import { Route, Navigate, Routes } from 'react-router-dom'
import { useAuth } from '../Contexts/AuthContext'

export const PrivateRoute = ({ component: Component, ...rest }) => {

    const { currentUser } = useAuth()
    return(
        <Routes>
             <Route
            {...rest}
            render = {props => {
                return currentUser ? <Component {...props} /> : <Navigate to = '/' />
            }}
            >
            </Route>
        </Routes>
    )
}

App.js

<Router>
              <AuthProvider>
                <Routes>
                  <Route exact path = '/' element = {<BrandName/>}/>
                  <Route path = '/signup' element = {<SignUp />} />
                  <Route path = '/login' element = {<Login />} />
                  <Route path = '/homepage' element = {<PrivateRoute component={<HomePage />} />} />
                </Routes>
              </AuthProvider>
</Router>

can anyone solve this ?

JS scroll to center with flex reverse

Hi intresting moment which i didnt find in google.

How i can scroll to vertical center with flex reverse ?

Problem in example:

i have temp1.scrollHeight = 1000

but in top position of scroll property temp1.scrollTop return
‘-940’ (not -1000)

i think it calculate how scrollHeight-minus selft scroll element height:

enter image description here

How i can center scroll?
(temp1.scrollTop / 2) return 470px not 500px !

How to shorten string length but keep ending with javascript?

i need you help again for a JavaScript, I’m not sure how to start.
If it’s a really stupid question, please just don’t answer.

Input examples:

123456_78910_KK_TK_MAAA_123_123456_DOC

123456_78911_KTT_TK_MAAA_123_654321_TXT

123456_10987_KK_TK_BEEE_123_12345678910111213_FILE

Output, string length = 30 + _DOC / _TXT / _FILE:

123456_78910_KK_TK_MAAA__DOC -> 123456_78910_KK_TK_MAAA_DOC

123456_78911_KTT_TK_MAAA__TXT -> 123456_78911_KTT_TK_MAAA_TXT

123456_10987_KK_TK_BEEE_FILE

Thanks a lot for you help.

Can you display a OneDrive folder on a HTML page?

I am trying to create a system where a user can upload a document on a site which is link to OneDrive. The site will also display all the document of that OneDrive folder.

I know you can embed a document on a website, but I am trying to embed the folder itself so you can see its contents.

My question is: Can you display the folder on a website and can you upload documents to OneDrive ?

I plan to use Php and JavaScript.
I know you can upload on the directly on the OneDrive web app but I’m trying this for ease of use.

Uncaught TypeError: Cannot read properties of undefined (reading ‘building’) in React JS

I’m writing React JS web application and i have this code:

import React,{useEffect,useState} from 'react'
import {useParams} from 'react-router-dom'
import {Card} from 'react-bootstrap'

import {MapContainer, TileLayer, Market} from 'react-leaflet'

const Restaurant=()=>{
    const {id}=useParams();
    const [restaurant,setRestaurant]=useState([]);
    const [loading,setLoading]=useState(true);
    const url=`http://localhost:8080/api/restaurants/${id}`;

    useEffect(()=>{

        setLoading(true);
        fetch(url)
        .then(data=>data.json())
        .then(res=>{
            if(res.hasOwnProperty('_id'))
            setRestaurant(res);
            else
            setRestaurant([]);
            console.log(res);
        })
        .catch((err)=>console.log('There was an error',err));
       setLoading(false);

    },[id, url]);

    return(
        //id in params
        // <p>Restaurant id:{id}</p>
        <>
         <Card>

<Card.Body>
    <Card.Title>{restaurant.name}
        </Card.Title>

      
  
<Card.Text>{restaurant.address.building+' '+ restaurant.address.street}</Card.Text>

</Card.Body>
</Card>

        </>

    )

}

export default Restaurant;

After the fetch I get the Object with restaurants and save it to the restaurant hook using setRestaurant.

But for some reason, {restaurant.name} works fine, but {restaurant.address.building+' '+ restaurant.address.street}
does not work and it says cannot read properties of undefined.

Can someone please help me solve this issue?

Visualize contents of multiple xml files in one table (Javascript)

I have a folder on a network share, wich automatically gets filled with new xml files (that contain weighing data – 1 file per weighing). I need to visualize/convert this data for human readability reasons. I thought of a local webserver wich will grab the xml files and parses the contents in a readable table. This has to be dynamic, because new xml files are getting added automatically – the segments of the xml files are always the same tho.
After hours of googling I did not find any answer on that, maybe you could provide me with a smart and modern solution (maybe even with React/NextJS?).
I know this is possible with Microsoft PowerBI but don’t want to use that cause it’s really slow and inefficiant imho. I am not really a specialist so I would ask for your indulgence 🙂

Thank you!

Use filename insted of ‘Download’

On my Django page I have a paragraph to download attached files:

{% for i in post.file_set.all %}<p class="article-content mt-2 mb-1"><strong>Attachment {{ forloop.counter }}: </strong><a href="{{i.file.url}}" >Download</a></p>{% endfor %}

How can I show File name insted of word ‘Download’. Users don’t know which file is which when downloading, in case of many files. Also, if extension is possible.

So, insted of:

Attachment: Download

I would like to have:

Attachment: image.png