-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: master
Are you sure you want to change the base?
Conversation
@@ -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) { |
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 => { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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}>` |
There was a problem hiding this comment.
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)
No description provided.