Skip to main content

filepond library and plugins not being detected

I am learing Node.JS by webdevsimplified and i am developing a book library website and i am facing an issue. I have imported a filepond library and some plugins. They are working perfectly fine when i try to add a new book but when i try to edit an existing book the filepond library does not appear to be working then if i try to edit image then it throws an error an automatically filepond start to work i have debugged everything and i can not understand why is this happening. When i click to edit a cover this is what comes up and everything works without error except the cover updation. if i try to update cover it throws an error and then shows the page that is originally intended to show intended image

Some Code related to edit routes

books.js


    router.get('/:id/edit', async (req,res)=>{
        try {
            const book = await Book.findById(req.params.id)
            renderEditPage(res, book)
        } catch {
            res.redirect('/')
        }
    })
    
    // Update book route
    router.put('/:id', async (req,res)=>{
        let book
    
        try {
            book = await Book.findById(req.params.id)
            book.title = req.body.title
            book.author = req.body.author
            book.publishDate = new Date(req.body.publishDate)
            book.pageCount = req.body.pageCount
            book.description = req.body.description
            if(req.body.cover != null && req.body.cover !== ''){
            saveCover(book, req.body.cover)
            }
            await book.save()
            res.redirect(`/books/${book.id}`)
        } catch{
            if(book != null){
                renderEditPage(res,book, true)
            } else {
                redirect('/')
            }
        }
    })
    
    router.delete('/:id', async (req, res) => {
        let book
        try {
          book = await Book.findById(req.params.id)
          await book.remove()
          res.redirect('/books')
        } catch {
          if (book != null) {
            res.render('books/show', {
              book: book,
              errorMessage: 'Could not remove book'
            })
          } else {
            res.redirect('/')
          }
        }
      })
    
    async function renderNewPage(res,book , hasError = false){
        renderFormPage(res,book,'new',hasError)
    }
    
    async function renderEditPage(res,book , hasError = false){
        renderFormPage(res,book,'edit',hasError)
    }
    
    async function renderFormPage(res,book , form, hasError = false){
        try{
            const authors = await Author.find({})
            const params = {
                authors: authors,
                book: book,
            }
            if(hasError){
                if(form === 'edit'){
                    params.errorMessage = 'Error Updating Book'
                }
                else {
                    params.errorMessage = 'Error Creating Book'
                }
            }
            res.render(`books/${form}`, params)
        }catch{
            res.redirect('/books')
        }
    }
    
    function saveCover(book, coverEncoded){
        if (coverEncoded == null) return
        const cover = JSON.parse(coverEncoded)
        if (cover != null && imageMimeTypes.includes(cover.type)){
            book.coverImage = new Buffer.from(cover.data, 'base64')
            book.coverImageType = cover.type
        }
    }
    
    module.exports = router

edit.ejs


    <h2>Edit Book</h2>
    
    <form action="/books/<%= book.id %>?_method=PUT" method="POST">
        <%- include('_form_fields') %>
        <a href="/books">Cancel</a>
        <button type = "submit">Update</button>
    </form>

also the URL for the wrong edit page is http://localhost:3000/books/64ca52c7a9b8a5350ccb4e00/edit

while URL after an error is thrown becomes http://localhost:3000/books/64ca52c7a9b8a5350ccb4e00?_method=PUT

Via Active questions tagged javascript - Stack Overflow https://ift.tt/rQnPDdC

Comments

Popular posts from this blog

Confusion between commands.Bot and discord.Client | Which one should I use?

Whenever you look at YouTube tutorials or code from this website there is a real variation. Some developers use client = discord.Client(intents=intents) while the others use bot = commands.Bot(command_prefix="something", intents=intents) . Now I know slightly about the difference but I get errors from different places from my code when I use either of them and its confusing. Especially since there has a few changes over the years in discord.py it is hard to find the real difference. I tried sticking to discord.Client then I found that there are more features in commands.Bot . Then I found errors when using commands.Bot . An example of this is: When I try to use commands.Bot client = commands.Bot(command_prefix=">",intents=intents) async def load(): for filename in os.listdir("./Cogs"): if filename.endswith(".py"): client.load_extension(f"Cogs.{filename[:-3]}") The above doesnt giveany response from my Cogs ...

How to show number of registered users in Laravel based on usertype?

i'm trying to display data from the database in the admin dashboard i used this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count(); echo $users; ?> and i have successfully get the correct data from the database but what if i want to display a specific data for example in this user table there is "usertype" that specify if the user is normal user or admin i want to user the same code above but to display a specific usertype i tried this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count()->WHERE usertype =admin; echo $users; ?> but it didn't work, what am i doing wrong? source https://stackoverflow.com/questions/68199726/how-to-show-number-of-registered-users-in-laravel-based-on-usertype

Where and how is this Laravel kernel constructor called? [closed]

Where and how is this Laravel kernel constructor called? public fucntion __construct(Application $app, $Router $roouter) { } I have read the documentation and some online tutorial but I can find any clear explanation. I am learning Laravel and I am wondering where does this kernel constructor receives its arguments from. "POSTMOTERM" CLARIFICATION: Here is more clarity.I have checked the boostrap/app.php and it is only used for boostrapping the interfaces into the container class. What is not clear to me is where and how the Kernel class is instatiated and the arguments passed to the object calling the constructor.Something similar to; obj = new kernel(arg1,arg2) or, is the framework using some magic functions somewhere? Special gratitude to those who burn their eyeballs and brain cells on this trivia before it goes into a full blown menopause alias "MARKED AS DUPLICATE". To some of the itchy-finger keyboard warriors, a.k.a The mods,because I believe in th...