Compare commits

...

2 Commits

Author SHA1 Message Date
a655b3b02e unshortener copies to clipboard 2024-04-13 21:46:51 -04:00
ca2c990002 implement in memory cache 2024-04-13 21:44:41 -04:00
3 changed files with 16 additions and 6 deletions

View File

@ -28,8 +28,6 @@ function getDomainFromUrl(linkUrl) {
}
function unshortenUrl(linkUrl) {
console.log(linkUrl);
fetch("http://localhost:8000/?url=" + linkUrl)
.then(res => {
if (!res.ok) {
@ -37,7 +35,9 @@ function unshortenUrl(linkUrl) {
}
return res.json();
})
.then(data => {
console.log(data);
.then(unshortenedUrl => {
console.log("unshortened: " + unshortenedUrl)
navigator.clipboard.writeText(unshortenedUrl)
.catch(err => console.error("couldn't copy to clipboard", err));
});
}

View File

@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Unshortener",
"version": "0.2",
"version": "0.3",
"description": "Unshorten links from Twitter.",
@ -17,6 +17,8 @@
},
"permissions": [
"activeTab",
"clipboardWrite",
"contextMenus"
]
}

View File

@ -9,6 +9,8 @@ UNSHORTEN = {
't.co': unshorten_twitter
}
CACHE = {}
app = FastAPI(docs_url=None, redoc_url=None)
app.add_middleware(
CORSMiddleware,
@ -29,4 +31,10 @@ async def receive_url(url: Optional[str] = None):
if domain not in UNSHORTEN:
return {"error": f"cannot unshorten {domain}"}
return UNSHORTEN[domain](url)
if url in CACHE:
unshortened = CACHE[url]
else:
unshortened = UNSHORTEN[domain](url)
CACHE[url] = unshortened
return unshortened