This commit is contained in:
GitHub
2024-07-27 09:46:40 +08:00
parent 05bea93aa3
commit f86be4aee0
11 changed files with 72 additions and 64 deletions

80
Cargo.lock generated
View File

@@ -162,9 +162,9 @@ dependencies = [
[[package]]
name = "async-compression"
version = "0.4.11"
version = "0.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd066d0b4ef8ecb03a55319dc13aa6910616d0f44008a045bb1835af830abff5"
checksum = "fec134f64e2bc57411226dfc4e52dec859ddfc7e711fc5e07b612584f000e4aa"
dependencies = [
"brotli",
"futures-core",
@@ -450,6 +450,12 @@ version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]]
name = "byteorder-lite"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f1fe948ff07f4bd06c30984e69f5b4899c516a3ef74f34df92a2df2ab535495"
[[package]]
name = "bytes"
version = "1.6.1"
@@ -458,9 +464,9 @@ checksum = "a12916984aab3fa6e39d655a33e09c0071eb36d6ab3aea5c2d78551f1df6d952"
[[package]]
name = "cached"
version = "0.53.0"
version = "0.53.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e79be32df7029b9418298d143ffa9e8ba95eaf13f5599c83a475a64577a7e8c9"
checksum = "b4d73155ae6b28cf5de4cfc29aeb02b8a1c6dab883cb015d15cd514e42766846"
dependencies = [
"ahash 0.8.11",
"cached_proc_macro",
@@ -473,9 +479,9 @@ dependencies = [
[[package]]
name = "cached_proc_macro"
version = "0.22.0"
version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "575f32e012222055211b70f5b0601f951f84523410a0e65c81f2744a6042450d"
checksum = "2f42a145ed2d10dce2191e1dcf30cfccfea9026660e143662ba5eec4017d5daa"
dependencies = [
"darling",
"proc-macro2",
@@ -888,14 +894,13 @@ dependencies = [
"garde",
"http",
"identicon",
"image 0.25.1",
"image 0.25.2",
"img-parts",
"indexmap",
"jieba-rs",
"latex2mathml",
"mozjpeg",
"nanoid",
"once_cell",
"pulldown-cmark",
"rand",
"regex",
@@ -1300,7 +1305,7 @@ name = "identicon"
version = "0.2.1"
source = "git+https://github.com/freedit-dev/identicon.git#51e94d7fd3f472b27e8735b3c3bed90c685751de"
dependencies = [
"image 0.25.1",
"image 0.25.2",
]
[[package]]
@@ -1328,12 +1333,12 @@ dependencies = [
[[package]]
name = "image"
version = "0.25.1"
version = "0.25.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd54d660e773627692c524beaad361aca785a4f9f5730ce91f42aabe5bce3d11"
checksum = "99314c8a2152b8ddb211f924cdae532d8c5e4c8bb54728e12fff1b0cd5963a10"
dependencies = [
"bytemuck",
"byteorder",
"byteorder-lite",
"color_quant",
"gif",
"num-traits",
@@ -1413,9 +1418,9 @@ dependencies = [
[[package]]
name = "jobserver"
version = "0.1.31"
version = "0.1.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2b099aaa34a9751c5bf0878add70444e1ed2dd73f347be99003d4577277de6e"
checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0"
dependencies = [
"libc",
]
@@ -1618,13 +1623,14 @@ dependencies = [
[[package]]
name = "mio"
version = "0.8.11"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c"
checksum = "4569e456d394deccd22ce1c1913e6ea0e54519f577285001215d33557431afe4"
dependencies = [
"hermit-abi",
"libc",
"wasi",
"windows-sys 0.48.0",
"windows-sys 0.52.0",
]
[[package]]
@@ -1753,9 +1759,9 @@ dependencies = [
[[package]]
name = "object"
version = "0.36.1"
version = "0.36.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "081b846d1d56ddfc18fdf1a922e4f6e07a11768ea1b92dec44e42b72712ccfce"
checksum = "3f203fa8daa7bb185f760ae12bd8e097f63d17041dcdcaf675ac54cdf863170e"
dependencies = [
"memchr",
]
@@ -2040,14 +2046,13 @@ dependencies = [
[[package]]
name = "quinn-udp"
version = "0.5.2"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9096629c45860fc7fb143e125eb826b5e721e10be3263160c7d60ca832cf8c46"
checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285"
dependencies = [
"libc",
"once_cell",
"socket2",
"tracing",
"windows-sys 0.52.0",
]
@@ -2295,9 +2300,9 @@ dependencies = [
[[package]]
name = "rustls"
version = "0.23.11"
version = "0.23.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4828ea528154ae444e5a642dbb7d5623354030dc9822b83fd9bb79683c7399d0"
checksum = "c58f8c84392efc0a126acce10fa59ff7b3d2ac06ab451a33f2741989b806b044"
dependencies = [
"once_cell",
"ring",
@@ -2325,9 +2330,9 @@ checksum = "976295e77ce332211c0d24d92c0e83e50f5c5f046d11082cea19f3df13a3562d"
[[package]]
name = "rustls-webpki"
version = "0.102.5"
version = "0.102.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9a6fccd794a42c2c105b513a2f62bc3fd8f3ba57a4593677ceb0bd035164d78"
checksum = "8e6b52d4fda176fd835fdc55a835d4a89b8499cad995885a21149d5ad62f852e"
dependencies = [
"ring",
"rustls-pki-types",
@@ -2563,9 +2568,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
[[package]]
name = "syn"
version = "2.0.71"
version = "2.0.72"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b146dcf730474b4bcd16c311627b31ede9ab149045db4d6088b3becaea046462"
checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af"
dependencies = [
"proc-macro2",
"quote",
@@ -2866,26 +2871,25 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]]
name = "tokio"
version = "1.38.1"
version = "1.39.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb2caba9f80616f438e09748d5acda951967e1ea58508ef53d9c6402485a46df"
checksum = "d040ac2b29ab03b09d4129c2f5bbd012a3ac2f79d38ff506a4bf8dd34b0eac8a"
dependencies = [
"backtrace",
"bytes",
"libc",
"mio",
"num_cpus",
"pin-project-lite",
"socket2",
"tokio-macros",
"windows-sys 0.48.0",
"windows-sys 0.52.0",
]
[[package]]
name = "tokio-macros"
version = "2.3.0"
version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a"
checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752"
dependencies = [
"proc-macro2",
"quote",
@@ -3146,9 +3150,9 @@ checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
[[package]]
name = "version_check"
version = "0.9.4"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
[[package]]
name = "virtue"
@@ -3539,9 +3543,9 @@ checksum = "3f423a2c17029964870cfaabb1f13dfab7d092a62a29a89264f4d36990ca414a"
[[package]]
name = "zune-jpeg"
version = "0.4.11"
version = "0.4.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec866b44a2a1fd6133d363f073ca1b179f438f99e7e5bfb1e33f7181facfe448"
checksum = "16099418600b4d8f028622f73ff6e3deaabdff330fb9a2a131dea781ee8b0768"
dependencies = [
"zune-core",
]

View File

@@ -3,6 +3,7 @@ name = "freedit"
version = "0.7.4-rc.1"
edition = "2021"
license = "MIT License"
rust = "1.80.0"
[dependencies]
ammonia = "4.0.0"
@@ -29,7 +30,6 @@ jieba-rs = "0.7.0"
latex2mathml = "0.2.3"
mozjpeg = "0.10.9"
nanoid = "0.4.0"
once_cell = "*"
pulldown-cmark = { version = "0.11.0", features = ["simd", "html"], default-features = false }
rand = "0.8"
regex = "1"

View File

@@ -1,11 +1,11 @@
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};
use std::fs::{self, read_to_string, File};
use std::io::Write;
use std::path::Path;
use std::sync::LazyLock;
use tracing::{info, warn};
pub static CONFIG: Lazy<Config> = Lazy::new(Config::load_config);
pub static CONFIG: LazyLock<Config> = LazyLock::new(Config::load_config);
#[derive(Serialize, Deserialize)]
pub struct Config {

View File

@@ -27,12 +27,14 @@ use axum_extra::{
use cached::proc_macro::cached;
use chrono::{DateTime, Utc};
use garde::Validate;
use once_cell::sync::Lazy;
use reqwest::Client;
use serde::Deserialize;
use sled::Db;
use std::collections::{BTreeMap, HashMap};
use std::{collections::HashSet, time::Duration};
use std::{
collections::{BTreeMap, HashMap},
sync::LazyLock,
};
use tracing::error;
struct SourceItem {
@@ -479,7 +481,7 @@ pub(crate) struct FormFeedAdd {
is_public: bool,
}
static CLIENT: Lazy<Client> = Lazy::new(|| {
static CLIENT: LazyLock<Client> = LazyLock::new(|| {
let mut client = reqwest::Client::builder().timeout(Duration::from_secs(6));
if !CONFIG.proxy.is_empty() {
let proxy = reqwest::Proxy::all(&CONFIG.proxy).unwrap();

View File

@@ -1,5 +1,6 @@
use std::sync::LazyLock;
use chrono::DateTime;
use once_cell::sync::Lazy;
use pulldown_cmark::{html, CodeBlockKind, Event, Options, Tag};
use syntect::{highlighting::ThemeSet, html::highlighted_html_for_string, parsing::SyntaxSet};
@@ -126,8 +127,9 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for SyntaxPreprocessor<'a, I> {
}
}
static THEME_SET: Lazy<syntect::highlighting::ThemeSet> = Lazy::new(ThemeSet::load_defaults);
static SYNTAX_SET: Lazy<SyntaxSet> = Lazy::new(SyntaxSet::load_defaults_newlines);
static THEME_SET: LazyLock<syntect::highlighting::ThemeSet> =
LazyLock::new(ThemeSet::load_defaults);
static SYNTAX_SET: LazyLock<SyntaxSet> = LazyLock::new(SyntaxSet::load_defaults_newlines);
fn code_highlighter(code: &str, lang: &str) -> String {
let syntax = if let Some(syntax) = SYNTAX_SET.find_syntax_by_name(lang) {

View File

@@ -43,13 +43,13 @@ use bincode::config::standard;
use cached::proc_macro::cached;
use chrono::{DateTime, Utc};
use garde::Validate;
use once_cell::sync::Lazy;
use serde::Deserialize;
use sled::{transaction::ConflictableTransactionError, Transactional};
use sled::{Batch, Db};
use std::{
collections::{BTreeSet, HashMap, HashSet},
path::PathBuf,
sync::LazyLock,
};
/// Page data: `inn_create.html`
@@ -1154,7 +1154,7 @@ fn recommend_users() -> Result<Vec<(u32, String)>, AppError> {
Ok(users)
}
static FEED_CONFIG: Lazy<WriteConfig> = Lazy::new(|| WriteConfig {
static FEED_CONFIG: LazyLock<WriteConfig> = LazyLock::new(|| WriteConfig {
write_document_declaration: false,
indent_size: Some(2),
});

View File

@@ -86,7 +86,7 @@ pub(crate) async fn message_post(
]
.concat();
DB.open_tree("messages")?.insert(&u32_to_ivec(mid), v)?;
DB.open_tree("messages")?.insert(u32_to_ivec(mid), v)?;
add_notification(&DB, uid, NtType::Message, claim.uid, mid)?;
let k = [&u32_to_ivec(uid), &u32_to_ivec(mid)].concat();

View File

@@ -1,3 +1,5 @@
use std::sync::LazyLock;
use super::{db_utils::u32_to_ivec, fmt::md2html, Claim, SiteConfig};
use crate::{error::AppError, DB};
use askama_axum::{into_response, Template};
@@ -10,7 +12,6 @@ use axum_extra::{
TypedHeader,
};
use http::{HeaderName, StatusCode};
use once_cell::sync::Lazy;
use tracing::error;
#[derive(Template)]
@@ -93,7 +94,7 @@ pub(crate) async fn home(
Ok(Redirect::to(redirect))
}
static CSS: Lazy<String> = Lazy::new(|| {
static CSS: LazyLock<String> = LazyLock::new(|| {
// TODO: CSS minification
let mut css = include_str!("../../static/css/bulma.min.css").to_string();
css.push('\n');

View File

@@ -492,7 +492,7 @@ pub(crate) async fn solo_post(
set_one(&DB, "solos", sid, &solo)?;
let k = [&u32_to_ivec(claim.uid), &sid_ivec].concat();
DB.open_tree("user_solos")?
.insert(k, &u32_to_ivec(solo_type as u32))?;
.insert(k, u32_to_ivec(solo_type as u32))?;
// kv_pair: sid = uid#solo_type
let v = [&u32_to_ivec(claim.uid), &u32_to_ivec(solo_type as u32)].concat();

View File

@@ -1,4 +1,4 @@
use std::collections::HashSet;
use std::{collections::HashSet, sync::LazyLock};
use askama_axum::{into_response, Template};
use axum::{extract::Query, response::IntoResponse};
@@ -6,7 +6,6 @@ use axum_extra::{headers::Cookie, TypedHeader};
use bincode::config::standard;
use indexmap::IndexSet;
use jieba_rs::{Jieba, TokenizeMode};
use once_cell::sync::Lazy;
use rust_stemmers::{Algorithm, Stemmer};
use serde::Deserialize;
use sled::{Batch, Db};
@@ -140,8 +139,8 @@ pub(super) trait ToDoc {
fn to_doc(&self, id: Option<u32>) -> TantivyDocument;
}
static SEARCHER: Lazy<Searcher> = Lazy::new(|| Tan::get_searcher().unwrap());
pub(super) static FIELDS: Lazy<Fields> = Lazy::new(|| Tan::set_schema().1);
static SEARCHER: LazyLock<Searcher> = LazyLock::new(|| Tan::get_searcher().unwrap());
pub(super) static FIELDS: LazyLock<Fields> = LazyLock::new(|| Tan::set_schema().1);
pub struct Tan {
writer: IndexWriter,
@@ -437,8 +436,8 @@ impl TokenStream for MultiLingoTokenStream {
}
}
static JIEBA: Lazy<Jieba> = Lazy::new(Jieba::new);
static STEMMER_ENG: Lazy<Stemmer> = Lazy::new(|| Stemmer::create(Algorithm::English));
static JIEBA: LazyLock<Jieba> = LazyLock::new(Jieba::new);
static STEMMER_ENG: LazyLock<Stemmer> = LazyLock::new(|| Stemmer::create(Algorithm::English));
fn pre_tokenize_text(text: &str) -> Vec<Token> {
let mut tokens = Vec::with_capacity(text.len() / 4);
@@ -496,13 +495,13 @@ fn pre_tokenize_text(text: &str) -> Vec<Token> {
tokens
}
static STOP_WORDS_ENG: Lazy<HashSet<String>> = Lazy::new(|| {
static STOP_WORDS_ENG: LazyLock<HashSet<String>> = LazyLock::new(|| {
stop_words::get(stop_words::LANGUAGE::English)
.into_iter()
.collect()
});
static STOP_WORDS_CMN: Lazy<HashSet<String>> = Lazy::new(|| {
static STOP_WORDS_CMN: LazyLock<HashSet<String>> = LazyLock::new(|| {
let mut set: HashSet<_> = stop_words::get(stop_words::LANGUAGE::Chinese)
.into_iter()
.collect();

View File

@@ -13,9 +13,9 @@ mod controller;
mod error;
use data_encoding::HEXLOWER;
use once_cell::sync::Lazy;
use ring::digest::{Context, Digest, SHA256};
use sled::Db;
use std::sync::LazyLock;
use std::{
env,
fs::File,
@@ -27,7 +27,7 @@ const GIT_COMMIT: &str = env!("GIT_COMMIT");
/// Returns SHA256 of the current running executable.
/// Cookbook: [Calculate the SHA-256 digest of a file](https://rust-lang-nursery.github.io/rust-cookbook/cryptography/hashing.html)
static CURRENT_SHA256: Lazy<String> = Lazy::new(|| {
static CURRENT_SHA256: LazyLock<String> = LazyLock::new(|| {
fn sha256_digest<R: Read>(mut reader: R) -> Digest {
let mut context = Context::new(&SHA256);
let mut buffer = [0; 1024];
@@ -50,7 +50,7 @@ static CURRENT_SHA256: Lazy<String> = Lazy::new(|| {
HEXLOWER.encode(digest.as_ref())
});
pub static DB: Lazy<Db> = Lazy::new(|| {
pub static DB: LazyLock<Db> = LazyLock::new(|| {
info!("sha256: {}", *CURRENT_SHA256);
info!(VERSION);
info!(GIT_COMMIT);