This is a dev diary of implementing Filerion, a web-based file manager for online storage (Dropbox, OneDrive, Google Drive, s3 and more).
Today:
implemented very simple text preview. It just loads text content into <pre> element
minor improvement to rename dialog: inform user about potentially un-intentional errors like ending the name with spaces or changing file extension:
fixed viewing of s3 text files by using Cloudflare workers
technote: to display a text file I get it’s content from URL with fetch and insert that content into <pre> tag. Browsers restrict ability to use fetch requests either to the same domain that is issuing a request or to a domain that explicitly allows access by anyone by setting the right CORS headers in responses. Unfortunately while we can get a public URL for any S3 file by using pre-signed urls, s3 servers by default don’t support CORS. To make it work the owner would have to configure the bucket properly, which is way too much to ask for users of an app like Filerion. The fix for this is relatively simple: write a proxy which will get the content for us. It could be done in Go backend but I chose to use Cloudflare workers instead. Mostly because Cloudflare bandwidth is much cheaper. Getting to learn a new technology is a bonus.