Transform URL Shorten Worker into R2 File Storage
Github
Transform into a File Storage Save to R2 Object Storage
Apply for a Cloudflare account, skipped.
Create R2
Set up public link
Set CORS Policy
Create R2 API
Click the Manage button
Create KV
Remember the name of this KV, using kvtest as an example
Create Worker Service
Set Up KV Binding
Edit the Worker's script content
Delete all the existing content
Replace it with the content from: https://github.com/crazypeace/Url-Shorten-Worker/blob/main/worker.js
Transform into File Storage lite
Set 5 variables:
Save and Deploy
Top right cornerStart using File Storage lite
Add the password as a path after the worker domain, e.g.
https://divine-voice-e752.crazypeace.workers.dev/suibianshezhishenme
Transform into a file hosting site (complete form)
Considering that the files in R2 may be large in size, and we only want to display small-sized thumbnails in the admin panel.Enable the Image Transformation feature
Set up a custom domain for R2
Modify the worker script
Modify the value of R2_PUBLIC_URL
R2_PUBLIC_URL = "https://r2test.xxxx.xxxx"
theme: "theme/file-r2", // File Storage Station (Complete Version)
Save and Deploy
Top-right cornerStart using the File Storage Station (Complete Version)
https://divine-voice-e752.crazypeace.workers.dev/suibianshezhishenme
======
Postscript
Click the "Upload to R2" button once, and then click the "Save KV" button once. It is indeed too tedious.
But, considering the "heritage" of the entire Url-Shorten-Worker series, I did not make further optimizations.
In the future, I will create a new repo to achieve further optimization and enhanced development.
======
The role of configuration parameters
result_page: false, // Whether to use a specific result page to display value
theme: "", // The theme of the management panel
cors: true, // Whether to allow CORS for the API
unique_link: false, // Whether a long link has only a unique short link (will increase write usage)
custom_link: true, // Allow custom short links
snapchat_mode: false, // Short link can only be accessed once (deleted after access)
visit_count: true, // Enable counting (will greatly increase write usage, not recommended for multi-user)
load_kv: false, // Load all data from KV (recommended for personal use, multi-user will see others' data)
system_type: "shorturl", // System function definition // shorturl, imghost, other types {pastebin, journal}
}
======
If used as a PasteBin
Demo site https://pastebin.crazypeace.workers.dev/tieludasiliqiuweiyue
Demo video https://www.youtube.com/watch?v=toBeb3DNpZc
======
If used as an Image Hosting
Demo site https://imghost.crazypeace.workers.dev/imghostimghost
Demo video https://www.youtube.com/watch?v=B7wH4tB1-O8
======
If used as an online journal, with MarkDown support
Demo site https://journal.crazypeace.workers.dev/journaljournal
Demo video https://www.youtube.com/watch?v=DZcXqyIm_R0
https://www.youtube.com/watch?v=Ra6SXZFeGM8
If you want to make a one-time QR code
Demo site https://snapchat.crazypeace.workers.dev/huiyingebielianaiputi
======
Development Log
Directly accessing the domain returns 404. Set an entry in KV to save a secret path, and the usage page is only displayed when this path is accessed.
https://zelikk.blogspot.com/2022/07/url-shorten-worker-hide-tutorial.html
Support custom short links
https://zelikk.blogspot.com/2022/07/url-shorten-worker-custom.html
API does not provide public service
https://zelikk.blogspot.com/2022/07/url-shorten-worker-api-password.html
Page cache of configured short links
https://zelikk.blogspot.com/2022/08/url-shorten-worker-localstorage.html
Long link text box pre-search localStorage
https://zelikk.blogspot.com/2022/08/url-shorten-worker-bootstrap-list-group-oninput.html
Add a button to delete a specific short link
https://zelikk.blogspot.com/2022/08/url-shorten-worker-delete-kv-localstorage.html
Visit count feature, ability to query short links, becoming a fully functional short link API system
https://zelikk.blogspot.com/2023/11/url-shorten-worker-visit-count-api-api.html
Burn-after-reading feature, can create one-time QR codes
https://zelikk.blogspot.com/2023/11/url-shorten-worker-snapchat-mode.html
Add the ability to read all records in KV
https://zelikk.blogspot.com/2024/01/url-shorten-worker-load-cloudflare-kv.html
Transform into a Pastebin online notepad
https://zelikk.blogspot.com/2024/01/url-shorten-worker-pastebin.html
Transform into an Image Hosting service
https://zelikk.blogspot.com/2024/01/url-shorten-worker-image-hosting-base64.html
Transform into a NetJournal diary, supports Markdown
https://zelikk.blogspot.com/2024/02/url-shorten-worker-netjournal.html
https://zelikk.blogspot.com/2024/02/url-shorten-worker-netjournal-markdown.html
https://zelikk.blogspot.com/2024/04/url-shorten-worker-netjournal-markdown.html