Sunday, 29 November 2020

How to list all root folder and shares on the Google Drive API v3 while paging and using order by?

I've seen a few questions about this but none cover my scenario.

Basically what I want is to use tokens to do paging and also list all folders and files in the root folder including shared files and folders.

This appears to be working, but once I add orderBy it doesn't work well. It works ok with sorting if I remove or sharedWithMe = true but once I add it it like the shared items aren't sorted.

What am I doing wrong?

This is my code (Kotlin and on Android):

val response =
 gDriveClient.files()
 .list()
 .setSpaces("drive")
 .setCorpora("user")
 .setFields("files(id, name, size, modifiedTime, mimeType, parents, quotaBytesUsed),nextPageToken")
 .setQ("('root' in parents or sharedWithMe = true) and trashed = false")
 .setOrderBy("folder,name")
 .setPageSize(params.loadSize)
 .setPageToken(token)


from How to list all root folder and shares on the Google Drive API v3 while paging and using order by?

How to use Firebase Cloud Messaging with NextJS API Routes

According to the Firebase Cloud Messaging docs on Setting up Javascript Client, it is required that you place a firebase-messaging-sw.js file in the root of your domain. In the NextJS examples with-firebase-cloud-messaging, the firebase-messaging-sw.js is configured using a custom server.

const express = require('express')
const next = require('next')

const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()

app.prepare().then(() => {
  const server = express()

  server.get('/service-worker.js', (req, res) => {
    app.serveStatic(req, res, './.next/service-worker.js')
  })

  const serviceWorkers = [
    {
      filename: 'service-worker.js',
      path: './.next/service-worker.js',
    },
    {
      filename: 'firebase-messaging-sw.js',
      path: './static/firebase-messaging-sw.js',
    },
  ]

  serviceWorkers.forEach(({ filename, path }) => {
    server.get(`/${filename}`, (req, res) => {
      app.serveStatic(req, res, path)
    })
  })

  server.get('*', (req, res) => {
    return handle(req, res)
  })

  server.listen(port, (err) => {
    if (err) throw err
    console.log(`> Ready on http://localhost:${port}`)
  })
})

My Application is already using API Routes, so do I need to also add a custom server, or is there a way this can be achieved with API Routes?



from How to use Firebase Cloud Messaging with NextJS API Routes

How to Concatenate 5 Images Out Of Multiple Images In a Folder

I have a folder which has multiple images lets say images names are----

AB_1.jpg, AB_2.jpg, AB_3.jpg, AB_4.jpg, AB_5.jpg, AB_6.jpg, AB_7.jpg, AB_8.jpg, BC_1.jpg, BC_2.jpg, BC_3.jpg, CA_1.jpg, CA_2.jpg

Here my objective is to concatenate all the images till _5 or less than _5 as one image....

So basically what I am saying is that--- AB_1.jpg, AB_2.jpg, AB_3.jpg, AB_4.jpg, AB_5.jpg

will get concatenated vertically and file name lets say will be AB_Concat.jpg

_6,_7,_8 are skipped because we want to concatenate only images till _5 as one....

Similarly,, BC_1.jpg, BC_2.jpg, BC_3.jpg

will get concatenated vertically and file name lets say will be BC_Concat.jpg as you can see here BC_3 is last one which is less than _5 so all will be concatenated vertically.....

So if anyone have any idea on how to achieve the same please help....

This question is not similar to the once where two images are concatenated since here we are concatenating images on the basis of value after underscore in a image....

This is something which I tried--- '''python

import cv2

import shutil

import numpy as np

import os

from PIL import Image

path = r"D:\split"

out = r"D:\concat_test"

os.makedirs(out,exist_ok=True)

imag_name =[]

imag_name1 = []

for img in os.listdir(path):

folder  = img.rsplit("_",1)[0]  

imag_name1.append((folder,img))

images = cv2.imread(os.path.join(path,img),0)

imag_name.append((folder,images))

to create a folder for multiple images contain same name

for image,name in zip(imag_name,imag_name1):

if image[0] == name[0]:

    folder_n = os.path.join(out,name[0])

    final_fldr = os.path.join(folder_n,name[1])

    os.makedirs(folder_n,exist_ok=True)

    cv2.imwrite(final_fldr,image[1])

to concatinate the images

for root,dirs,files in os.walk(out):

np_images = [cv2.imread(os.path.join(root,file),0) for file in files]

np_name = list(set([file.rsplit("_",1)[0] for file in files]))


if len(np_images) != 0:

    print(np_name)

    concat = cv2.vconcat(np_images)

    concatinated_images = os.path.join(out,"concatinated_images")

    os.makedirs(concatinated_images,exist_ok=True)

    cv2.imwrite(os.path.join(concatinated_images,*np_name)+".tif",concat)

#to remove the unwanted folder

for remove_folder in os.listdir(out):

if remove_folder != "concatinated_images":

    folders_to_remove = os.path.join(out,remove_folder)

    shutil.rmtree(folders_to_remove)

'''



from How to Concatenate 5 Images Out Of Multiple Images In a Folder