This repository was archived by the owner on Nov 5, 2025. It is now read-only.
Conversation
Codecov Report
@@ Coverage Diff @@
## alpha #318 +/- ##
==========================================
- Coverage 53.20% 53.13% -0.07%
==========================================
Files 82 83 +1
Lines 2934 2949 +15
Branches 427 429 +2
==========================================
+ Hits 1561 1567 +6
- Misses 1373 1382 +9
Continue to review full report at Codecov.
|
12 tasks
Contributor
Author
import { Buffer } from 'buffer';
import { IAppAccessors, IHttp, ILogger, IModify, IPersistence, IRead } from '@rocket.chat/apps-engine/definition/accessors';
import { App } from '@rocket.chat/apps-engine/definition/App';
import { IMessage, IPostMessageSent } from '@rocket.chat/apps-engine/definition/messages';
import { IAppInfo } from '@rocket.chat/apps-engine/definition/metadata';
export class FileUploadApp extends App implements IPostMessageSent {
constructor(info: IAppInfo, logger: ILogger, accessors: IAppAccessors) {
super(info, logger, accessors);
}
public async executePostMessageSent(message: IMessage, read: IRead, http: IHttp, persistence: IPersistence, modify: IModify): Promise<void> {
try {
const { text, room } = message;
if (!text) {
return;
}
// ! An error will be thrown if without extension name
// await modify.getCreator().getUploadCreator().createUpload(room, 'example', Buffer.from(files.txt, 'base64'));
// ! An error will be thrown if extension is not matched with detected MIME type
// await modify.getCreator().getUploadCreator().createUpload(room, 'example.png', Buffer.from(files.pdf, 'base64'));
// Upload a txt file (plain text)
// const r1 = await modify.getCreator().getUploadCreator().createUpload(room, 'example.txt', Buffer.from(files.txt, 'base64'));
// console.log(`${ r1.name }: ${ r1.url }`);
// Upload a pdf file (binary)
// const r2 = await createUpload(room, 'example.pdf', Buffer.from(files.pdf, 'base64'));
// console.log(`${ r2.name }: ${ r2.url }`);
// Pressure Testing
const { name, complete, uploading, updatedAt, url } = await modify
.getCreator()
.getUploadCreator()
.createUpload(room, `${ Math.random() }.txt`, Buffer.from((Math.random() * 10 ** 6).toFixed(0)));
console.log({ name, complete, uploading, updatedAt, url });
} catch (err) {
console.error(err);
}
}
}Zip: fileupload_0.0.1.zip |
Contributor
Author
d-gubert
suggested changes
Sep 18, 2020
d-gubert
approved these changes
Sep 18, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What? ⛵
Introduced a new upload API
createUploadunder the accessormodify.getCreator().getUploadCreator().Why? 🤔
Closes #32
Links 🌎
https://app.clickup.com/t/24zkzh
PS 👀
The PR on the RC side: RocketChat/Rocket.Chat#18955