Build a URL Shortener with Cloudflare Workers & KV
Source code GitHub: https://github.com/crazypeace/Url-Shorten-Worker
In localStorage, only write the random string of the short URL
Omitted
No need to use wrapping - for displaying the urlList. Change to
Omitted
When displaying the short URL, add a delete button in front
First turn off auto-loading localStorage, then try writing it in the HTML to see the effect.
API supports deleting short URLs
POST adds fields
cmd: value add, del;
keyPhrase: when adding, it's a custom short URL; when deleting, it's the short URL specified for deletion.
For the part displaying the urlList, add an onclick event inside the button
Tested the effect, it works and modifies the KV
The part that loads localStorage to the urlList, implement it with JS
Standardize the API
When the API fails to add a short URL, the status is not 200, and the error message should not be placed in the key; the error should be stored separately.
When the API successfully adds a short URL, the status is 200, and the key is simply the key field of the short URL, without the '/ ' prefix.
When displaying the API result, it should first check whether the status is 200 (success), and then decide whether to display the key short URL or display the error message.
Omitted
