JSFiddle - React, Tailwind, and code Playground

by Haze32

JavaScript

//@hw-use-exceptions
include("config-stag.js")

var api = new HW_DC_API_Server()

apiConnect() // Function from config to check connection
apiAuth() // Function from config to check authentication

var objectID = decodeURIComponent("XXXXXXXXXXXX")

var destFolders = [
  "XXXXXXXXXXXX",
  "XXXXXXXXXXXX",
  "XXXXXXXXXXXX",
  "XXXXXXXXXXXX",
]

try {
  destFolders.forEach(function (itemUrl) {
    // Function to create a shortcut for the specified object in the target path
    function createShortcut(objectID, targetPath) {
      // Ensure targetPath is a string before applying string methods
      targetPath = String(targetPath)
      var fullPathUrl =
        targetPath + "/" + objectID.substring(objectID.lastIndexOf("/") + 1)

      writeln("Checking existence of the object at: " + fullPathUrl)
      if (!api.objectExists({ objectidentifier: fullPathUrl }).exists) {
        writeln("No existing object found at: " + fullPathUrl)
        writeln(
          "Attempting to create shortcut for: " +
            objectID +
            " in " +
            targetPath,
        )

        // Ensure that the shortcut is only created in archive paths and not in the live paths
        if (targetPath.toLowerCase().indexOf("/archive/") !== -1) {
          try {
            var out = api.link({
              objectidentifier: objectID,
              destinationparentidentifier: targetPath,
            })

            if (out.error.error()) {
              writeln("Failed to create shortcut in: " + targetPath)
              print_error(out.error)
            } else {
              writeln("Shortcut successfully created in: " + targetPath)
              writeln("Shortcut link: " + fullPathUrl)
            }
          } catch (error) {
            writeln(
              "Error during shortcut creation for " +
                fullPathUrl +
                ": " +
                error.message,
            )
          }
        } else {
          writeln(
            "Shortcut creation...