Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add file upload support #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

joshua-cain
Copy link

No description provided.

@joshua-cain joshua-cain requested a review from solb December 24, 2020 01:46
@@ -217,30 +220,64 @@ async function cached(memo, key, method, parameter, argument, workspace, update
return memo[key];
}

function call(method, body, workspace) {
function authHeaders(workspace) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: More general name, as it might have other headers in the future

headers: {
Authorization: 'Bearer ' + token,
...authHeaders(workspace),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this to headers: authHeaders(workspace), (or whatever we call it)

var payload = '';
var form = undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're making it undefined, why initialize it at all?

return [];
}

// TODO: figure out why this doesn't work
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop this. Rebase mistake?

@@ -267,6 +304,103 @@ async function collect_call(method, body, array, workspace) {
return collected;
}

async function get_event_files_data(event, workspace) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have this accept a files array instead of an event

if(event.files) {
const uploaded_files = await upload_files(await get_event_files_data(event, workspace), paired.workspace, paired.channel);
message.attachments = uploaded_files
.filter(file => typeof file === 'object' && file.permalink)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove filter() because we can trust upload_files().

const uploaded_files = await upload_files(await get_event_files_data(event, workspace), paired.workspace, paired.channel);
message.attachments = uploaded_files
.filter(file => typeof file === 'object' && file.permalink)
.map(file => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Closure style

@@ -721,6 +852,23 @@ async function handle_event(event) {
message.text, paired.workspace, users, event.channel);
}

if(event.files) {
const uploaded_files = await upload_files(await get_event_files_data(event, workspace), paired.workspace, paired.channel);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: const

@@ -3,6 +3,7 @@
"start": "node index.js"
},
"dependencies": {
"pg": "8.2.0"
"pg": "8.2.0",
"form-data": "3.0.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please alphabetize

.map(file => {
if(!file.mimetype || !file.mimetype.includes('image/')) {
return {
text: `<${file.permalink}|${file.name}>`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't appear to be working (at least for PDFs)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants