javascript – List sub-folders and its ID in the given path in Google Drive with Google App Script

I am trying to create a doc file which contains the list of folders in a given folder path. The Main function is the entry point.

// This function performs the operation of creating the file of the list of folders in the specific folder.
// Usage: Set the ListDocName, the ListDocFullPath, and the SpecificFolder, then just run Main function.
function Main() {
  // Set Doc (output) file name
  var ListDocName = "RootFolderList";
  
  // Set Doc (output) file path
  var ListDocFullPath = "/";
  
  // Set specific folder, and this program would list its subfolders to Doc file.
  var SpecificFolder = "/";
  
  CreateGoogleDocInSpecificFolder(ListDocName, ListDocFullPath);
  var DocFiles = GoogleDocsInSpecificFolder(ListDocName, ListDocFullPath);
  
  while(DocFiles.hasNext())
  {
    var docFile = DocFiles.next();
    var docID = docFile.getId();
    var doc = DocumentApp.openById(docID);
    
    var Folders = FoldersInSpecificFolder(SpecificFolder);
    while(Folders.hasNext())
    {
      var Folder = Folders.next();
      // Access the body of the document, then add a paragraph.
      doc.getBody().appendParagraph(SpecificFolder + '/' + Folder.getName() + 't' + Folder.getId());
    }
    doc.saveAndClose();
  }
}

// FoldersInSpecificFolder function would return a FileIterator
function FoldersInSpecificFolder(FolderFullPath)
{
  if(FolderFullPath == '/')
  {
    // Return the FolderIterator in Root.
    return getFolder(FolderFullPath);
  }
  else
  {
    // getFolder return the FolderIterator
    var TargetFolders = getFolder(FolderFullPath);
    while (TargetFolders.hasNext())
    {
      var folder = TargetFolders.next();
      return folder.getFolders();
    }
  } 
}

// GoogleDocsInSpecificFolder function would return a FileIterator
function GoogleDocsInSpecificFolder(docName, FolderFullPath)
{
  if(FolderFullPath == '/')
  {
    // Read files in Root, getFilesByName return the FileIterator
    var RootDocs = DriveApp.getRootFolder().getFilesByName(docName);
    return RootDocs;
  }
  else
  {
    // getFolder return the FolderIterator
    var TargetFolders = getFolder(FolderFullPath);   
    while (TargetFolders.hasNext())
    {
      var folder = TargetFolders.next();
      var docFiles = folder.getFilesByName(docName);
      return docFiles;
    }
  } 
}

function CreateGoogleDocInSpecificFolder(docName, FolderFullPath)
{
  var docID;
  if(FolderFullPath == '/')
  {
    // Create a new Google Doc in Root
    var docRoot = DocumentApp.create(docName);
    var docRootID = docRoot.getId();
    docRoot.saveAndClose();
    return docRootID;
  }
  else
  {
    // Create a new Google Doc in Root
    var docRoot = DocumentApp.create(docName);
    var docRootID = docRoot.getId();
    docRoot.saveAndClose();
    
    // Get new Google Doc file ID (Use in copy)
    var docRootFile = DriveApp.getFileById(docRootID);
    
    var TargetFolders = getFolder(FolderFullPath);   
    while (TargetFolders.hasNext())
    {
      var folder = TargetFolders.next();
      
      // Copy Google Doc to correct file path
      var docFile = docRootFile.makeCopy(docName, folder);
      
      docID = docFile.getId();
    }
    
    // Delete Google Doc in Root
    DriveApp.removeFile(docRootFile);
    
    return docID;
  } 
}

// getFolder function would return the FolderIterator which is locate at Path.
function getFolder(Path)
{
  var SubFolder;
  var arr = Path.split("/");
  for (var i = 1; i < arr.length; i = i + 1)
  {
    var FolderName = arr(i);
    if(i == 1)
    {
      SubFolder = DriveApp.getRootFolder().searchFolders("title contains '"+FolderName+"'");
    }
    else
    {
      if (SubFolder.hasNext())
      {
        var folderTemp = SubFolder.next();
        SubFolder = folderTemp.searchFolders("title contains '"+FolderName+"'");
      }
    }
  }
  return SubFolder;
}

If there is any possible improvement about potential drawback, please let me know.

path aliases – [D8/Drupal8]: Pathauto pattern for a content type depending on a reference field?

This question is already asked here, but the answer selected does not work for Drupal8.

Description: There is a content-type, which has field, referencing taxonomy term. The term is in “Content class” dictionary. This term is used in views to filter the right content for the view. When a link in the view is clicked, it opens the node. This is OK.
So, it is needed pathauto to generate /Content class term/Content_title_name when this node is opened.

