mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-13 07:34:36 +01:00
validate url backgrounds
This commit is contained in:
@@ -57,7 +57,8 @@ fn main() {
|
||||
downloader::download_file,
|
||||
downloader::stop_download,
|
||||
lang::get_lang,
|
||||
lang::get_languages
|
||||
lang::get_languages,
|
||||
web::valid_url
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
|
||||
@@ -5,4 +5,14 @@ pub(crate) async fn query(site: &str) -> String {
|
||||
|
||||
let response = client.get(site).header(USER_AGENT, "cultivation").send().await.unwrap();
|
||||
return response.text().await.unwrap();
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub(crate) async fn valid_url(url: String) -> bool {
|
||||
// Check if we get a 200 response
|
||||
let client = reqwest::Client::new();
|
||||
|
||||
let response = client.get(url).header(USER_AGENT, "cultivation").send().await.unwrap();
|
||||
|
||||
return response.status().as_str() == "200";
|
||||
}
|
||||
@@ -35,6 +35,8 @@ interface IState {
|
||||
bgFile: string;
|
||||
}
|
||||
|
||||
const DEFAULT_BG = 'https://webstatic.hoyoverse.com/upload/event/2020/11/04/7fd661b5184e1734f91f628b6f89a31f_7367318474207189623.png'
|
||||
|
||||
const downloadHandler = new DownloadHandler()
|
||||
|
||||
class App extends React.Component<IProps, IState> {
|
||||
@@ -46,7 +48,7 @@ class App extends React.Component<IProps, IState> {
|
||||
miniDownloadsOpen: false,
|
||||
downloadsOpen: false,
|
||||
gameDownloadsOpen: false,
|
||||
bgFile: 'https://webstatic.hoyoverse.com/upload/event/2020/11/04/7fd661b5184e1734f91f628b6f89a31f_7367318474207189623.png',
|
||||
bgFile: DEFAULT_BG,
|
||||
}
|
||||
|
||||
listen('lang_error', (payload) => {
|
||||
@@ -100,8 +102,13 @@ class App extends React.Component<IProps, IState> {
|
||||
bgFile: convertFileSrc(custom_bg)
|
||||
}, this.forceUpdate)
|
||||
} else {
|
||||
// Check if URL returns a valid image.
|
||||
const isValid = await invoke('valid_url', {
|
||||
url: custom_bg
|
||||
})
|
||||
|
||||
this.setState({
|
||||
bgFile: custom_bg
|
||||
bgFile: isValid ? custom_bg : DEFAULT_BG
|
||||
}, this.forceUpdate)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user