From c8d90a04991c574e7f10a356ada9548c78aec16c Mon Sep 17 00:00:00 2001 From: lolimay Date: Fri, 18 Sep 2020 23:42:22 +0800 Subject: [PATCH 1/7] [Apps] Add a new upload API - createUpload --- app/apps/server/bridges/uploads.js | 9 +++++++++ app/file-upload/server/lib/FileUpload.js | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/apps/server/bridges/uploads.js b/app/apps/server/bridges/uploads.js index fced605713f9..d22384765cda 100644 --- a/app/apps/server/bridges/uploads.js +++ b/app/apps/server/bridges/uploads.js @@ -26,4 +26,13 @@ export class AppUploadBridge { }); }); } + + createUpload(details, buffer, appId) { + this.orch.debugLog(`The App ${ appId } is creating an upload "${ details.name }"`); + + const fileStore = FileUpload.getStore('Uploads'); + const uploadedFile = fileStore.insertSync(details, buffer); + + return this.orch.getConverters().get('uploads').convertToApp(uploadedFile); + } } diff --git a/app/file-upload/server/lib/FileUpload.js b/app/file-upload/server/lib/FileUpload.js index b03ea21f337a..5b6a6078e6aa 100644 --- a/app/file-upload/server/lib/FileUpload.js +++ b/app/file-upload/server/lib/FileUpload.js @@ -66,7 +66,7 @@ export const FileUpload = { const room = Rooms.findOneById(file.rid); const directMessageAllowed = settings.get('FileUpload_Enabled_Direct'); const fileUploadAllowed = settings.get('FileUpload_Enabled'); - if (canAccessRoom(room, user, file) !== true) { + if (canAccessRoom(room, user, file) !== true && user.type !== 'app') { return false; } const language = user ? user.language : 'en'; From c1eac6712dd333d5a1b1e8df79affb0ceba1d83d Mon Sep 17 00:00:00 2001 From: Douglas Gubert Date: Fri, 18 Sep 2020 19:05:06 -0300 Subject: [PATCH 2/7] Update Apps-Engine version --- package-lock.json | 152 +++++++++++++++++++++++++++++++++++++--------- package.json | 3 +- 2 files changed, 126 insertions(+), 29 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3b2455825f34..4237a93bd073 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5028,12 +5028,13 @@ } }, "@rocket.chat/apps-engine": { - "version": "1.17.0", - "resolved": "https://registry.npmjs.org/@rocket.chat/apps-engine/-/apps-engine-1.17.0.tgz", - "integrity": "sha512-4jsN9RUQR9zvZnOr4IZj9bnZR5/kAuSpKJ3JwqTv/DXBeHRSrCCCX0EDoZh5akmQu6x9tRpAXd1DRJWRfI5/Jw==", + "version": "1.18.0-alpha.3806", + "resolved": "https://registry.npmjs.org/@rocket.chat/apps-engine/-/apps-engine-1.18.0-alpha.3806.tgz", + "integrity": "sha512-MmeO/OBwpRR9Re2Y4zd4M4lo+SG8YtKMIKmPu9qY3mdngcpzVQ54l3Nf2qLU8YX4H1PFrw2G1LJIU6ap0KtZVg==", "requires": { "adm-zip": "^0.4.9", "cryptiles": "^4.1.3", + "file-type": "^15.0.1", "lodash.clonedeep": "^4.5.0", "semver": "^5.5.0", "stack-trace": "0.0.10", @@ -5041,10 +5042,16 @@ "uuid": "^3.2.1" }, "dependencies": { - "adm-zip": { - "version": "0.4.16", - "resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.4.16.tgz", - "integrity": "sha512-TFi4HBKSGfIKsK5YCkKaaFG2m4PEDyViZmEwof3MTIgzimHLto6muaHVpbrljdIvIrFZzEq/p4nafOeLcYegrg==" + "file-type": { + "version": "15.0.1", + "resolved": "https://registry.npmjs.org/file-type/-/file-type-15.0.1.tgz", + "integrity": "sha512-0LieQlSA3bWUdErNrxzxfI4rhsvNAVPBO06R8pTc1hp9SE6nhqlVyvhcaXoMmtXkBTPnQenbMPLW9X76hH76oQ==", + "requires": { + "readable-web-to-node-stream": "^2.0.0", + "strtok3": "^6.0.3", + "token-types": "^2.0.0", + "typedarray-to-buffer": "^3.1.5" + } }, "typescript": { "version": "2.9.2", @@ -8136,6 +8143,11 @@ } } }, + "@tokenizer/token": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/@tokenizer/token/-/token-0.1.1.tgz", + "integrity": "sha512-XO6INPbZCxdprl+9qa/AAbFFOMzzwqYxpjPgLICrMD6C2FCw6qfJOPcBk6JqqPLSaZ/Qx87qn4rpPmPMwaAK6w==" + }, "@types/anymatch": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/@types/anymatch/-/anymatch-1.3.1.tgz", @@ -8220,8 +8232,7 @@ "@types/debug": { "version": "4.1.5", "resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.5.tgz", - "integrity": "sha512-Q1y515GcOdTHgagaVFhHnIFQ38ygs/kmxdNpvpou+raI9UO3YZcHDngBSYKQklcKlvA7iuQlmIKbzvmxcOE9CQ==", - "dev": true + "integrity": "sha512-Q1y515GcOdTHgagaVFhHnIFQ38ygs/kmxdNpvpou+raI9UO3YZcHDngBSYKQklcKlvA7iuQlmIKbzvmxcOE9CQ==" }, "@types/dedent": { "version": "0.7.0", @@ -13264,6 +13275,29 @@ "integrity": "sha512-JR/iSQOSt+LQIWwrwEzJ9uk0xfN3mTVYMwt1Ir5mUcSN6pU+V4zQFFaJsclJbPuAUQH+yfWef6tm7l1quW3C8Q==", "dev": true }, + "clean": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/clean/-/clean-4.0.2.tgz", + "integrity": "sha1-yfAW9wonzB8aOfypW1BAR+S28VM=", + "requires": { + "async": "^0.9.0", + "minimist": "^1.1.0", + "mix2": "^1.0.0", + "skema": "^1.0.0" + }, + "dependencies": { + "async": { + "version": "0.9.2", + "resolved": "https://registry.npmjs.org/async/-/async-0.9.2.tgz", + "integrity": "sha1-rqdNXmHB+JlhO/ZL2mbUx48v0X0=" + }, + "minimist": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", + "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==" + } + } + }, "clean-css": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/clean-css/-/clean-css-4.2.3.tgz", @@ -17909,7 +17943,7 @@ }, "chownr": { "version": "1.1.1", - "resolved": false, + "resolved": "", "integrity": "sha512-j38EvO5+LHX84jlo6h4UzmOwi0UgW61WRyPtJz4qaadK5eY3BTS5TY/S1Stc3Uk2lIM6TPevAlULiEJwie860g==", "dev": true, "optional": true @@ -17944,7 +17978,7 @@ }, "debug": { "version": "4.1.1", - "resolved": false, + "resolved": "", "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", "dev": true, "optional": true, @@ -17975,7 +18009,7 @@ }, "fs-minipass": { "version": "1.2.5", - "resolved": false, + "resolved": "", "integrity": "sha512-JhBl0skXjUPCFH7x6x61gQxrKyXsxB5gcgePLZCwfyCGGsTISMoIeObbrvVeP6Xmyaudw4TT43qV2Gz+iyd2oQ==", "dev": true, "optional": true, @@ -18009,7 +18043,7 @@ }, "glob": { "version": "7.1.3", - "resolved": false, + "resolved": "", "integrity": "sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==", "dev": true, "optional": true, @@ -18041,7 +18075,7 @@ }, "ignore-walk": { "version": "3.0.1", - "resolved": false, + "resolved": "", "integrity": "sha512-DTVlMx3IYPe0/JJcYP7Gxg7ttZZu3IInhuEhbchuqneY9wWe5Ojy2mXLBaQFUQmo0AW2r3qG7m1mg86js+gnlQ==", "dev": true, "optional": true, @@ -18062,7 +18096,7 @@ }, "inherits": { "version": "2.0.3", - "resolved": false, + "resolved": "", "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", "dev": true, "optional": true @@ -18110,7 +18144,7 @@ }, "minipass": { "version": "2.3.5", - "resolved": false, + "resolved": "", "integrity": "sha512-Gi1W4k059gyRbyVUZQ4mEqLm0YIUiGYfvxhF6SIlk3ui1WVxMTGfGdQ2SInh3PDrRTVvPKgULkpJtT4RH10+VA==", "dev": true, "optional": true, @@ -18121,7 +18155,7 @@ }, "minizlib": { "version": "1.2.1", - "resolved": false, + "resolved": "", "integrity": "sha512-7+4oTUOWKg7AuL3vloEWekXY2/D20cevzsrNT2kGWm+39J9hGTCBv8VI5Pm5lXZ/o3/mdR4f8rflAPhnQb8mPA==", "dev": true, "optional": true, @@ -18141,7 +18175,7 @@ }, "ms": { "version": "2.1.1", - "resolved": false, + "resolved": "", "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==", "dev": true, "optional": true @@ -18155,7 +18189,7 @@ }, "needle": { "version": "2.3.0", - "resolved": false, + "resolved": "", "integrity": "sha512-QBZu7aAFR0522EyaXZM0FZ9GLpq6lvQ3uq8gteiDUp7wKdy0lSd2hPlgFwVuW1CBkfEs9PfDQsQzZghLs/psdg==", "dev": true, "optional": true, @@ -18167,7 +18201,7 @@ }, "node-pre-gyp": { "version": "0.12.0", - "resolved": false, + "resolved": "", "integrity": "sha512-4KghwV8vH5k+g2ylT+sLTjy5wmUOb9vPhnM8NHvRf9dHmnW/CndrFXy2aRPaPST6dugXSdHXfeaHQm77PIz/1A==", "dev": true, "optional": true, @@ -18197,14 +18231,14 @@ }, "npm-bundled": { "version": "1.0.6", - "resolved": false, + "resolved": "", "integrity": "sha512-8/JCaftHwbd//k6y2rEWp6k1wxVfpFzB6t1p825+cUb7Ym2XQfhwIC5KwhrvzZRJu+LtDE585zVaS32+CGtf0g==", "dev": true, "optional": true }, "npm-packlist": { "version": "1.4.1", - "resolved": false, + "resolved": "", "integrity": "sha512-+TcdO7HJJ8peiiYhvPxsEDhF3PJFGUGRcFsGve3vxvxdcpO2Z4Z7rkosRM0kWj6LfbK/P0gu3dzk5RU1ffvFcw==", "dev": true, "optional": true, @@ -18284,7 +18318,7 @@ }, "process-nextick-args": { "version": "2.0.0", - "resolved": false, + "resolved": "", "integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw==", "dev": true, "optional": true @@ -18329,7 +18363,7 @@ }, "rimraf": { "version": "2.6.3", - "resolved": false, + "resolved": "", "integrity": "sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==", "dev": true, "optional": true, @@ -18360,7 +18394,7 @@ }, "semver": { "version": "5.7.0", - "resolved": false, + "resolved": "", "integrity": "sha512-Ya52jSX2u7QKghxeoFGpLwCtGlt7j0oY9DYb5apt9nPlJ42ID+ulTXESnt/qAQcoSERyZ5sl3LDIOw0nAn/5DA==", "dev": true, "optional": true @@ -18420,7 +18454,7 @@ }, "tar": { "version": "4.4.8", - "resolved": false, + "resolved": "", "integrity": "sha512-LzHF64s5chPQQS0IYBn9IN5h3i98c12bo4NCO7e0sGM2llXQ3p2FGC5sdENN4cTW48O915Sh+x+EXx7XW96xYQ==", "dev": true, "optional": true, @@ -18460,7 +18494,7 @@ }, "yallist": { "version": "3.0.3", - "resolved": false, + "resolved": "", "integrity": "sha512-S+Zk8DEWE6oKpV+vI3qWkaK+jSbIK86pCwe2IF/xwIpQ8jEuxpw9NyaGjmp9+BoJv5FV2piqCDcoCtStppiq2A==", "dev": true, "optional": true @@ -22988,6 +23022,11 @@ } } }, + "make-array": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/make-array/-/make-array-0.1.2.tgz", + "integrity": "sha1-M14267DFpDFU0hIToeyuriobs+8=" + }, "make-dir": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-1.3.0.tgz", @@ -24327,6 +24366,11 @@ "integrity": "sha512-ILj2TpLiysu2wkBbWjAmww7TkZb65aiQO+DkVdUTBpBXq+MHYiETENkKFMtsJZX1Lf4pe4QOrTSjIfUwN5lRdg==", "dev": true }, + "mix2": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/mix2/-/mix2-1.0.5.tgz", + "integrity": "sha512-ybWz7nY+WHBBIyliND5eYaJKzkoa+qXRYNTmVqAxSLlFtL/umT2iv+pmyTu1oU7WNkrirwheqR8d9EaKVz0e5g==" + }, "mixin-deep": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/mixin-deep/-/mixin-deep-1.3.1.tgz", @@ -26370,6 +26414,11 @@ "resolved": "https://registry.npmjs.org/pdfjs-dist/-/pdfjs-dist-2.4.456.tgz", "integrity": "sha512-yckJEHq3F48hcp6wStEpbN9McOj328Ib09UrBlGAKxvN2k+qYPN5iq6TH6jD1C0pso7zTep+g/CKsYgdrQd5QA==" }, + "peek-readable": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/peek-readable/-/peek-readable-3.1.0.tgz", + "integrity": "sha512-KGuODSTV6hcgdZvDrIDBUkN0utcAVj1LL7FfGbM0viKTtCHmtZcuEJ+lGqsp0fTFkGqesdtemV2yUSMeyy3ddA==" + }, "pend": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", @@ -29164,6 +29213,11 @@ "util-deprecate": "~1.0.1" } }, + "readable-web-to-node-stream": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/readable-web-to-node-stream/-/readable-web-to-node-stream-2.0.0.tgz", + "integrity": "sha512-+oZJurc4hXpaaqsN68GoZGQAQIA3qr09Or4fqEsargABnbe5Aau8hFn6ISVleT3cpY/0n/8drn7huyyEvTbghA==" + }, "readdirp": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-2.2.1.tgz", @@ -30444,6 +30498,23 @@ "simplebar": "^4.2.3" } }, + "skema": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/skema/-/skema-1.0.2.tgz", + "integrity": "sha1-NxIc/qHK7DEHLZVlhXSMmxGfxFM=", + "requires": { + "async": "^0.9.0", + "make-array": "^0.1.2", + "mix2": "^1.0.0" + }, + "dependencies": { + "async": { + "version": "0.9.2", + "resolved": "https://registry.npmjs.org/async/-/async-0.9.2.tgz", + "integrity": "sha1-rqdNXmHB+JlhO/ZL2mbUx48v0X0=" + } + } + }, "slash": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/slash/-/slash-1.0.0.tgz", @@ -31367,6 +31438,16 @@ "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=" }, + "strtok3": { + "version": "6.0.4", + "resolved": "https://registry.npmjs.org/strtok3/-/strtok3-6.0.4.tgz", + "integrity": "sha512-rqWMKwsbN9APU47bQTMEYTPcwdpKDtmf1jVhHzNW2cL1WqAxaM9iBb9t5P2fj+RV2YsErUWgQzHD5JwV0uCTEQ==", + "requires": { + "@tokenizer/token": "^0.1.1", + "@types/debug": "^4.1.5", + "peek-readable": "^3.1.0" + } + }, "stubs": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/stubs/-/stubs-3.0.0.tgz", @@ -32684,6 +32765,22 @@ "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz", "integrity": "sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw==" }, + "token-types": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/token-types/-/token-types-2.0.0.tgz", + "integrity": "sha512-WWvu8sGK8/ZmGusekZJJ5NM6rRVTTDO7/bahz4NGiSDb/XsmdYBn6a1N/bymUHuWYTWeuLUg98wUzvE4jPdCZw==", + "requires": { + "@tokenizer/token": "^0.1.0", + "ieee754": "^1.1.13" + }, + "dependencies": { + "ieee754": { + "version": "1.1.13", + "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.13.tgz", + "integrity": "sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg==" + } + } + }, "tough-cookie": { "version": "2.4.3", "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.4.3.tgz", @@ -33075,7 +33172,6 @@ "version": "3.1.5", "resolved": "https://registry.npmjs.org/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz", "integrity": "sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==", - "dev": true, "requires": { "is-typedarray": "^1.0.0" } diff --git a/package.json b/package.json index 0966101fb2fb..19be2d88fe70 100644 --- a/package.json +++ b/package.json @@ -128,7 +128,7 @@ "@nivo/heatmap": "^0.61.0", "@nivo/line": "^0.61.1", "@nivo/pie": "^0.61.1", - "@rocket.chat/apps-engine": "1.17.0", + "@rocket.chat/apps-engine": "1.18.0-alpha.3806", "@rocket.chat/css-in-js": "^0.14.1", "@rocket.chat/fuselage": "^0.14.1", "@rocket.chat/fuselage-hooks": "^0.14.1", @@ -163,6 +163,7 @@ "cas": "https://github.com/kcbanner/node-cas/tarball/fcd27dad333223b3b75a048bce27973fb3ca0f62", "change-case": "^4.1.1", "chart.js": "^2.9.3", + "clean": "^4.0.2", "clipboard": "^2.0.6", "codemirror": "^5.56.0", "coffeescript": "^2.5.1", From fe702245c39dbc74a3d4922765b2d7495d45196a Mon Sep 17 00:00:00 2001 From: Douglas Gubert Date: Fri, 18 Sep 2020 19:08:48 -0300 Subject: [PATCH 3/7] Update package.json --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 19be2d88fe70..9bf988a3b533 100644 --- a/package.json +++ b/package.json @@ -163,7 +163,6 @@ "cas": "https://github.com/kcbanner/node-cas/tarball/fcd27dad333223b3b75a048bce27973fb3ca0f62", "change-case": "^4.1.1", "chart.js": "^2.9.3", - "clean": "^4.0.2", "clipboard": "^2.0.6", "codemirror": "^5.56.0", "coffeescript": "^2.5.1", From e59fbcf804715adb038ed42864a40509b145c988 Mon Sep 17 00:00:00 2001 From: Douglas Gubert Date: Fri, 18 Sep 2020 20:28:39 -0300 Subject: [PATCH 4/7] Update Apps-Engine version --- package-lock.json | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4237a93bd073..d9650efe26ed 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5028,9 +5028,9 @@ } }, "@rocket.chat/apps-engine": { - "version": "1.18.0-alpha.3806", - "resolved": "https://registry.npmjs.org/@rocket.chat/apps-engine/-/apps-engine-1.18.0-alpha.3806.tgz", - "integrity": "sha512-MmeO/OBwpRR9Re2Y4zd4M4lo+SG8YtKMIKmPu9qY3mdngcpzVQ54l3Nf2qLU8YX4H1PFrw2G1LJIU6ap0KtZVg==", + "version": "1.18.0-beta.3837", + "resolved": "https://registry.npmjs.org/@rocket.chat/apps-engine/-/apps-engine-1.18.0-beta.3837.tgz", + "integrity": "sha512-cAdyBDW7TQNlTsMF/imgySXdGxh3RJdbeYV8Crzl9trHzq0Mu5PPOyZBcro/iutoNE6NxG3ZHS6/5ejf8Qg4BA==", "requires": { "adm-zip": "^0.4.9", "cryptiles": "^4.1.3", diff --git a/package.json b/package.json index 9bf988a3b533..a31a601d0b1f 100644 --- a/package.json +++ b/package.json @@ -128,7 +128,7 @@ "@nivo/heatmap": "^0.61.0", "@nivo/line": "^0.61.1", "@nivo/pie": "^0.61.1", - "@rocket.chat/apps-engine": "1.18.0-alpha.3806", + "@rocket.chat/apps-engine": "1.18.0-beta.3837", "@rocket.chat/css-in-js": "^0.14.1", "@rocket.chat/fuselage": "^0.14.1", "@rocket.chat/fuselage-hooks": "^0.14.1", From 44b03c424a47a6d1db0dbaef0a1c3d36ab84ee3f Mon Sep 17 00:00:00 2001 From: Douglas Gubert Date: Mon, 21 Sep 2020 22:05:47 -0300 Subject: [PATCH 5/7] Add mime detection to upload --- app/apps/lib/misc/determineFileType.js | 19 +++++++++++++++++++ app/apps/server/bridges/uploads.js | 3 +++ app/file-upload/server/lib/FileUpload.js | 2 +- 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 app/apps/lib/misc/determineFileType.js diff --git a/app/apps/lib/misc/determineFileType.js b/app/apps/lib/misc/determineFileType.js new file mode 100644 index 000000000000..8cc15ebfcf3b --- /dev/null +++ b/app/apps/lib/misc/determineFileType.js @@ -0,0 +1,19 @@ +import fileType from 'file-type'; + +import { mime as MIME } from '../../../utils/lib/mimeTypes'; + +export function determineFileType(buffer, details) { + const mime = MIME.lookup(details.name); + + if (mime) { + return Array.isArray(mime) ? mime[0] : mime; + } + + const detectedType = fileType(buffer); + + if (detectedType) { + return detectedType.mime; + } + + return 'application/octet-stream'; +} diff --git a/app/apps/server/bridges/uploads.js b/app/apps/server/bridges/uploads.js index d22384765cda..e7a974a2e5cd 100644 --- a/app/apps/server/bridges/uploads.js +++ b/app/apps/server/bridges/uploads.js @@ -1,4 +1,5 @@ import { FileUpload } from '../../../file-upload/server'; +import { determineFileType } from '../../lib/misc/determineFileType'; export class AppUploadBridge { constructor(orch) { @@ -30,6 +31,8 @@ export class AppUploadBridge { createUpload(details, buffer, appId) { this.orch.debugLog(`The App ${ appId } is creating an upload "${ details.name }"`); + details.type = determineFileType(buffer, details); + const fileStore = FileUpload.getStore('Uploads'); const uploadedFile = fileStore.insertSync(details, buffer); diff --git a/app/file-upload/server/lib/FileUpload.js b/app/file-upload/server/lib/FileUpload.js index 5b6a6078e6aa..1eab825ec6fe 100644 --- a/app/file-upload/server/lib/FileUpload.js +++ b/app/file-upload/server/lib/FileUpload.js @@ -66,7 +66,7 @@ export const FileUpload = { const room = Rooms.findOneById(file.rid); const directMessageAllowed = settings.get('FileUpload_Enabled_Direct'); const fileUploadAllowed = settings.get('FileUpload_Enabled'); - if (canAccessRoom(room, user, file) !== true && user.type !== 'app') { + if (user.type !== 'app' && canAccessRoom(room, user, file) !== true) { return false; } const language = user ? user.language : 'en'; From 2558df9bb7a9391da973e4a570b1721ab7499412 Mon Sep 17 00:00:00 2001 From: Douglas Gubert Date: Mon, 21 Sep 2020 23:16:25 -0300 Subject: [PATCH 6/7] Send file message on upload via apps --- app/apps/server/bridges/uploads.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/apps/server/bridges/uploads.js b/app/apps/server/bridges/uploads.js index e7a974a2e5cd..59e2fca88a7c 100644 --- a/app/apps/server/bridges/uploads.js +++ b/app/apps/server/bridges/uploads.js @@ -1,3 +1,5 @@ +import { Meteor } from 'meteor/meteor'; + import { FileUpload } from '../../../file-upload/server'; import { determineFileType } from '../../lib/misc/determineFileType'; @@ -36,6 +38,12 @@ export class AppUploadBridge { const fileStore = FileUpload.getStore('Uploads'); const uploadedFile = fileStore.insertSync(details, buffer); + if (details.userId) { + Meteor.runAsUser(details.userId, () => { + Meteor.call('sendFileMessage', details.rid, null, uploadedFile); + }); + } + return this.orch.getConverters().get('uploads').convertToApp(uploadedFile); } } From ff8ecf16d5b9f3dd6c8a0f21d934985d7b90a87b Mon Sep 17 00:00:00 2001 From: Douglas Gubert Date: Mon, 21 Sep 2020 23:17:40 -0300 Subject: [PATCH 7/7] Update Apps-Engine version --- package-lock.json | 113 +++------------------------------------------- package.json | 2 +- 2 files changed, 7 insertions(+), 108 deletions(-) diff --git a/package-lock.json b/package-lock.json index d9650efe26ed..53aa5bb25469 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5028,13 +5028,12 @@ } }, "@rocket.chat/apps-engine": { - "version": "1.18.0-beta.3837", - "resolved": "https://registry.npmjs.org/@rocket.chat/apps-engine/-/apps-engine-1.18.0-beta.3837.tgz", - "integrity": "sha512-cAdyBDW7TQNlTsMF/imgySXdGxh3RJdbeYV8Crzl9trHzq0Mu5PPOyZBcro/iutoNE6NxG3ZHS6/5ejf8Qg4BA==", + "version": "1.18.0-beta.3848", + "resolved": "https://registry.npmjs.org/@rocket.chat/apps-engine/-/apps-engine-1.18.0-beta.3848.tgz", + "integrity": "sha512-hGlsvrPalh8OszLFhXDZn2IJ8zBmsMF8SNEEVceZgb6hUvg/j4Ebqm+5O0AanRDurda+HzS29ZJP107guKtlHQ==", "requires": { "adm-zip": "^0.4.9", "cryptiles": "^4.1.3", - "file-type": "^15.0.1", "lodash.clonedeep": "^4.5.0", "semver": "^5.5.0", "stack-trace": "0.0.10", @@ -5042,17 +5041,6 @@ "uuid": "^3.2.1" }, "dependencies": { - "file-type": { - "version": "15.0.1", - "resolved": "https://registry.npmjs.org/file-type/-/file-type-15.0.1.tgz", - "integrity": "sha512-0LieQlSA3bWUdErNrxzxfI4rhsvNAVPBO06R8pTc1hp9SE6nhqlVyvhcaXoMmtXkBTPnQenbMPLW9X76hH76oQ==", - "requires": { - "readable-web-to-node-stream": "^2.0.0", - "strtok3": "^6.0.3", - "token-types": "^2.0.0", - "typedarray-to-buffer": "^3.1.5" - } - }, "typescript": { "version": "2.9.2", "resolved": "https://registry.npmjs.org/typescript/-/typescript-2.9.2.tgz", @@ -8143,11 +8131,6 @@ } } }, - "@tokenizer/token": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/@tokenizer/token/-/token-0.1.1.tgz", - "integrity": "sha512-XO6INPbZCxdprl+9qa/AAbFFOMzzwqYxpjPgLICrMD6C2FCw6qfJOPcBk6JqqPLSaZ/Qx87qn4rpPmPMwaAK6w==" - }, "@types/anymatch": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/@types/anymatch/-/anymatch-1.3.1.tgz", @@ -8232,7 +8215,8 @@ "@types/debug": { "version": "4.1.5", "resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.5.tgz", - "integrity": "sha512-Q1y515GcOdTHgagaVFhHnIFQ38ygs/kmxdNpvpou+raI9UO3YZcHDngBSYKQklcKlvA7iuQlmIKbzvmxcOE9CQ==" + "integrity": "sha512-Q1y515GcOdTHgagaVFhHnIFQ38ygs/kmxdNpvpou+raI9UO3YZcHDngBSYKQklcKlvA7iuQlmIKbzvmxcOE9CQ==", + "dev": true }, "@types/dedent": { "version": "0.7.0", @@ -13275,29 +13259,6 @@ "integrity": "sha512-JR/iSQOSt+LQIWwrwEzJ9uk0xfN3mTVYMwt1Ir5mUcSN6pU+V4zQFFaJsclJbPuAUQH+yfWef6tm7l1quW3C8Q==", "dev": true }, - "clean": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/clean/-/clean-4.0.2.tgz", - "integrity": "sha1-yfAW9wonzB8aOfypW1BAR+S28VM=", - "requires": { - "async": "^0.9.0", - "minimist": "^1.1.0", - "mix2": "^1.0.0", - "skema": "^1.0.0" - }, - "dependencies": { - "async": { - "version": "0.9.2", - "resolved": "https://registry.npmjs.org/async/-/async-0.9.2.tgz", - "integrity": "sha1-rqdNXmHB+JlhO/ZL2mbUx48v0X0=" - }, - "minimist": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==" - } - } - }, "clean-css": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/clean-css/-/clean-css-4.2.3.tgz", @@ -23022,11 +22983,6 @@ } } }, - "make-array": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/make-array/-/make-array-0.1.2.tgz", - "integrity": "sha1-M14267DFpDFU0hIToeyuriobs+8=" - }, "make-dir": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-1.3.0.tgz", @@ -24366,11 +24322,6 @@ "integrity": "sha512-ILj2TpLiysu2wkBbWjAmww7TkZb65aiQO+DkVdUTBpBXq+MHYiETENkKFMtsJZX1Lf4pe4QOrTSjIfUwN5lRdg==", "dev": true }, - "mix2": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/mix2/-/mix2-1.0.5.tgz", - "integrity": "sha512-ybWz7nY+WHBBIyliND5eYaJKzkoa+qXRYNTmVqAxSLlFtL/umT2iv+pmyTu1oU7WNkrirwheqR8d9EaKVz0e5g==" - }, "mixin-deep": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/mixin-deep/-/mixin-deep-1.3.1.tgz", @@ -26414,11 +26365,6 @@ "resolved": "https://registry.npmjs.org/pdfjs-dist/-/pdfjs-dist-2.4.456.tgz", "integrity": "sha512-yckJEHq3F48hcp6wStEpbN9McOj328Ib09UrBlGAKxvN2k+qYPN5iq6TH6jD1C0pso7zTep+g/CKsYgdrQd5QA==" }, - "peek-readable": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/peek-readable/-/peek-readable-3.1.0.tgz", - "integrity": "sha512-KGuODSTV6hcgdZvDrIDBUkN0utcAVj1LL7FfGbM0viKTtCHmtZcuEJ+lGqsp0fTFkGqesdtemV2yUSMeyy3ddA==" - }, "pend": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", @@ -29213,11 +29159,6 @@ "util-deprecate": "~1.0.1" } }, - "readable-web-to-node-stream": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/readable-web-to-node-stream/-/readable-web-to-node-stream-2.0.0.tgz", - "integrity": "sha512-+oZJurc4hXpaaqsN68GoZGQAQIA3qr09Or4fqEsargABnbe5Aau8hFn6ISVleT3cpY/0n/8drn7huyyEvTbghA==" - }, "readdirp": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-2.2.1.tgz", @@ -30498,23 +30439,6 @@ "simplebar": "^4.2.3" } }, - "skema": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/skema/-/skema-1.0.2.tgz", - "integrity": "sha1-NxIc/qHK7DEHLZVlhXSMmxGfxFM=", - "requires": { - "async": "^0.9.0", - "make-array": "^0.1.2", - "mix2": "^1.0.0" - }, - "dependencies": { - "async": { - "version": "0.9.2", - "resolved": "https://registry.npmjs.org/async/-/async-0.9.2.tgz", - "integrity": "sha1-rqdNXmHB+JlhO/ZL2mbUx48v0X0=" - } - } - }, "slash": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/slash/-/slash-1.0.0.tgz", @@ -31438,16 +31362,6 @@ "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=" }, - "strtok3": { - "version": "6.0.4", - "resolved": "https://registry.npmjs.org/strtok3/-/strtok3-6.0.4.tgz", - "integrity": "sha512-rqWMKwsbN9APU47bQTMEYTPcwdpKDtmf1jVhHzNW2cL1WqAxaM9iBb9t5P2fj+RV2YsErUWgQzHD5JwV0uCTEQ==", - "requires": { - "@tokenizer/token": "^0.1.1", - "@types/debug": "^4.1.5", - "peek-readable": "^3.1.0" - } - }, "stubs": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/stubs/-/stubs-3.0.0.tgz", @@ -32765,22 +32679,6 @@ "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz", "integrity": "sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw==" }, - "token-types": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/token-types/-/token-types-2.0.0.tgz", - "integrity": "sha512-WWvu8sGK8/ZmGusekZJJ5NM6rRVTTDO7/bahz4NGiSDb/XsmdYBn6a1N/bymUHuWYTWeuLUg98wUzvE4jPdCZw==", - "requires": { - "@tokenizer/token": "^0.1.0", - "ieee754": "^1.1.13" - }, - "dependencies": { - "ieee754": { - "version": "1.1.13", - "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.13.tgz", - "integrity": "sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg==" - } - } - }, "tough-cookie": { "version": "2.4.3", "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.4.3.tgz", @@ -33172,6 +33070,7 @@ "version": "3.1.5", "resolved": "https://registry.npmjs.org/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz", "integrity": "sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==", + "dev": true, "requires": { "is-typedarray": "^1.0.0" } diff --git a/package.json b/package.json index a31a601d0b1f..4467bb6d9882 100644 --- a/package.json +++ b/package.json @@ -128,7 +128,7 @@ "@nivo/heatmap": "^0.61.0", "@nivo/line": "^0.61.1", "@nivo/pie": "^0.61.1", - "@rocket.chat/apps-engine": "1.18.0-beta.3837", + "@rocket.chat/apps-engine": "1.18.0-beta.3848", "@rocket.chat/css-in-js": "^0.14.1", "@rocket.chat/fuselage": "^0.14.1", "@rocket.chat/fuselage-hooks": "^0.14.1",