-
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 image insertion support to codepress #89
Conversation
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.
Looks great! 💯
A few comments.
packages/client/codepress/src/app.ts
Outdated
const filename = `${file.md5}_${file.name}`; | ||
const filepath = path.join(absDir, filename); | ||
|
||
console.log(`[UPLOAD] saving file for ${req.params.resourceId} at `); |
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.
Is this supposed to log the filename, e.g. at ...?
?
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.
Ah... Yes it is 😅
console.log(`[UPLOAD] saving file for ${req.params.resourceId} at `); | ||
file.mv(filepath, err => { | ||
if (err) { | ||
next(err); |
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.
Would this still result in res.send
getting called later on line 142?
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.
Oh good call. I don't think so, but even if not it's not obvious so I'll add an early return
@@ -294,6 +313,13 @@ class ContentEditor extends React.Component<Props> { | |||
.toPromise(); | |||
}; | |||
|
|||
handleFileUpload = (file: File): Promise<string> => { | |||
if (!this.props.challengeId) { |
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.
Would it make sense to move the error checking to the uploadFile
method?
Not a big deal if it stays here.
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.
Yeah that would work too. Will update.
What this does:
public/
directory of the client projectThe rationale behind the second point is that we ideally want any images or
assets of any kind associated with challenges to be available as long as the
challenges are. For this reason using external URLs is less appealing than it
otherwise might be.
The alternative to this would be dropping images into a google storage bucket,
however that would require codepress users to be authorized with gcloud which is
a whole nother can of worms that I'd rather avoid for now.
NOTE: There are a few issues with the implementation...
This second point sucks, and I'm not sure what's going on there however my guess
is that rich-markdown-editor is rendering the image in such a way that the key
is prone to change often. I saw this in the inspector, although I'm not sure it's
the issue.
However, I'd still like to ship this even with caveats because we do not upload
many images and even when the editor does break the output markdown is correct
and it is read back correctly meaning it is not a user facing bug from what I
can tell.