~williewillus/filite

553d7a6defe01b941d7ee26bfb9b21f695ea2347 — Vincent Lee 2 years ago 3a0b0a4
Clippy lint
3 files changed, 10 insertions(+), 19 deletions(-)

M src/db.rs
M src/routes.rs
M src/setup.rs
M src/db.rs => src/db.rs +4 -13
@@ 63,22 63,13 @@ impl Record {
    }
}

#[derive(Default)]
pub struct Directory {
    dirty: bool,
    files: BTreeMap<RecordId, Record>,
    links: BTreeMap<String, String>,
}

impl Default for Directory {
    fn default() -> Self {
        Self {
            dirty: false,
            files: BTreeMap::new(),
            links: BTreeMap::new(),
        }
    }
}

impl Directory {
    pub fn lookup_file(&self, id: RecordId) -> Option<&Record> {
        self.files.get(&id)


@@ 192,8 183,8 @@ impl Directory {
        for line in file.lines() {
            let line = line?;
            let splits = line.split('\t').collect::<Vec<_>>();
            match splits.as_slice() {
                &["file", id, name, created, language, visibility] => {
            match *splits.as_slice() {
                ["file", id, name, created, language, visibility] => {
                    let id = match u64::from_str_radix(id, 16) {
                        Ok(id) => id,
                        Err(_) => panic!("Malformed ID at line {}", cur_line),


@@ 217,7 208,7 @@ impl Directory {
                    };
                    files.insert(id, record);
                }
                &["link", k, v] => {
                ["link", k, v] => {
                    if k.contains(char::is_whitespace) {
                        panic!("Malformed link key at line {}", cur_line);
                    }

M src/routes.rs => src/routes.rs +4 -4
@@ 249,10 249,10 @@ pub mod files {
            match id {
                Some(id) => {
                    let r = directory.lookup_file_mut(id).ok_or_else(make_404)?;
                    r.set_name(&filename);
                    r.set_name(filename);
                    r.id_string()
                }
                None => directory.register_file(&filename, public).id_string(),
                None => directory.register_file(filename, public).id_string(),
            }
        };



@@ 484,11 484,11 @@ pub mod texts {
            let record = match id {
                // todo allow filename customization
                Some(id) => directory.lookup_file_mut(id).ok_or_else(make_404)?,
                None => directory.register_file(&"", params.public),
                None => directory.register_file("", params.public),
            };

            if let Some(lang) = &params.highlight {
                record.set_highlight_language(&lang);
                record.set_highlight_language(lang);
            }

            record.id_string()

M src/setup.rs => src/setup.rs +2 -2
@@ 77,10 77,10 @@ pub fn init_config() -> Result<Config, anyhow::Error> {
        log::info!("No config file found. Creating default.");
        let config = Config::default();
        config
            .write_file(&config_path)
            .write_file(config_path)
            .context("Can't write config file")?;
        return Ok(config);
    }

    Config::read_file(&config_path)
    Config::read_file(config_path)
}