change thumb path to random file name in temp

This commit is contained in:
mairandomness 2019-02-18 20:11:47 -05:00
parent a384c19472
commit d71da4afec
2 changed files with 14 additions and 6 deletions

View file

@ -8,8 +8,10 @@ use gtk;
use gtk::prelude::*; use gtk::prelude::*;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use log::error; use log::error;
use rand::Rng;
use serde_json::json; use serde_json::json;
use serde_json::Value as JsonValue; use serde_json::Value as JsonValue;
use std::env::temp_dir;
use std::fs; use std::fs;
use std::path::PathBuf; use std::path::PathBuf;
@ -494,11 +496,18 @@ fn get_image_media_info(file: &str, mimetype: &str) -> Option<JsonValue> {
// make thumbnail max 800x600 // make thumbnail max 800x600
let thumb = Pixbuf::new_from_file_at_scale(&file, 800, 600, true).ok()?; let thumb = Pixbuf::new_from_file_at_scale(&file, 800, 600, true).ok()?;
thumb.savev("/tmp/fractal_thumb.png", "png", &[]).ok()?; let mut rng = rand::thread_rng();
let x: u64 = rng.gen_range(1, 9223372036854775807);
let thumb_path = format!(
"{}/fractal_{}.png",
temp_dir().to_str().unwrap_or_default(),
x.to_string()
);
thumb.savev(&thumb_path, "png", &[]).ok()?;
let info = json!({ let info = json!({
"info": { "info": {
"thumbnail_url": "", "thumbnail_url": thumb_path,
"thumbnail_info": { "thumbnail_info": {
"w": thumb.get_width(), "w": thumb.get_width(),
"h": thumb.get_height(), "h": thumb.get_height(),

View file

@ -465,7 +465,9 @@ pub fn set_room_avatar(bk: &Backend, roomid: &str, avatar: &str) -> Result<(), E
pub fn attach_file(bk: &Backend, mut msg: Message) -> Result<(), Error> { pub fn attach_file(bk: &Backend, mut msg: Message) -> Result<(), Error> {
let fname = msg.url.clone().unwrap_or_default(); let fname = msg.url.clone().unwrap_or_default();
let thumb = msg.thumb.clone().unwrap_or_default(); let mut extra_content: ExtraContent =
serde_json::from_value(msg.clone().extra_content.unwrap()).unwrap();
let thumb = extra_content.info.thumbnail_url.clone().unwrap_or_default();
let tx = bk.tx.clone(); let tx = bk.tx.clone();
let itx = bk.internal_tx.clone(); let itx = bk.internal_tx.clone();
@ -484,9 +486,6 @@ pub fn attach_file(bk: &Backend, mut msg: Message) -> Result<(), Error> {
} }
Ok(thumb_uri) => { Ok(thumb_uri) => {
msg.thumb = Some(thumb_uri.to_string()); msg.thumb = Some(thumb_uri.to_string());
let mut extra_content: ExtraContent =
serde_json::from_value(msg.extra_content.unwrap()).unwrap();
extra_content.info.thumbnail_url = Some(thumb_uri); extra_content.info.thumbnail_url = Some(thumb_uri);
msg.extra_content = Some(serde_json::to_value(&extra_content).unwrap()); msg.extra_content = Some(serde_json::to_value(&extra_content).unwrap());
} }