53 lines
1.7 KiB
JavaScript
53 lines
1.7 KiB
JavaScript
// this is straight up just copied from google appsscript
|
|
|
|
function getFiles() {
|
|
const thisYear = new Date().getFullYear().toString()
|
|
const dregdayFolder = DriveApp.getFolderById(process.env.DREGDAY_FOLDER_ID)
|
|
const prepSheet = SpreadsheetApp.openById(process.env.DREGDAY_PREP_SHEET_ID)
|
|
const folder = dregdayFolder.getFoldersByName(thisYear).next()
|
|
const specials = folder.getFolders()
|
|
const dregs = folder.getFiles()
|
|
const entries = []
|
|
|
|
const makeEntry = (file) => {
|
|
return {
|
|
url: file.getUrl(),
|
|
direct: file.getDownloadUrl(),
|
|
name: file.getName(),
|
|
category: file.getParents().next().getName(),
|
|
mimeType: file.getMimeType(),
|
|
caption: ""
|
|
}
|
|
}
|
|
|
|
const isImage = mimeType => mimeType?.slice(0,6) === "image/"
|
|
|
|
while (specials.hasNext()) {
|
|
const items = specials.next().getFiles()
|
|
while (items.hasNext()) {
|
|
const entry = makeEntry(items.next())
|
|
if (isImage(entry.mimeType)) entries.push(entry)
|
|
}
|
|
}
|
|
while (dregs.hasNext()) {
|
|
const entry = makeEntry(dregs.next())
|
|
if (isImage(entry.mimeType)) entries.push(entry)
|
|
}
|
|
|
|
|
|
if (!prepSheet.getSheetByName(thisYear)) prepSheet.insertSheet(thisYear)
|
|
else prepSheet.getSheetByName(thisYear).activate()
|
|
|
|
const active = prepSheet.getActiveSheet()
|
|
active.setFrozenRows(1)
|
|
active.setFrozenColumns(3)
|
|
active.getRange('A1:H1').setValues([["Status", "Category", "Name", "URL", "Machine Caption", "Image Description", "Post", "Notes"]])
|
|
|
|
for (let i = 0; i < entries.length; i++) {
|
|
const row = i+2
|
|
const entry = entries[i]
|
|
const category = entry.category.toString() === thisYear ? "General" : entry.category
|
|
active.getRange(row, 1, 1, 5).setValues([[false, entry.category, entry.name, entry.url, entry.caption]])
|
|
}
|
|
}
|