I try to make the CKEditor a good alternative to the current editors. Why? That's not important.
Currently I focus on the upload process. There is the /api/v2/media endpoint which is quite handy. You just need to POST the file to that api endpoint and it gets saved and an entry is made in the media table. That's a great starting point. But there are two features missing:
- The row in the Media table must show correctly ForeignID and ForeignType
- There must be a thumbnail created (if applicable)
I've got the code for the thumbnail creation, but I'm unsure about the best process. Currently I tend to implement a process like that:
- User (let's give him userID 7) drops picture flowers.jpg into editor
- EditorPlugin hooks into AfterSave event and updates GDN_Media where MediaID in $formValues['MediaIDs'], UserID = session->UserID, ForeignID = session->UserID, ForeignType = embed with Discussion/Comment and the corresponding ID
- Together with 5., also create a thumbnail file /uploads/953/thumbs/t_ZGHUJABS.jpg and update GDN_Media to keep the thumb information, too (I'll certainly do only one update call 5 & 6)
Does that sound reasonable and safe?
I thought about security problems when someone spoofes the hidden form field, but when the update checks for the InsertUserID, the ForeignID and -Type, I don't think there should be a problem. Current entries in the Media table can be changed and I will have to check if they will still work with the Rich Editor afterwards. But even if not: I wouldn't mind...
I had considered creating the thumbnail already during the main file upload (that's why I have implemented right now, but it certainly shouldn't stay like that) but if the post will be changed and the file will be deleted, than the rsources would be wasted. Also, if updating happens when the ForeignInformation is updated, there will be only one update call needed instead of two.
There are numerous ways uploading has been done in the past and nearly the same number of ways how thumbnail creation has been done in the past. Is there any reason to save the thumbs in another naming scheme? Which would be better and why?
Any feedback is welcome!