diff --git a/extensions.json b/extensions.json new file mode 100644 index 000000000..f007246bd --- /dev/null +++ b/extensions.json @@ -0,0 +1,382 @@ +[ + { + "extension": "aac", + "description": "AAC audio", + "category": "Music" + }, + { + "extension": "abw", + "description": "AbiWord document", + "category": "Document" + }, + { + "extension": "arc", + "description": "Archive document (multiple files embedded)", + "category": "Document" + }, + { + "extension": "avif", + "description": "AVIF image", + "category": "Image" + }, + { + "extension": "avi", + "description": "AVI: Audio Video Interleave", + "category": "Movie" + }, + { + "extension": "azw", + "description": "Amazon Kindle eBook format", + "category": "Document" + }, + { + "extension": "bin", + "description": "Any kind of binary data", + "category": "Other" + }, + { + "extension": "bmp", + "description": "Windows OS/2 Bitmap Graphics", + "category": "Image" + }, + { + "extension": "bz", + "description": "BZip archive", + "category": "Other" + }, + { + "extension": "bz2", + "description": "BZip2 archive", + "category": "Other" + }, + { + "extension": "cda", + "description": "CD audio", + "category": "Music" + }, + { + "extension": "csh", + "description": "C-Shell script", + "category": "Executable" + }, + { + "extension": "css", + "description": "Cascading Style Sheets (CSS)", + "category": "Other" + }, + { + "extension": "csv", + "description": "Comma-separated values (CSV)", + "category": "Document" + }, + { + "extension": "doc", + "description": "Microsoft Word", + "category": "Document" + }, + { + "extension": "docx", + "description": "Microsoft Word (OpenXML)", + "category": "Document" + }, + { + "extension": "eot", + "description": "MS Embedded OpenType fonts", + "category": "Other" + }, + { + "extension": "epub", + "description": "Electronic publication (EPUB)", + "category": "Document" + }, + { + "extension": "gz", + "description": "GZip Compressed Archive", + "category": "Other" + }, + { + "extension": "gif", + "description": "Graphics Interchange Format (GIF)", + "category": "Image" + }, + { + "extension": "htm", + "description": "HyperText Markup Language (HTML)", + "category": "Other" + }, + { + "extension": "html", + "description": "HyperText Markup Language (HTML)", + "category": "Other" + }, + { + "extension": "ico", + "description": "Icon format", + "category": "Image" + }, + { + "extension": "ics", + "description": "iCalendar format", + "category": "Document" + }, + { + "extension": "jar", + "description": "Java Archive (JAR)", + "category": "Executable" + }, + { + "extension": "jpeg", + "description": "JPEG images", + "category": "Image" + }, + { + "extension": "jpg", + "description": "JPEG images", + "category": "Image" + }, + { + "extension": "js", + "description": "JavaScript", + "category": "Other" + }, + { + "extension": "json", + "description": "JSON format", + "category": "Other" + }, + { + "extension": "jsonld", + "description": "JSON-LD format", + "category": "Other" + }, + { + "extension": "mid", + "description": "Musical Instrument Digital Interface (MIDI)", + "category": "Music" + }, + { + "extension": "midi", + "description": "Musical Instrument Digital Interface (MIDI)", + "category": "Music" + }, + { + "extension": "mjs", + "description": "JavaScript module", + "category": "Other" + }, + { + "extension": "mp3", + "description": "MP3 audio", + "category": "Music" + }, + { + "extension": "mp4", + "description": "MP4 video", + "category": "Movie" + }, + { + "extension": "mpeg", + "description": "MPEG Video", + "category": "Movie" + }, + { + "extension": "mpkg", + "description": "Apple Installer Package", + "category": "Application" + }, + { + "extension": "odp", + "description": "OpenDocument presentation document", + "category": "Presentation" + }, + { + "extension": "ods", + "description": "OpenDocument spreadsheet document", + "category": "Document" + }, + { + "extension": "odt", + "description": "OpenDocument text document", + "category": "Document" + }, + { + "extension": "oga", + "description": "OGG audio", + "category": "Music" + }, + { + "extension": "ogv", + "description": "OGG video", + "category": "Movie" + }, + { + "extension": "ogx", + "description": "OGG", + "category": "Other" + }, + { + "extension": "opus", + "description": "Opus audio", + "category": "Music" + }, + { + "extension": "otf", + "description": "OpenType font", + "category": "Other" + }, + { + "extension": "png", + "description": "Portable Network Graphics", + "category": "Image" + }, + { + "extension": "pdf", + "description": "Adobe Portable Document Format (PDF)", + "category": "PDF" + }, + { + "extension": "php", + "description": "Hypertext Preprocessor (Personal Home Page)", + "category": "Other" + }, + { + "extension": "ppt", + "description": "Microsoft PowerPoint", + "category": "Presentation" + }, + { + "extension": "pptx", + "description": "Microsoft PowerPoint (OpenXML)", + "category": "Presentation" + }, + { + "extension": "rar", + "description": "RAR archive", + "category": "Other" + }, + { + "extension": "rtf", + "description": "Rich Text Format (RTF)", + "category": "Document" + }, + { + "extension": "sh", + "description": "Bourne shell script", + "category": "Executable" + }, + { + "extension": "svg", + "description": "Scalable Vector Graphics (SVG)", + "category": "Image" + }, + { + "extension": "tar", + "description": "Tape Archive (TAR)", + "category": "Other" + }, + { + "extension": "tif", + "description": "Tagged Image File Format (TIFF)", + "category": "Image" + }, + { + "extension": "tiff", + "description": "Tagged Image File Format (TIFF)", + "category": "Image" + }, + { + "extension": "ts", + "description": "MPEG transport stream", + "category": "Movie" + }, + { + "extension": "ttf", + "description": "TrueType Font", + "category": "Other" + }, + { + "extension": "txt", + "description": "Text, (generally ASCII or ISO 8859-n)", + "category": "Text" + }, + { + "extension": "vsd", + "description": "Microsoft Visio", + "category": "Application" + }, + { + "extension": "wav", + "description": "Waveform Audio Format", + "category": "Music" + }, + { + "extension": "weba", + "description": "WEBM audio", + "category": "Music" + }, + { + "extension": "webm", + "description": "WEBM video", + "category": "Movie" + }, + { + "extension": "webp", + "description": "WEBP image", + "category": "Image" + }, + { + "extension": "woff", + "description": "Web Open Font Format (WOFF)", + "category": "Other" + }, + { + "extension": "woff2", + "description": "Web Open Font Format (WOFF)", + "category": "Other" + }, + { + "extension": "xhtml", + "description": "XHTML", + "category": "Other" + }, + { + "extension": "xls", + "description": "Microsoft Excel", + "category": "Document" + }, + { + "extension": "xlsx", + "description": "Microsoft Excel (OpenXML)", + "category": "Document" + }, + { + "extension": "xml", + "description": "XML", + "category": "Document" + }, + { + "extension": "xul", + "description": "XUL", + "category": "Application" + }, + { + "extension": "zip", + "description": "ZIP archive", + "category": "Application" + }, + { + "extension": "3gp", + "description": "3GPP audio/video container", + "category": "Movie" + }, + { + "extension": "3g2", + "description": "3GPP2 audio/video container", + "category": "Movie" + }, + { + "extension": "7z", + "description": "7-zip archive", + "category": "Application" + } +] \ No newline at end of file diff --git a/packages/basic.gblib/services/SystemKeywords.ts b/packages/basic.gblib/services/SystemKeywords.ts index c7a6ed3e1..75f51ea07 100644 --- a/packages/basic.gblib/services/SystemKeywords.ts +++ b/packages/basic.gblib/services/SystemKeywords.ts @@ -61,6 +61,7 @@ import { WebAutomationServices } from './WebAutomationServices.js'; import { KeywordsExpressions } from './KeywordsExpressions.js'; import { ChatServices } from '../../gpt.gblib/services/ChatServices.js'; import mime from 'mime-types'; +import exts from '../../../extensions.json' assert { type: 'json' }; /** * @fileoverview General Bots server core. @@ -1973,23 +1974,23 @@ export class SystemKeywords { const file = GBServer.globals.files[handle]; GBLog.info(`BASIC: Auto saving '${file.filename}' (SAVE file).`); let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min); + const path = DialogKeywords.getGBAIPath(min.botId, `gbdrive`); - try { - const contentType = mime.lookup(file.url ? file.url : file.name); - const kind = await getContentTypeFolder(contentType); - await client.api(`${baseUrl}/drive/root:/${path}/${kind}/${file.name}:/content`).put(file.data); - } catch (error) { - if (error.code === 'itemNotFound') { - GBLog.info(`BASIC: BASIC source file not found: ${file}.`); - } - throw error; + const fileName =file.url ? file.url : file.name; + const contentType = mime.lookup(fileName); + const ext = Path.extname(fileName).substring(1); + const kind = await this.getExtensionInfo(ext); + + const result = await client.api(`${baseUrl}/drive/root:/${path}/${kind.category}/${fileName}:/content`).put(file.data); + + return {contentType, ext, kind, category: kind['category']}; + } + public async getExtensionInfo(ext: any): Promise { + + let array = exts.filter((v, i, a) => a[i]['extension'] === ext); + if (array[0]) { + return array[0]; } - } -} -function getContentTypeFolder(contentType: any) { - // TODO: DS .jpog ->'image/jpg' -> IMages - // #359 - if (contentType === 'image/jpg') { - return 'Images'; + return {category: 'Other', description: 'General documents'}; } } diff --git a/packages/core.gbapp/services/GBMinService.ts b/packages/core.gbapp/services/GBMinService.ts index e97d402c5..bb75afb45 100644 --- a/packages/core.gbapp/services/GBMinService.ts +++ b/packages/core.gbapp/services/GBMinService.ts @@ -1313,7 +1313,10 @@ export class GBMinService { }; GBServer.globals.files[handle] = gbfile; - await t.internalAutoSave({min: min, handle:handle }); + const result = await t.internalAutoSave({min: min, handle:handle }); + await min.conversationalService.sendText(min, step, + `Seu arquivo ${gbfile.name} foi salvo no .gbdrive (${result.category}).` + ); } } else { @@ -1343,14 +1346,6 @@ export class GBMinService { } min.cbMap[userId].promise = results[0]; } - else - { - // Uploads file to .gbdrive associated folder. - - - } - - } }