33 lines
1.0 KiB
TypeScript
33 lines
1.0 KiB
TypeScript
import { createPhotoFolderForSku } from "./Product"
|
|
import { getColumnRichTextByName, getColumnValuesByName, toastAndLog } from "./sheetUtils"
|
|
import { Config } from "./config"
|
|
|
|
export function createMissingPhotoFolders() {
|
|
const ss = SpreadsheetApp.getActive()
|
|
const s = ss.getSheetByName("product_inventory")
|
|
if (!s) {
|
|
toastAndLog("Could not find 'product_inventory' sheet.")
|
|
return
|
|
}
|
|
|
|
let skus = getColumnValuesByName(s, "sku")
|
|
let photos = getColumnRichTextByName(s, "photos")
|
|
let config = new Config()
|
|
|
|
// Process rows backward, as that is where the missing folders are most likely to occur
|
|
for (let i = skus.length - 1; i >= 0; i--) {
|
|
const sku = String(skus[i][0])
|
|
if (!sku) {
|
|
continue
|
|
}
|
|
let folderUrl = photos[i][0].getLinkUrl()
|
|
if (folderUrl && folderUrl.includes("drive.google.com")) {
|
|
console.log(`Photo folder already exists for SKU: ${sku}`)
|
|
continue
|
|
}
|
|
|
|
createPhotoFolderForSku(config, sku)
|
|
}
|
|
toastAndLog("Finished creating missing photo folders.")
|
|
}
|