feat: add search filter, refactor params
This commit is contained in:
parent
44e14a4ae0
commit
25de7d678a
24 changed files with 374 additions and 72 deletions
|
|
@ -1,7 +1,7 @@
|
|||
// This file is automatically generated. DO NOT EDIT.
|
||||
// See codegen/gen_dictionary.rs for the generation code.
|
||||
use crate::{
|
||||
model::Language,
|
||||
param::Language,
|
||||
timeago::{DateCmp, TaToken, TimeUnit},
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
mod protobuf;
|
||||
|
||||
pub mod dictionary;
|
||||
|
||||
pub use protobuf::ProtoBuilder;
|
||||
|
||||
use std::{borrow::Borrow, collections::BTreeMap, str::FromStr};
|
||||
|
||||
use fancy_regex::Regex;
|
||||
|
|
@ -7,7 +11,7 @@ use once_cell::sync::Lazy;
|
|||
use rand::Rng;
|
||||
use url::Url;
|
||||
|
||||
use crate::{error::Error, error::Result, model::Language};
|
||||
use crate::{error::Error, error::Result, param::Language};
|
||||
|
||||
const CONTENT_PLAYBACK_NONCE_ALPHABET: &[u8; 64] =
|
||||
b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
||||
|
|
@ -57,6 +61,12 @@ pub fn url_to_params(url: &str) -> Result<(String, BTreeMap<String, String>)> {
|
|||
Ok((parsed_url.to_string(), url_params))
|
||||
}
|
||||
|
||||
pub fn urlencode(string: &str) -> String {
|
||||
url::form_urlencoded::Serializer::new(String::new())
|
||||
.append_key_only(string)
|
||||
.finish()
|
||||
}
|
||||
|
||||
/// Parse a string after removing all non-numeric characters
|
||||
pub fn parse_numeric<F>(string: &str) -> core::result::Result<F, F::Err>
|
||||
where
|
||||
|
|
|
|||
56
src/util/protobuf.rs
Normal file
56
src/util/protobuf.rs
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
/// [`ProtoBuilder`] is used to construct protobuf messages using a builder pattern
|
||||
#[derive(Debug, Default)]
|
||||
pub struct ProtoBuilder {
|
||||
pub bytes: Vec<u8>,
|
||||
}
|
||||
|
||||
impl ProtoBuilder {
|
||||
/// Instantiate a new [`ProtoBuilder`]
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
/// Internal: write a raw varint value
|
||||
fn _varint(&mut self, val: u64) {
|
||||
if val == 0 {
|
||||
self.bytes.push(0);
|
||||
} else {
|
||||
let mut v = val;
|
||||
while v != 0 {
|
||||
let mut byte = (v & 0x7f) as u8;
|
||||
v >>= 7;
|
||||
|
||||
if v != 0 {
|
||||
byte |= 0x80;
|
||||
}
|
||||
|
||||
self.bytes.push(byte);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Internal: write a field tag
|
||||
///
|
||||
/// Reference: <https://developers.google.com/protocol-buffers/docs/encoding?hl=en#structure>
|
||||
fn _field(&mut self, field: u32, wire: u8) {
|
||||
let fbits: u64 = (field as u64) << 3;
|
||||
let wbits = wire as u64 & 0x07;
|
||||
let val: u64 = fbits | wbits;
|
||||
self._varint(val);
|
||||
}
|
||||
|
||||
/// Write a varint field
|
||||
pub fn varint(&mut self, field: u32, val: u64) {
|
||||
self._field(field, 0);
|
||||
self._varint(val);
|
||||
}
|
||||
|
||||
/// Write an embedded message
|
||||
///
|
||||
/// Requires passing another [`ProtoBuilder`] with the embedded message.
|
||||
pub fn embedded(&mut self, field: u32, mut pb: Self) {
|
||||
self._field(field, 2);
|
||||
self._varint(pb.bytes.len() as u64);
|
||||
self.bytes.append(&mut pb.bytes);
|
||||
}
|
||||
}
|
||||
Reference in a new issue