What is tried: (node:field_content_class:value)/(node:title). This is not accepted, produces error: Path pattern is using the following invalid tokens: (node:field_

The accepted (by Drupal) pattern: (node:field_content_class)/(node:title) generates alias, containing only the (node:title) part. The first component is empty.

This is made to not create separate content-types for nodes with the same fields.

Given graph G and vertices v and w can you non-deterministically walk the “least Hamiltonian path” from v to w, if it exists?

My understanding of non-deterministic algorithms is that they’re “as lucky as you want”.

…you can think of the algorithm as being able to make a guess at any point it wants, and a space alien magically guarantees it will always make the right/lucky guess.

For example, if you choose two vertices v and w, if there’s a vw path, then you can non-deterministically walk a vw path, luckily correctly guessing the vertices to walk in a vw path. Given this is true of paths in general, I wonder if the same can be done for Hamiltonian paths. I would think so, but I’m not sure.

Therefore, my first question is: if you can non-deterministically walk a vw path, can you non-deterministically walk a Hamiltonian path from v to w, if a Hamiltonian path exists? If you can non-deterministically walk a Hamiltonian path, I wonder if the same can be done for an additional constraint, what I’m calling a “least Hamiltonian path.” I would think so, but I’m not sure.

Define the least Hamiltonian path from v to w to be the Hamiltonian path such that the second vertex is the smallest it can be, then the third vertex is the smallest it can be, the fourth is the smallest, etc. Assume vertices are integers. For example, if we consider K5 the graph with vertices {1,2,3,4,5} and all possible edges, then the least Hamiltonian path for (v,w) = (2,3) is 21453. If you were at vertex 2, the next least vertex would be 1. Then, the next least vertex would 4. etc.

Therefore, my actual question is: Given graph G and vertices v and w can you non-deterministically walk the least Hamiltonian path from v to w, if it exists?

Motivation: If so, then perhaps there’s a space-efficient algorithm for non-deterministically walking a Hamiltonian path: You can keep a counter for vertices v and w, and go through each pair of vertices such that v<w, checking for the existence of a least Hamiltonian path. To ensure all vertices in G are reached, keep a counter for the number of vertices walked (this should equal N if there are N vertices). Also, ensure that each vertex in the path is unique. The least Hamiltonian path from v to w will be unique, therefore it can be walked multiple times (each time you walk through it, starting at v, you’ll non-deterministically guess the next least vertex in the least Hamiltonian path). You could use two counters to ensure no vertices are repeated – one for the vertex you’re checking to see if it’s unique (loop through the vertices in the least Hamiltonian path), and another counter for a second pass through the least Hamiltonian path. Ensure the second counter encounters the value of the first counter exactly once (use a boolean flag to keep track of this).

views – Contextual Filter Path Alias

I searched for this for some time now but couldnt find an anwser. I am using drupal 9.1.5 and pathauto. I have content types department and depratment news. The news are linked to the department. So whenever you create a department news you link it to a department. Now I want to display all depratment news linked to the department when i am on the department page (all children) and when I am on a page of a children (department news) I want to display all siblings, i.e. all departments news linked with the same department.

My url for departments is
(node:title)
and for department news is
(node:field_department:entity)/(node:title)

I thought that using a contextual filter in my view using the raw value from the url would work. So I used path component 1 and checked to use path alias. However this does not display anything.
enter image description here

When using path component 2 and disable to use path alias it works for the department news, which makes sence as I am internally on page node/xxx. I was so frustrated that I tried every other combination of path component and use path alias but nothing works. When using a fixed value for a department everything works as expected for that specific department

Steer a path for financial harmony with QuickBooks Online For WHMCS 1.7.0! | Proxies-free

Accounting Doesn’t Have To Be Mind-Numbing!

Every little thing you would expect to handle finance dealings of your business in an effortless manner sealed up in a single tool – this is our QuickBooks Online For WHMCS!

As soon as you start exploring new functionalities inside the module’s freshly launched 1.7.0 version, you will spot a broadened selection of relations between the collected financial details. Now, you are free to set up Custom Rules that shall be applied in case certain items appear on the invoice but have no relation with any QuickBooks service. Furthermore, the update offers the possibility to define a relation between WHMCS transaction fees and QuickBooks deposit account via the Gateway Fee Account feature.

Sneak a closer look at all new advantages of QuickBooks Online For WHMCS 1.7.0!

Have you seen what other module updates arrived in our Marketplace as of late?

Need Custom Software Development For Your Business?

Specially for you we will adapt an application and its design to your own needs, create a new module or even a completely new system built from scratch!

javascript – How do I get the image path inside a jsonapi response?

I a content type for movies that includes plain text fields, and an image. The field name for the image is field_movie_poster.

Am using JSON API to expose the endpoints, and my JavaScript looks like this:

getMovies() {
    fetch('https://drupal-api.ddev.site/jsonapi/node/movies')
    .then(res => {
        return res.json()
    })
    .then(res => {
        
        this.movies.push(...res.data)
        console.log(res.data)

    })
    .catch(err => console.log(err))
}

How do I include the image path in the request?

If you look at the image attached, you will see that field_movie_poster is under the relationships attribute, and it does not include the image path.

enter image description here

REST API is protected by HMAC based authentication. What does including URL path in the message protect from?

I have came across a REST API for some commercial software, that checks authentication by requiring HMAC on concatenation of

  • http_method (GET, PUT, etc)
  • timestamp
  • payload (body of a POST / PUT request if any)
  • path (everything between https://domain.tld and the first question mark)

This HMAC then is passed in a request header.

What does this scheme protect against by including the path?