aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock111
-rw-r--r--Cargo.toml1
-rw-r--r--prechoster.json2
-rw-r--r--src/main.rs14
4 files changed, 123 insertions, 5 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 1423d87..56fb618 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -76,6 +76,12 @@ dependencies = [
]
[[package]]
+name = "async_once"
+version = "0.2.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2ce4f10ea3abcd6617873bae9f91d1c5332b4a778bd9ce34d0cd517474c1de82"
+
+[[package]]
name = "atomic"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -135,6 +141,43 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c"
[[package]]
+name = "cached"
+version = "0.40.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "72b4147cd94d5fbdc2ab71b11d50a2f45493625576b3bb70257f59eedea69f3d"
+dependencies = [
+ "async-trait",
+ "async_once",
+ "cached_proc_macro",
+ "cached_proc_macro_types",
+ "futures",
+ "hashbrown",
+ "instant",
+ "lazy_static",
+ "once_cell",
+ "thiserror",
+ "tokio",
+]
+
+[[package]]
+name = "cached_proc_macro"
+version = "0.15.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "751f7f4e7a091545e7f6c65bacc404eaee7e87bfb1f9ece234a1caa173dc16f2"
+dependencies = [
+ "cached_proc_macro_types",
+ "darling",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "cached_proc_macro_types"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3a4f925191b4367301851c6d99b09890311d74b0d43f274c0b34c86d308a3663"
+
+[[package]]
name = "cc"
version = "1.0.77"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -204,6 +247,41 @@ dependencies = [
]
[[package]]
+name = "darling"
+version = "0.13.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c"
+dependencies = [
+ "darling_core",
+ "darling_macro",
+]
+
+[[package]]
+name = "darling_core"
+version = "0.13.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610"
+dependencies = [
+ "fnv",
+ "ident_case",
+ "proc-macro2",
+ "quote",
+ "strsim",
+ "syn",
+]
+
+[[package]]
+name = "darling_macro"
+version = "0.13.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835"
+dependencies = [
+ "darling_core",
+ "quote",
+ "syn",
+]
+
+[[package]]
name = "devise"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -517,6 +595,12 @@ dependencies = [
]
[[package]]
+name = "ident_case"
+version = "1.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
+
+[[package]]
name = "indexmap"
version = "1.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -574,6 +658,7 @@ name = "linja-pona-svginator"
version = "0.1.0"
dependencies = [
"anyhow",
+ "cached",
"quick-xml",
"rocket",
]
@@ -1132,6 +1217,12 @@ dependencies = [
]
[[package]]
+name = "strsim"
+version = "0.10.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
+
+[[package]]
name = "subtle"
version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1163,6 +1254,26 @@ dependencies = [
]
[[package]]
+name = "thiserror"
+version = "1.0.37"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e"
+dependencies = [
+ "thiserror-impl",
+]
+
+[[package]]
+name = "thiserror-impl"
+version = "1.0.37"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
name = "thread_local"
version = "1.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index f5197f0..870c875 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -7,5 +7,6 @@ edition = "2021"
[dependencies]
anyhow = "1.0.66"
+cached = "0.40.0"
quick-xml = "0.26.0"
rocket = "0.5.0-rc.2"
diff --git a/prechoster.json b/prechoster.json
index 180b67b..43952a7 100644
--- a/prechoster.json
+++ b/prechoster.json
@@ -1 +1 @@
-{"modules":[{"id":"00423c5ee8323e1e","data":{"name":"Toki","contents":"<script>\n export let font;\n export let text;\n export let textRender = text;\n export let textEn;\n export let width = \"2\";\n export let height = \"2\";\n const src = 'https://linja-pona-svginator.fly.dev/render/' + encodeURIComponent(textRender);\n\n const fWidth = parseFloat(width), fHeight = parseFloat(height);\n\n let widthRem, heightRem;\n\n if (fWidth > fHeight && false) {\n widthRem = 2;\n // orig-height/orig-width = new-height/new-width\n heightRem = fHeight / fWidth * 2;\n } else {\n heightRem = 2;\n widthRem = fWidth / fHeight * 2;\n }\n\n const style = `height: ${heightRem}rem; width: ${widthRem}rem`;\n</script>\n\n<ruby style=\"ruby-position: over\"><ruby style=\"ruby-position: under\"><img src={src} alt={text} style={style} /><rt>{textEn}</rt></ruby><rt>{text}</rt></ruby>\n\n<style>\n img {\n display: inline-block;\n margin: 0;\n }\n\n rt {\n font-size: 0.8rem;\n }\n</style>\n"},"pluginId":"source.svelte-component","sends":[],"namedSends":{"5e0a6640c309d9dd":["Toki"]},"graphPos":null},{"id":"5e0a6640c309d9dd","data":{"contents":"<script>\n import Toki from \"./Toki.svelte\";\n</script>\n\n<p>\n <Toki text=\"tenpo ni\" textRender=\"tenpo+ni\" textEn=\"now\" width=\"8.004\" height=\"10.08\" />\n <Toki text=\"la\" textEn=\",\" width=\"4.8\" height=\"7.656\" />\n <Toki text=\"mi\" textEn=\"I\" width=\"7.44\" height=\"8.556\" />\n <Toki text=\"ken\" textEn=\"can\" width=\"6.84\" height=\"8.004\" />\n <Toki text=\"pali\" textEn=\"build\" width=\"8.016\" height=\"8.556\" />\n <Toki text=\"pona\" textEn=\"simply\" width=\"9.084\" height=\"5.304\" />\n <a href=\"https://boringcactus.neocities.org/toki-pona/lipu-pi-toki-mute.html\">\n <Toki text=\"lipu\" textEn=\"documents\" width=\"7.092\" height=\"8.1\" />\n <Toki text=\"pi toki mute\" textRender=\"pi+toki+mute\" textEn=\"of many languages\" width=\"11.184\" height=\"10.74\" />\n </a>.\n</p>\n\n<p>\n <Toki text=\"tenpo pini\" textRender=\"tenpo+pini\" textEn=\"before\" width=\"8.004\" height=\"9.492\" />\n <Toki text=\"la\" textEn=\",\" width=\"4.8\" height=\"7.656\" />\n <Toki text=\"nasin\" textEn=\"way\" width=\"6.9\" height=\"7.98\" />\n <Toki text=\"pi pali ni\" textRender=\"pi++pali ni\" textEn=\"of doing this\" width=\"21.18\" height=\"10.044\" />\n <Toki text=\"li\" textEn=\"is\" width=\"5.664\" height=\"8.472\" />\n <a href=\"https://cohost.org/cactus/post/455309-p-style-font-size\">\n <Toki text=\"jaki\" textEn=\"gross\" width=\"7.98\" height=\"8.796\" />\n <Toki text=\"mute\" textEn=\"very\" width=\"6.6\" height=\"8.004\" />\n </a>.\n <Toki text=\"ni\" textEn=\"this\" width=\"7.392\" height=\"8.376\" />\n <Toki text=\"awen\" textEn=\"remains\" width=\"8.496\" height=\"8.664\" />\n <Toki text=\"jaki\" textEn=\"gross\" width=\"7.98\" height=\"8.796\" />\n <Toki text=\"lili\" textEn=\"slightly\" width=\"6.156\" height=\"4.956\" />\n .\n <Toki text=\"mi\" textEn=\"I\" width=\"7.44\" height=\"8.556\" />\n <Toki text=\"wile\" textEn=\"want\" width=\"8.604\" height=\"7.248\" />\n <Toki text=\"e\" textEn=\"\" width=\"8.376\" height=\"8.412\" />\n <a href=\"https://help.antisoftware.club/support/discussions/topics/62000183101\">\n <Toki text=\"nasin\" textEn=\"way\" width=\"6.9\" height=\"7.98\" />\n <Toki text=\"lon\" textEn=\"real\" width=\"8.496\" height=\"4.056\" />\n <Toki text=\"pi lukin ante\" textRender=\"pi+lukin+ante\" textEn=\"of looking different\" width=\"11.184\" height=\"10.656\" />\n </a>.\n</p>\n\n<p>\n <Toki text=\"mi\" textEn=\"I\" width=\"7.44\" height=\"8.556\" />\n <Toki text=\"kepeken\" textEn=\"use\" width=\"8.304\" height=\"8.304\" />\n <Toki text=\"e\" textEn=\"\" width=\"8.376\" height=\"8.412\" />\n <a href=\"https://cloudwithlightning.net/random/chostin/prechoster/\">\n <Toki text=\"ilo\" textEn=\"tool\" width=\"7.908\" height=\"7.8\" />\n <Toki text=\"Pinsotu\" textRender=\"[_pipi_ilo_nimi_soweli_olin_toki_utala]\" textEn=\"Prechoster\" width=\"77.46\" height=\"11.604\" />\n </a>\n <Toki text=\"e\" textEn=\",\" width=\"8.376\" height=\"8.412\" />\n <a href=\"https://musilili.net/linja-pona/\">\n <Toki text=\"sitelen\" textEn=\"symbols\" width=\"7.092\" height=\"8.1\" />\n <Toki text=\"pi linja pona\" textRender=\"pi+linja+pona\" textEn=\"linja pona\" width=\"11.184\" height=\"9.744\" />\n </a>\n <Toki text=\"e\" textEn=\",\" width=\"8.376\" height=\"8.412\" />\n <a href=\"https://cohost.org/ant/post/450295-p-style-font-size\">\n <Toki text=\"nasin\" textEn=\"way\" width=\"6.9\" height=\"7.98\" />\n <Toki text=\"pi nimi poka tu\" textRender=\"pi+++nimi poka tu\" textEn=\"of two aside words\" width=\"31.176\" height=\"9.744\" />\n </a>\n <Toki text=\"e\" textEn=\",\" width=\"8.376\" height=\"8.412\" />\n <a href=\"https://code.boringcactus.com/linja-pona-svginator/tree/\">\n <Toki text=\"toki ilo\" textRender=\"toki+ilo\" textEn=\"machine language\" width=\"8.424\" height=\"9.552\" />\n <Toki text=\"nasa\" textEn=\"silly\" width=\"8.724\" height=\"8.856\" />\n <Toki text=\"mi\" textEn=\"my\" width=\"7.44\" height=\"8.556\" />\n </a>.\n <Toki text=\"mi\" textEn=\"I\" width=\"7.44\" height=\"8.556\" />\n <Toki text=\"pana\" textEn=\"release\" width=\"8.448\" height=\"8.508\" />\n <a href=\"https://code.boringcactus.com/linja-pona-svginator/tree/prechoster.json\">\n <Toki text=\"kon\" textEn=\"essence\" width=\"7.14\" height=\"8.604\" />\n <Toki text=\"pi lipu ni\" textRender=\"pi+lipu+ni\" textEn=\"of this post\" width=\"11.184\" height=\"9.744\" />\n </a>.\n</p>\n\n<style>\n p {\n font-size: 2rem;\n }\n a {\n filter: invert(66%) sepia(11%) saturate(2468%) hue-rotate(235deg) brightness(62%) contrast(87%);\n text-decoration: none;\n }\n</style>\n"},"pluginId":"source.svelte","sends":["a019876d3132d78a"],"namedSends":{},"graphPos":null},{"id":"a019876d3132d78a","data":{"mode":"attr"},"pluginId":"transform.style-inliner","sends":["output"],"namedSends":{},"graphPos":null}]} \ No newline at end of file
+{"modules":[{"id":"00423c5ee8323e1e","data":{"name":"Toki","contents":"<script>\n export let font;\n export let text;\n export let textRender = text;\n export let textEn;\n export let width = \"2\";\n export let height = \"2\";\n const src = 'https://linja-pona-svginator.fly.dev/render/' + encodeURIComponent(textRender);\n\n const fWidth = parseFloat(width), fHeight = parseFloat(height);\n\n let widthRem, heightRem;\n\n if (fWidth > fHeight && false) {\n widthRem = 2;\n // orig-height/orig-width = new-height/new-width\n heightRem = fHeight / fWidth * 2;\n } else {\n heightRem = 2;\n widthRem = fWidth / fHeight * 2;\n }\n\n const style = `height: ${heightRem}rem; width: ${widthRem}rem`;\n</script>\n\n<ruby style=\"ruby-position: over\"><ruby style=\"ruby-position: under\"><img src={src} alt={text} style={style} loading=\"lazy\" /><rt>{textEn}</rt></ruby><rt>{text}</rt></ruby>\n\n<style>\n img {\n display: inline-block;\n margin: 0;\n }\n\n rt {\n font-size: 0.8rem;\n }\n</style>\n"},"pluginId":"source.svelte-component","sends":[],"namedSends":{"5e0a6640c309d9dd":["Toki"]},"graphPos":null},{"id":"5e0a6640c309d9dd","data":{"contents":"<script>\n import Toki from \"./Toki.svelte\";\n</script>\n\n<p>\n <Toki text=\"tenpo ni\" textRender=\"tenpo+ni\" textEn=\"now\" width=\"8.004\" height=\"10.08\" />\n <Toki text=\"la\" textEn=\",\" width=\"4.8\" height=\"7.656\" />\n <Toki text=\"mi\" textEn=\"I\" width=\"7.44\" height=\"8.556\" />\n <Toki text=\"ken\" textEn=\"can\" width=\"6.84\" height=\"8.004\" />\n <Toki text=\"pali\" textEn=\"build\" width=\"8.016\" height=\"8.556\" />\n <Toki text=\"pona\" textEn=\"simply\" width=\"9.084\" height=\"5.304\" />\n <a href=\"https://boringcactus.neocities.org/toki-pona/lipu-pi-toki-mute.html\">\n <Toki text=\"lipu\" textEn=\"documents\" width=\"7.092\" height=\"8.1\" />\n <Toki text=\"pi toki mute\" textRender=\"pi+toki+mute\" textEn=\"of many languages\" width=\"11.184\" height=\"10.74\" />\n </a>.\n</p>\n\n<p>\n <Toki text=\"tenpo pini\" textRender=\"tenpo+pini\" textEn=\"before\" width=\"8.004\" height=\"9.492\" />\n <Toki text=\"la\" textEn=\",\" width=\"4.8\" height=\"7.656\" />\n <Toki text=\"nasin\" textEn=\"way\" width=\"6.9\" height=\"7.98\" />\n <Toki text=\"pi pali ni\" textRender=\"pi++pali ni\" textEn=\"of doing this\" width=\"21.18\" height=\"10.044\" />\n <Toki text=\"li\" textEn=\"is\" width=\"5.664\" height=\"8.472\" />\n <a href=\"https://cohost.org/cactus/post/455309-p-style-font-size\">\n <Toki text=\"jaki\" textEn=\"gross\" width=\"7.98\" height=\"8.796\" />\n <Toki text=\"mute\" textEn=\"very\" width=\"6.6\" height=\"8.004\" />\n </a>.\n <Toki text=\"ni\" textEn=\"this\" width=\"7.392\" height=\"8.376\" />\n <Toki text=\"awen\" textEn=\"remains\" width=\"8.496\" height=\"8.664\" />\n <Toki text=\"jaki\" textEn=\"gross\" width=\"7.98\" height=\"8.796\" />\n <Toki text=\"lili\" textEn=\"slightly\" width=\"6.156\" height=\"4.956\" />\n .\n <Toki text=\"mi\" textEn=\"I\" width=\"7.44\" height=\"8.556\" />\n <Toki text=\"wile\" textEn=\"want\" width=\"8.604\" height=\"7.248\" />\n <Toki text=\"e\" textEn=\"\" width=\"8.376\" height=\"8.412\" />\n <a href=\"https://help.antisoftware.club/support/discussions/topics/62000183101\">\n <Toki text=\"nasin\" textEn=\"way\" width=\"6.9\" height=\"7.98\" />\n <Toki text=\"lon\" textEn=\"real\" width=\"8.496\" height=\"4.056\" />\n <Toki text=\"pi lukin ante\" textRender=\"pi+lukin+ante\" textEn=\"of looking different\" width=\"11.184\" height=\"10.656\" />\n </a>.\n</p>\n\n<p>\n <Toki text=\"mi\" textEn=\"I\" width=\"7.44\" height=\"8.556\" />\n <Toki text=\"kepeken\" textEn=\"use\" width=\"8.304\" height=\"8.304\" />\n <Toki text=\"e\" textEn=\"\" width=\"8.376\" height=\"8.412\" />\n <a href=\"https://cloudwithlightning.net/random/chostin/prechoster/\">\n <Toki text=\"ilo\" textEn=\"tool\" width=\"7.908\" height=\"7.8\" />\n <Toki text=\"Pinsotu\" textRender=\"[_pipi_ilo_nimi_soweli_olin_toki_utala]\" textEn=\"Prechoster\" width=\"77.46\" height=\"11.604\" />\n </a>\n <Toki text=\"e\" textEn=\",\" width=\"8.376\" height=\"8.412\" />\n <a href=\"https://musilili.net/linja-pona/\">\n <Toki text=\"sitelen\" textEn=\"symbols\" width=\"7.092\" height=\"8.1\" />\n <Toki text=\"pi linja pona\" textRender=\"pi+linja+pona\" textEn=\"linja pona\" width=\"11.184\" height=\"9.744\" />\n </a>\n <Toki text=\"e\" textEn=\",\" width=\"8.376\" height=\"8.412\" />\n <a href=\"https://cohost.org/ant/post/450295-p-style-font-size\">\n <Toki text=\"nasin\" textEn=\"way\" width=\"6.9\" height=\"7.98\" />\n <Toki text=\"pi nimi poka tu\" textRender=\"pi+++nimi poka tu\" textEn=\"of two aside words\" width=\"31.176\" height=\"9.744\" />\n </a>\n <Toki text=\"e\" textEn=\",\" width=\"8.376\" height=\"8.412\" />\n <a href=\"https://code.boringcactus.com/linja-pona-svginator/tree/\">\n <Toki text=\"toki ilo\" textRender=\"toki+ilo\" textEn=\"machine language\" width=\"8.424\" height=\"9.552\" />\n <Toki text=\"nasa\" textEn=\"silly\" width=\"8.724\" height=\"8.856\" />\n <Toki text=\"mi\" textEn=\"my\" width=\"7.44\" height=\"8.556\" />\n </a>.\n <Toki text=\"mi\" textEn=\"I\" width=\"7.44\" height=\"8.556\" />\n <Toki text=\"pana\" textEn=\"release\" width=\"8.448\" height=\"8.508\" />\n <a href=\"https://code.boringcactus.com/linja-pona-svginator/tree/prechoster.json\">\n <Toki text=\"kon\" textEn=\"essence\" width=\"7.14\" height=\"8.604\" />\n <Toki text=\"pi lipu ni\" textRender=\"pi+lipu+ni\" textEn=\"of this post\" width=\"11.184\" height=\"9.744\" />\n </a>.\n</p>\n\n<style>\n p {\n font-size: 2rem;\n }\n a {\n filter: invert(66%) sepia(11%) saturate(2468%) hue-rotate(235deg) brightness(62%) contrast(87%);\n text-decoration: none;\n }\n</style>\n"},"pluginId":"source.svelte","sends":["a019876d3132d78a"],"namedSends":{},"graphPos":null},{"id":"a019876d3132d78a","data":{"mode":"attr"},"pluginId":"transform.style-inliner","sends":["output"],"namedSends":{},"graphPos":null}]} \ No newline at end of file
diff --git a/src/main.rs b/src/main.rs
index 235023a..1d7e27e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,6 +1,7 @@
#[macro_use]
extern crate rocket;
+use cached::proc_macro::cached;
use quick_xml::events::BytesText;
use quick_xml::Writer;
use rocket::http::{ContentType, Status};
@@ -64,6 +65,14 @@ fn to_final_svg(text: &str) -> anyhow::Result<String> {
Ok(result)
}
+#[cached]
+fn get_result(text: String) -> Result<(ContentType, String), (Status, String)> {
+ match to_final_svg(&text) {
+ Ok(svg) => Ok((ContentType::SVG, svg)),
+ Err(e) => Err((Status::InternalServerError, e.to_string())),
+ }
+}
+
#[get("/")]
fn index() -> &'static str {
"Hello, world!"
@@ -71,10 +80,7 @@ fn index() -> &'static str {
#[get("/render/<text>")]
fn render(text: &str) -> Result<(ContentType, String), (Status, String)> {
- match to_final_svg(text) {
- Ok(svg) => Ok((ContentType::SVG, svg)),
- Err(e) => Err((Status::InternalServerError, e.to_string())),
- }
+ get_result(text.to_string())
}
#[rocket::main]