|
@@ -2,7 +2,7 @@ const querystring = require('querystring')
|
|
|
|
|
|
exports.getUsername = (data) => {
|
|
|
for (const item of data.files) {
|
|
|
- if (item.ownedByMe) {
|
|
|
+ if (item.ownedByMe && item.permissions) {
|
|
|
for (const permission of item.permissions) {
|
|
|
if (permission.role === 'owner') {
|
|
|
return permission.emailAddress
|
|
@@ -38,14 +38,40 @@ exports.getItemIcon = (item) => {
|
|
|
}
|
|
|
|
|
|
exports.getItemSubList = (item) => {
|
|
|
- return item.files
|
|
|
+ const allowedGSuiteTypes = [
|
|
|
+ 'application/vnd.google-apps.document',
|
|
|
+ 'application/vnd.google-apps.drawing',
|
|
|
+ 'application/vnd.google-apps.script',
|
|
|
+ 'application/vnd.google-apps.spreadsheet',
|
|
|
+ 'application/vnd.google-apps.presentation'
|
|
|
+ ]
|
|
|
+
|
|
|
+ return item.files.filter((i) => {
|
|
|
+ return exports.isFolder(i) || !exports.isGsuiteFile(i.mimeType) || allowedGSuiteTypes.includes(i.mimeType)
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
exports.getItemName = (item) => {
|
|
|
+ const extensionMaps = {
|
|
|
+ 'application/vnd.google-apps.document': '.docx',
|
|
|
+ 'application/vnd.google-apps.drawing': '.png',
|
|
|
+ 'application/vnd.google-apps.script': '.json',
|
|
|
+ 'application/vnd.google-apps.spreadsheet': '.xlsx',
|
|
|
+ 'application/vnd.google-apps.presentation': '.ppt'
|
|
|
+ }
|
|
|
+
|
|
|
+ const extension = extensionMaps[item.mimeType]
|
|
|
+ if (extension && item.name && !item.name.endsWith(extension)) {
|
|
|
+ return item.name + extension
|
|
|
+ }
|
|
|
+
|
|
|
return item.name ? item.name : '/'
|
|
|
}
|
|
|
|
|
|
exports.getMimeType = (item) => {
|
|
|
+ if (exports.isGsuiteFile(item.mimeType)) {
|
|
|
+ return exports.getGsuiteExportType(item.mimeType)
|
|
|
+ }
|
|
|
return item.mimeType
|
|
|
}
|
|
|
|
|
@@ -78,3 +104,19 @@ exports.getNextPagePath = (data, currentQuery, currentPath) => {
|
|
|
})
|
|
|
return `${currentPath}?${querystring.stringify(query)}`
|
|
|
}
|
|
|
+
|
|
|
+exports.isGsuiteFile = (mimeType) => {
|
|
|
+ return mimeType.startsWith('application/vnd.google')
|
|
|
+}
|
|
|
+
|
|
|
+exports.getGsuiteExportType = (mimeType) => {
|
|
|
+ const typeMaps = {
|
|
|
+ 'application/vnd.google-apps.document': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
|
+ 'application/vnd.google-apps.drawing': 'image/png',
|
|
|
+ 'application/vnd.google-apps.script': 'application/vnd.google-apps.script+json',
|
|
|
+ 'application/vnd.google-apps.spreadsheet': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
|
+ 'application/vnd.google-apps.presentation': 'application/vnd.openxmlformats-officedocument.presentationml.presentation'
|
|
|
+ }
|
|
|
+
|
|
|
+ return typeMaps[mimeType] || 'application/pdf'
|
|
|
+}
|